Blocking trackers via /etc/hosts


These are some of the entries I keep in my /etc/hosts file. Feel free to borrow. more

Tags: trackers, hosts, facebook, google, mac, linux

Importing env vars from .env file


There's a very quick way of importing all env vars defined in your .env file to the shell session you're currently in.

Adding this to your bash profile will allow you to run dotenv:

alias dotenv='export $(cat .env | grep -v ^# | xargs)'

To remove these variables you can also define unset-dotenv:

alias unset-dotenv='unset $(cat .env | grep -v ^# | sed -E "s/(.*)=.*/\1/" | xargs)'

Tags: env, dotenv, file, shell, bash, import, export, alias

Disabling mongo.log


In many installations of MongoDB verbose logging to the mongo.log file is switched on by default. This file can grow to quite substantial size (hundreds of megs are added regularly) and cleaning the file manually every time is rather tedious.

MongoDB recommends rotating logs but on local dev machines you aren't likely to actually need these logs in the first place.

To disable them edit /usr/local/etc/mongod.conf file (or whenever your mongo config is located - check the arguments provided to mongod with ps aux | grep mongod).

In mongod.conf comment out the logpath line. Restart the service and the logs won't be collected anymore. You may want to still remove that file (look in /usr/local/var/log/mongodb/mongo.log)

Tags: mongo, log, disabling

Switching node versions with Homebrew


Just a quick trick to switch between node versions when you install more than one version through Homebrew (brew install node)

You check the currently selected version with node --version. Working out version from paths in brew list node or looking for an asterisk next to a version listed in brew info node can also be used if you're after a different package.

1) List the versions present on your system: brew list --versions node

2) Switch to one of the versions, in my case I'm switching to 6.2.2: brew switch node 6.2.2

That's it, you can verify the operation was successful with node --version.

Tags: brew, homebrew, node, versions



It seems like nobody has created npm module to get prebuilt binaries for ffmpeg, ffprobe, ffplay and ffserver.

I went ahead and put something together quickly.

API and Node module


Node module:

Git repos


Node module:

At the moment it simply links to externally hosted archives containing binaries. In the future they will be repackaged into individual components and I will add automated unzipping in the npm module.

Issues and pull requests welcome.

Tags: ffbinaries, api, npm

Generating self-signed certificates for debugging


This post's purpose is to store the quick shell script that I created for myself the other day after I forgot the password to the previous certificate. Since these are really throwaway I figured I might as well have a single point of entry to regenerate the whole lot:

openssl genrsa -des3 -out myssl.key 1024
openssl req -new -key myssl.key -out myssl.csr
openssl x509 -req -days 365 -in myssl.csr -signkey myssl.key -out myssl.crt

Put that into "" file, run "chmod +x" on it and simply execute it for quick generation of self-signed certificates.

Tags: https, ssl, selfsigned, cert, certificate

Builds failing because of node-gyp missing common.gypi


This issue became apparent on one of CI build boxes. For whatever reason the common.gypi file has gone missing. Stack trace: gyp: /home/builder/.node-gyp/5.9.1/common.gypi not found (cwd: /home/builder/buildtmp/X-JOB1/app/node_modules/fsevents) while reading includes of binding.gyp while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1 gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:355:16) gyp ERR! stack at emitTwo (events.js:100:13) gyp ERR! stack at ChildProcess.emit (events.js:185:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12) gyp ERR! System Linux 3.10.0-229.7.2.el7.x86_64 gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/home/builder/buildtmp/X-JOB1/app/node_modules/fsevents/lib/binding/Release/node-v47-linux-x64/fse.node"... more

Tags: node, node-gyp, common.gypi, npm, js

Installing databases as services with Homebrew on a Mac


First steps

Update your homebrew references and install services package to run the servers in the background.

brew update
brew tap homebrew/services

Installing services

Now you can install MongoDB, Redis or MySQL. Install whatever you need depending on your setup.

brew install mongodb
brew install redis
brew install mysql

Starting services

You can then control services with syntax typically seen in service launchers.

brew services start [service]
brew services stop [service]
brew services restart [service]

Replace [service] bit with mongodb, redis, mysql or whatever service you need to run and you're done.

Some debug options

brew services list
brew services cleanup

Tags: mac, homebrew, mongo, redis, mysql, services

HTTP Basic Auth with nginx on CentOS 7


The other day I decided to set up a fresh VPS for few of my small apps. Essentially it's a CentOs 7 box with nginx which serves one static site when requests come on one domain (in few different contexts/locations with different settings for each of them) and proxies traffic to a Node app on a different domain. Since CentOS7 doesn't have httpd-tools package installed by default we'll need to install that first: yum -y install httpd-tools Next - use it to generate password. We will want to output this to a .htpasswd file. Assuming username "exampleuser": htpasswd -c /etc/nginx/.htpasswd exampleuser This will prompt you for password which will be later encrypted. Then add these two lines to your nginx config (location or server block): auth_basic "Restricted"; auth_basic_user_file /your-app-path/.htpasswd; Restart nginx to pick up the changes and you should be asked for password when you next try to reach that URL. sudo systemctl restart nginx Extra... more

Tags: http, basic, auth, htpasswd, centos, nginx

Checking exit code of the last process in Terminal


When setting up your tools for Continuous Integration one of the things that you will have to do is making sure you're exiting with the correct code.

An easy way to check the exit code of last process run in Terminal is simply to execute this command:

echo $?

While in most cases the exit code will be 0 (indicating successful execution of the process) this can be extremely useful for troubleshooting and ensuring your CI tool catches the errors correctly.

Tags: mac, terminal

Checking DNS zone file


Since I keep forgetting this command, I thought it would be rather useful for the moments when a custom DNS records are needed (i.e. setting up an external email provider).

dig -t ANY

Tags: dns, zone, terminal

BitBucket celebrates marriage equality


I was pushing some small code updates to BitBucket just now and saw this:

BitBucket git push log

BitBucket git push log takes the rainbow photos from Facebook to your terminal. Nice one, Atlassian :)

Tags: bitbucket, git, terminal, equality

Pro tip: Free cross-browser and DNS testing


If you just got yourself a domain and want to see if the DNS records have been updated already "out there in the wild" you can use any screenshot-taking site.

Turns out that Microsoft gives us a surprisingly good tool for this absolutely for free. What's more is you get to see how your site looks in different browsers. No queues, just click the button and wait a few seconds. Thanks, Microsoft! :)

Tags: tip, microsoft, dns, browserstack



So I started writing this little util launcher to replace my local instances of Grunt. You can find the code here:

The reason I started writing this post is need to close off some tabs in my browser and one of them is the POSIX module for node. I was considering this initially for printing out user stats (username, group, etc.) but also to chroot the npm-toolkit tasks. This might be disadvantageous though so I'll just store a link to code for time being should I ever reconsider:

Tags: npm, tools, grunt, gulp

Fixing EMFILE error


If you're on a Mac like me and you develop sizeable Node.js applications you will at some point suffer from the issue which manifests itself in something like this:

EMFILE, too many open files /app/node_modules/random-module/index.js

The problem behind this is the Mac's unusually low open file descriptors limit (256).

To change this simply enter this command in terminal and your issue will be gone:

ulimit -n 1024

Then simply run your app in the same terminal session. You may need to increase the limit even further depending on the size and complexity of your application.

It's also worth checking out this thread on Stack Exchange about persisting ulimit settings.

Tags: node, error, troubleshooting

Simulating Retina resolutions on a non-Retina Mac


If like me you have a non-Retina Mac you may want to fake a Retina resolution in order to get a larger working area.

I was searching for a simple way to achieve this for a while. Finally I found an app called RDM (Retina DisplayMenu). It simply adds an icon to the menu bar which allows you to go beyond the default resolutions. You can download RDM here (direct link).

Since this is faking it and you're still limited by the physical number of pixels you should not expect absolute clarity so it clearly isn't a good solution for playing movies or games. For development and general browsing however it is quite a handy technique. I found that on my 13" MacBook Air 1920x1200 works quite well which is a pretty nice improvement over the native 1440x900.

Tags: mac

Unit testing of Node.js with Mocha and Istanbul


Useful tips

Basic usage

./node_modules/.bin/_mocha --reporter spec

This command will help you run just a subset of tests in a given directory.

./node_modules/.bin/_mocha recursive test/my-subdir

Quick coverage check

./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha

Tags: node

Publishing node modules to a private repository


This is a tutorial on how to use your own private repository to publish node modules to. In most cases this will be a CouchDB based proxy of the public npm registry like Sinopia. I assume that is already set up and all you need is to configure your local development machine to use that registry. Publishing your first package 1) Set your npm config to point to your private repo. npm set registry http://your-private-repo:4873/ npm set always-auth true npm adduser The last command (adduser) will prompt you for the username, password and email. 2) Go to the location of files you want to be included in your package and make sure you have a valid package.json there. You may also add .npmignore file to exclude some files from being part of your package (i.e. unit tests). node_modules folder is automatically ignored but it won’t hurt to add it just in case. Remember to add the publishConfig property. 3) (optional) If you’re publishing the first version of your package, use npm pack to... more

Tags: node, publish, private

Demo: MultiTrack player


An old demo I found in demo section. Consider this to be archival material.

Few years ago I was experimenting with browser support of playback and synchronisation of multiple audio streams. Suspended due to lack of time, also the browser support got much better since I started this rendering this demo obsolete.

Multitrack demo v2

Tags: labs, html5

First post


Hey there, this is just a first post to test the HTMLy platform. I realised I should start writing a bit more and putting together a platform for it is the first step. I'll try to move the existing content here soon to finalise the migration.

I will focus mostly on coding related issues here and occasionally show a demo or two.

Tags: introduction