In today’s article, we’ll talk a bit about the HDF5 format. From the HDF5 website:
An HDF5 file is a container for two kinds of objects: datasets, which are array-like collections of data, and groups, which are folder-like containers that hold datasets and other groups.
GNU Grep is an amazingly powerful tool that will allow you to search input files containing specified patterns.
The following command performs a recursive search for a string, inside a directory of files:
Breaking this command down:
-r makes the execution recursive
-n will give you the line number
-w matches the whole word
You can use the --exclude switch to remove file patterns from the set of files included in your search. Removing js and html files from your search might look like this:
The opposite of this will be the --include switch.
For further details on this really useful tool, check out the man page.
Sometimes you might find yourself in the situation where you require a little more power out of your node.js application. You may need to squeeze some extra performance out of a piece of code that you simply can’t achieve using javascript alone. Node.js provides a very rich sdk to allow application developers to create their own addons to use, that allow you to write in C++.
These binary compiled modules then become directly accessible from your node.js applications.
In today’s article, I’d like to walk through the basic setup of an addon project. We’ll also add a function to the addon, and demonstrate the call from javascript to C++.
Setup
Before you can get developing, you’ll need to make sure you have some dependencies installed. Create a directory, and start a new node application.
You’ll need to let the package manager know that your application has a gyp file present by switching gypfile to true.
The project is going to require a gyp file called binding.gyp. It’s the responsibility of this file to generate the build environment that will compile our addon.
With these in place, you can install your dependencies.
Your first module
The gyp file notes that the source of our addon sits at src/main.cpp. Create this file now, and we can fill it out with the following.
The keen reader would see that our module does nothing. That’s ok to start with. This will be an exercise in checking that the build environment is setup correctly.
Import and use your addon just like you would any other module from within the node environment.
Build and run
We’re ready to run.
Ok, great. As expected, that did nothing.
Make it do something
Let’s create a function that will return a string. We can then take that string, and print it out to the console once we’re in the node environment.
We’ll add a header file that will define any functions. We also need to tell our build environment that we’ve got another file to compile.
We define the functions for the addon.
Now for the definition of the function, as well as its registration into the module.
The getGreeting function is actually doing the work here. It’s simply returning a greeting. The InitAll function now changes to add a Set call on the exports object. This is just registering the function to be available to us.
Greetings
So, now we can actually use the greeting. We can just console.log it out.
Generating ranges in PostgreSQL can be a very useful tool for the creation of virtual tables to join to. Should your report require you to generate an entire range; left joining only to the values that need to be filled out.
The following code snippet will allow you to generate such a range:
This snippet will create a table of dates, 1st of each month for the year 2018.
The initial line of the CTE allows you to set the start of the range:
The frequency at which the range is sampled is then set with this line:
Finally, the end of the range is set with the following line: