Goodbye Vancouver, Hello London

vancouver.jpg

So I have left beautiful British Columbia and I’m back in Europe, in London of all places. I’ve gone full circle it seems!

I’m not going to bother going into the details of why I left Vancouver, but in short, you can’t extend a “two year working holiday” visa. Which totally sucks as after two years I had really set myself up over there.

ubc.jpg

So after many many goodbyes and cramming in as much touristy things as possible in the last couple of weeks I set sail back to London. Getting the cheapest possible flight which had two stopovers; Toronto (11 hours), Saint Johns (2 hours).

Eleven hours did not seem so bad to me when I was looking at the ticket however after my flight from Vancouver -> Toronto staying in the airport for anything over an hour did not seem appealing. So I got the train from the airport into the city. Unfortunately I hadn’t gotten any sleep during my flight at all so I was pretty exhausted and not so much in the mood to really explore Toronto. I spent about three hours just wandering about picking different places to sit down and rest, eventually giving up and going back to the airport to try sleep (no luck with that).

toronto.jpg

Saint Johns was uneventful, pretty much just had enough time to go and grab a cigarette outside and then re-do security before my flight. The flight from Saint Johns -> London seemed to take forever, again I got no sleep. I think I’m going to start drugging myself before long-haul flights in future, although I think that might make the stop-overs a bit more difficult 😛

But anyway, now I’m in London. Exchanging my money from CAD to GBP was very depressing, outside of that though re-exploring London has been a lot of fun!

I’ve got a double room in a flat for now, getting my own place initially just seemed like a terrible idea money wise. It’s nothing special but it will do for now.

camden.jpg

This week is going to be the CV and interview game, I have a couple of interviews lined up already and I’m going to apply to a bunch more jobs. I’m really not looking forward to going through the technical interview process all over again, it’s exhausting and very demoralizing at times. But it just unfortunately has to be done.

So if anyone reading this is in London and hiring do reach out to me, I can’t imagine it will take too long to find a job here however as there are many opportunities.

So that’s the personal update for now, there will likely be some more technical posts incoming in the near future.


Posted on May 26, 2016

Free SSL Certificates with LetsEncrypt and Ajenti-v

This is a quick post on how to use LetsEncrypt SSL certificates on your Ajenti-v setup .

Ajenti-v will probably be supporting this natively at some point, there is an open issue on their Github here. But in the meantime you can just follow these steps to start using LetsEncrypt now.

You can click this link and head to ‘Getting Started’ or you can just run these commands to install LetsEncrypt in the folder of your choice:

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt

So now LetsEncrypt is installed, LetsEncrypt doesn’t yet support nGinx and since that’s what I’m using I’ll assume that’s what you’re using, the automatic function won’t work for us so we will have to use the ‘certonly’ option.

Run the following command and follow the steps.

service nginx stop
./letsencrypt-auto certonly

Now you should get a message like:

Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/yourdomain.com/fullchain.pem.

You can now restart nginx by running:

service nginx start

Now that we have the cert, it’s time to see how we fit this into Ajenti. Open up the websites tab of Ajenti and open whatever website you’ve decided to do this for, hit the SSL tab and you will get this window:

Ajenti Certs Window

So the first box gets filled in with what the wizard returned to us:

/etc/letsencrypt/live/yourdomain.com/fullchain.pem

The second box gets filled in with the certificates private key:

/etc/letsencrypt/live/yourdomain.com/privkey.pem

Now Ajenti knows what certificate to use, it is time to turn SSL on, lets get the Advanced configuration out of the way first:

ajenti-advanced-cert.png

The ‘Custom top level configuration’ you see will automatically redirect users accessing your website on http:// to the https:// domain.

Lastly we just need to change the website port from the default 80 to SSL’s 443:

ajenti-ssl-ports.png

Apply changes, and check to make sure your website is still redirecting.


Posted on March 21, 2016

Easy Caching with StashPHP

Frequently with PHP you are going to need to cache things, mostly expensive SQL queries, but also data you aren’t going to want to be inserting into the database on every page hit, for instance website statistics.

With PHP we have a few options to achieve this;

  • Caching with the file system .
    • Pros:
      • Works well with the Opcode cache
      • Usually the fastest method of caching for small or medium websites
    • Cons:
      • Clearing the cache can be a lot slower as you will have to recursively search through path’s and delete.
  • Caching with SqlLite
    • Pros:
      • Can be substantially faster than a full-blown RDBMS
      • All data is stored in a normal file in the host’s file system.
    • Cons:
      • Can only support one writer at a time, which can cause high file system latency, which is inconvenient if there are many clients trying to access it simultaneously.
  • Caching with APC
    • Pros:
      • Makes PHP faster for you through the so called opcode caching.
      • No special configuration required.
    • Cons:
      • Practically none
  • Caching with Memcached
    • Pros:
      • Allows machines to pool their memory together as one large memory cache, perfect for large websites.
      • Cross platform and cross RDBMS
    • Cons:
      • Stores data in the RAM, not ideal for small systems
      • Is considered to be a volatile in-memory key/value store
  • Caching with Redis
    • Pros:
      • Can act like memcached as a key/value store however it’s really a data structure server.
      • Persistence to disk, by default.
      • Values up to 512MB in size
      • Built in clustering
      • Extremely fast at everything
    • Cons:
      • The more objects you put in it, the more memory its going to use.

So as you can see there are a bunch of different systems that handle caching in arguably better or worse ways depending on how big your website is. Putting a small website on Redis is probably overkill, you might already have set up a RDBMS solution and now not want to change to a key value store etc.

