Creating an encrypted Time Machine disk on ExFAT

hdiutil create -stdinpass -encryption "AES-256" -size 500g -type SPARSEBUNDLE -fs "HFS+J" YourImage.sparsebundle

Where YourImage is the name you want to give your backup image and 500g is the maximum size of your disk image.

open YourImage.sparsebundle
diskutil list

Find your mounted image in the list and get it's path, in my case it was: /dev/disk3s2

sudo diskutil enableOwnership /dev/disk3s2
sudo tmutil setdestination /Volumes/YourImage

references: http://hints.macworld.com/article.php?story=20140415132734925 http://garretthoneycutt.com/index.php/MacOSX#Creating_an_encrypted_sparsebundle https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/hdiutil.1.html

Running NodeJS in production

NodeJS is pretty straight forward to run on a developer laptop, however it is likely that at some point in time, we will want to run it in a production setting.

You can start up the Node app on the server by running node myapp.js. The narrative says that you can have a single NodeJS process serving all requests, this however does not work in practice:

Node does not have an official process manager, so we need to chose from community provided ones:

Even with a process manager, 1 faulty request that makes Node crash will crash all other requests that are in progress on the same process, there is no way to fix this.

Running multiple processes means we need an application load balancer. Some of the NodeJS process managers have load balancing capabilities, however since they are running with Node, it means they have the same limitations we are trying to overcome in the first place. Nginx is a good solution for this problem.

See also: http://geekforbrains.com/post/after-a-year-of-nodejs-in-production

My production NodeJS setup: https://github.com/istvan-antal/solid-node

The LAMP test

New flashy web technologies appear all the time, that claim they are better than their old outdated counterparts.

The LAMP test is designed to compare a new technology to something old but widely used to see wether it holds up to it's promise, or it's just a marketing ploy.

Most marketers of new technology showcase areas where the particular technology excels and ignore all the other areas where it fails compared to it's old counterpart.

A lot of new technologies look good on paper and demos, but fail when they are used under production conditions.

Surprisingly a lot of over-hyped web technologies fall short compared to boring technologies like: PHP, MySQL and jQuery.

AngularJS

AngularJS is one of the most hyped JavaScript-based frontend technologies built by Google.

I have developed 3 projects in AngularJS and have 1 year experience with the technology. During the last two years, I have consistently seen AngularJS to be advertised as the holy grail. I've seen managers put the Angular logo on their slides when pitching a project, just to make it more appealing.

In reality however AngularJS doesn't live up to it's promises.

This article sums of the issues best: Why you should not use AngularJS ( HN discussion )

The following comment sums up how mind blowing AngularJS's faults are:

I find the rise of Angular kind of baffling. Angular's scope system is exactly analogous to the scope system of a programming language. This is a solved problem! When you make a scope system, make it lexical, and require explicit declaration before use. If you're not making those choices, then at least acknowledge that these are the standard answers, with very clear advantages over other scoping systems, and explain why you are not using these answers. But with angular, we have a dynamic, implicit declaration scoping system. New scopes are introduced somewhat unpredictably, at the discretion of each directive. I thought that introducing dynamic, implicit-declaration, non-block-scoped variables in 2014 was like introducing a new car with a coal-burning engine, but no one even seems to remark on it. Then there's the dirty-checking loop. After every event there is a digest; every digest runs every watch. To me, just reading this description makes a voice speak up in my head: "Uh-oh! That sounds like O(n^2)!" Now that angular is being widely used, people are noticing that it's slow as shit. But why did the framework get to this level without anyone remarking, "this dirty-checking algorithm is fundamentally, irremediably not scalable"? Do people not have a sense even for the most coarse performance characteristics of algorithms like this? Or do people simply think that nowadays "performance does not matter"? Angular's "module" system is the strangest of all. It doesn't do namespacing or dependency tracking. What is even the point of it? What thought process led to this useless module system? It's just strange. Hundreds of years of people's work are spent on something, which the most cursory, CS 101 analysis shows to be seriously flawed. Is analysis simply a lost art in this industry? Oh well, people are finally realizing Angular has its faults, because they've seen them with their own eyes and now they believe them. It would be nice if we could learn from this, and maybe skip the next boondoggle (web components for instance), but I have no hope for it.

source: https://news.ycombinator.com/item?id=8652566

Problems with Angular: http://www.leanpanda.com/blog/2015/09/20/our-criticisms-of-angularjs/

In summary, if you use AngularJS in a large project:

Docker

Docker is the AngularJS of infrastructure:

In terms of development practices docker images are used exactly like VM images, there is no substantial difference there, you are getting the same features you would get from using VirtualBox or VMWare.

Docker can be useful if you have one powerful machine and want to run multiple isolated environments inside it without the overhead of virtualisation, this would have been really useful 10 years ago, however in the age of the cloud platforms, this use case is very rare.

The real problem with using docker is that you inherit all the issues you would have with using VM images as well as ones unique to Docker:

References:

http://www.vitavonni.de/blog/201503/2015031201-the-sad-state-of-sysadmin-in-the-age-of-containers.html