This is where StashPHP comes in, you basically use the StashPHP library to cache things like so:

First you setup the driver to use, lets just use File System for the moment:

<?php
// Create Driver with default options
$driver = new Stash\Driver\FileSystem();
$driver->setOptions(array());
// Inject the driver into a new Pool object.
$pool = new Stash\Pool($driver);

Now you can setup your by wrapping the following code around your code:

<?php
// Get a cache item.
$item = $pool->getItem('path/to/item');
// Attempt to get the data
$data = $item->get();
// Check to see if the data was a miss.
if($item->isMiss())
{
// Let other processes know that this one is rebuilding the data.
$item->lock();
// Run intensive code
$data = codeThatTakesALongTime();
// Store the expensive to generate data.
$item->set($data);
}
// Continue as normal.
useDataForStuff($data);

Later on when you decide to add another cache, rather than needing to go rewrite all your caching calls etc. you can just change the setup of the drivers like so:

<?php
$subDrivers = array();
$subDrivers[] = new Stash\Driver\Apc();
$subDrivers[] = new Stash\Driver\FileSystem();
$subDrivers[] = new Stash\Driver\Memcached();
$options = array('drivers' => $subDrivers);
$driver = new Stash\Driver\Composite($options);
$pool = new Stash\Pool($driver);

This saves you a bunch of time and allows testing what suits your application best.


Posted on September 08, 2015

Software I’m using to track tasks & time

So lately I’ve been trying to manage my time better, with countless personal projects and legacy applications to support I find not properly tracking what I’m doing to surprisingly be more of a waste of time than tracking my time, even when you take in the time lost by tracking said time.

Firstly, I already use Trello for organizing my tasks across bigger projects, I’m pretty sure most people do, it’s one of the best task management tools for things that are just general planning rather than bugs. For managing bugs I’m using JIRA or Github Issues depending on if the project is open source or not. I’m generally trying to do as much open source as possible lately. For more general tasks I’m using Todoist , which I recommend checking out if you haven’t, it has a very clean and simple interface.

So with all that in mind I set out to find an application that could potentially work with all of the above as well as give me time tracking. Handily enough I found Toggl , which is completely free until you want to export invoices etc, which I don’t really have a need for right now.

Toggl just takes all the hassle out of time tracking, after installing it’s browser plugin Toggl integrates with most task tools. Github issues , JIRA , Trello , and Todoist just to name a few.

So not only do they make it really easy, but how they actually output your data is really handy also.

Screenshot of Toggl

Another one for any of you programmers is WakaTime.

Screenshot of Wakatime

Wakatime allows you to install a plugin in your IDE of choice, pretty much all are supported, it basically reports on what programming languages your spending the most time using. Their graphs are not as pretty as Toggl’s but I still enjoy them!


Posted on March 29, 2015

The Perfect Web Server - Nginx, Ajenti, Ubuntu

ajenti-dashboard.png

I’ve done a lot of installing of web servers over the last while, some of which have been effortless, others a thorn in my side. I’ve decided to compile a guide for my latest server setup that I’ve fallen in love with;

First a breakdown of what we’ll be installing today;

Nginx : (pronounced Engine X) is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Nginx doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly,predictable amounts of memory under load. Even if you don’t expect to handle thousands of simultaneous requests, you can still benefit from Nginx’s high-performance and small memory footprint. Nginx scales in all directions: from the smallest VPS all the way up to clusters of servers.

Ajenti : “The admin panel your servers deserve.” Easily extensible using Python. Plugin development is fast and pleasant with rich APIs. Includes lots of plugins for system and software configuration, monitoring and management.

Ajenti V : A plugin for Ajenti that makes website setup easy – including app servers, database, and routing.

Ubuntu : If you don’t know what Ubuntu is we’re in trouble.

Now I’m going to take a leap of faith and assume you can either install Ubuntu yourself or figure out how to get a server with it already. A DigitalOcean droplet works perfectly here. So lets log in as root and run all this:

#Insall Ajenti
apt-get update
wget http://repo.ajenti.org/debian/key -O- | apt-key add -
echo "deb http://repo.ajenti.org/ng/debian main main ubuntu" >> /etc/apt/sources.list
apt-get update
apt-get install ajenti
service ajenti restart
# Uninstall Apache2
sudo apt-get autoremove && sudo apt-get remove apache2*
# Install Ajenti-v
apt-get install ajenti-v ajenti-v-nginx ajenti-v-mysql ajenti-v-php-fpm php5-mysql
# If you <3 Ruby
apt-get install ajenti-v-ruby-unicorn ajenti-v-ruby-puma
# If you need Python
apt-get install ajenti-v-python-gunicorn
# If you need nodeJS
apt-get install ajenti-v-nodejs
# If you want FTP
apt-get install ajenti-v-ftp-pureftpd
# If you want mail
apt-get install ajenti-v-mail
# If you want POP support (for gmail etc.)
apt-get install courier-pop
# Restart All Services
sudo service php5-fpm restart
sudo service nginx restart
sudo service ajenti restart

You should now be able to log in to your Ajenti control panel at https://yourserver.com:8000 with:

username: root
password: admin

Now that’s done you’ll notice if you open /etc/nginx/nginx.conf that files inside /etc/nginx/conf.d/ are loaded before any other .conf files, this is where you should put any additional configuration for Nginx. However if you are just configuring a specific domain or website you should just put the configuration in the Ajenti website configuration’s advanced section.


Posted on February 18, 2015