https://news.ycombinator.com/item?id=9419188

http://www.banyanops.com/blog/analyzing-docker-hub/

http://blog.gardeviance.org/2015/08/is-there-trouble-brewing-in-land-of.html?m=1

https://thehftguy.wordpress.com/2016/11/01/docker-in-production-an-history-of-failure/

If you want a manageable infrastructure, it's better to script it with Puppet, Chef, Ansible etc.

Python with MacPorts

sudo port install python27 py27-pip
sudo port select --set python python27
sudo port select --set pip pip27
printf '\nexport PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH\n' >> ~/.profile

Why you might want to use boring technologies

There are technologies that are over-glorified overhyped and there are technologies that get the job done, sometimes these two are not the same thing.

If you need to solve a technically boring problem, you might be better off using a boring technology instead of whatever is on the front page of Hacker News.

Rockstar databases

Episode 1 - Mongo DB Is Web Scale https://www.youtube.com/watch?v=b2F-DItXtZs

Why You Should Never Use MongoDB http://www.sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/

https://news.ycombinator.com/item?id=6712703

Re: MemSQL the "world's fastest database"? http://www.postgresql.org/message-id/4FE8A2DE.5050806@agliodbs.com

https://news.ycombinator.com/item?id=8399100

MongoDB stands for humongous:

http://docs.mongodb.org/manual/reference/limits/

http://stackoverflow.com/questions/6766781/maximum-length-for-mysql-type-text/6766854#6766854

https://blog.shodan.io/its-the-data-stupid/

http://cryto.net/~joepie91/blog/2015/07/19/why-you-should-never-ever-ever-use-mongodb/

Cool Architectures

Episode 2 - All The Cool Kids Use Ruby https://www.youtube.com/watch?v=5GpOfwbFRcs

Node.js Is Bad Ass Rock Star Tech https://www.youtube.com/watch?v=bzkRVzciAZg

PHP and Nginx

Ubuntu

sudo apt-get install php5-fpm
sudo mkdir /www
sudo chown ubuntu:ubuntu /www
sudo vim /etc/nginx/sites-available/default
server {
    listen       80;
    index index.php index.html;
    root /www;
    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
}

Mac OS X (Macports)

sudo port install php55-fpm
sudo cp /opt/local/etc/php55/php-fpm.conf.default /opt/local/etc/php55/php-fpm.conf
sudo port load php55-fpm
sudo vim /opt/local/etc/php55/php-fpm.conf

Commend out: listen = 127.0.0.1:9000

Add in: listen = /opt/local/var/run/php5-fpm.sock

Uncomment:

listen.owner = nobody
listen.group = nobody
listen.mode = 0660
sudo cp /opt/local/etc/nginx/fastcgi_params.default /opt/local/etc/nginx/fastcgi_params
sudo port unload php55-fpm
sudo port load php55-fpm

Sample nginx vhost:

server {
    listen       80;
    server_name  watchtower.dev;
    index index.php index.html;
    root /Users/void/Developer/watchtower;
    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    location ~ \.php$ {
        fastcgi_pass unix:/opt/local/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }
}

Setting up an Ubuntu server for PHP

It's good practice to ensure that the system is up to date.

sudo apt-get update
sudo apt-get dist-upgrade
sudo reboot
sudo apt-get install apache2 mysql-server php5 libapache2-mod-php5 php5-gd php5-mysql php5-curl postfix
sudo a2enmod vhost_alias rewrite
sudo service apache2 restart

(Optional) Add ServerName yourhostname to /etc/apache2/httpd.conf

Difference between coding style and error handling

In one of my previous projects some people were complaining that I was trying to force everyone to code in my style, what was really happening is that I kept telling my colleges to write proper error handling in their code.

If we are talking about code style, that implies that we are talking about the source codes that do exactly the same thing, all they differ is in the style they are written in.

Examples:

function isEven(number) {
   return !(number % 2)
}
function isEven(number) {
   if (number % 2) {
       return false;
   } else {
       return true;
   }
}
function isEven(number) {
   if (number % 2)
       return false;
   else
       return true;
}
function isEven(number) {
   if (number % 2) {
       return false;
   }

   return true;
}
function isEven(number) {
   var returnValue = true;
   if (number % 2) {
       returnValue = false;
   }

   return returnValue;
}

These all do the same thing but are written in different styles, I could use either of these in an application and I would get the same end results.

However this is not the case with the following examples:

// #1
function isEven(number) {
   if (typeof number !== 'number') {
       return;
   }
   return !(number % 2)
}
// #2
function isEven(number) {
   if (typeof number !== 'number') {
       throw new Error('Input argument is not a number type');
   }
   return !(number % 2)
}
// #3
function isEven(number) {
   return !(number % 2)
}

For these examples we would get different results for invalid inputs, therefore we cannot say that there are written in a different style, because they clearly don't do the same thing. All 3 of these examples behave differently for invalid inputs.

The problem with code like #1 is that if you give it something other then a number, it will return undefined which acts as false in a conditional statement. Your program will never know that it received a bad input, it will just continue executing and producing bugs in other places.

Previous Next