Containerizing this blog

Recently I have started using Docker more and more, and for practice, I decided to containerize this WordPress blog. The blog was originally set up on a VPS running Apache, PHP, and MySQL. Multiple other domains were hosted on that server as well. Backups are hard, and if I ever needed to switch servers, the configuration and initial setup would be a nightmare. The machine at the time was running PHP 5.5 on Ubuntu 14.04. With the release of Ubuntu 16.04 and PHP 7, I had wanted to upgrade, but it would have been a very tedious task involving much manual labor. However, if I converted everything to run in containers, then the upgrade process becomes trivial.

I did not want to manually set up a new machine, so I chose Ansible to provision my new server since it is extremely easy to get started on, and does not require a server/client model as other tools do (such as Chef). I wrote a few playbooks and roles to provision web servers that perform all the basic tasks like user creation, adding SSH keys, installing packages, etc. Then it was time for the real work.

First, I committed initialized a new git repository and committed all the site source code into a directory called src. The Dockerfile is relatively simple:

Since there are multiple domains hosted on the same server, I needed to use my custom Apache config file. This uses the official PHP 7 image with Apache to build a base image for the site. Now we need another container to run the database.

Docker Compose is an awesome tool that makes linking containers together very simple. I created a docker-compose.yml file:

The web container builds the Dockerfile above, and the db container is linked together with Docker Compose. After running docker-compose up and restoring the MySQL database backup, I now have this blog running in containers, on PHP 7. The best part is that with the restart: always option, the containers will automatically restart themselves, even across system reboots.

Useful Xcode 7 plugins for Swift 2

Recently I started picking up Swift 2 with some practice projects and once again started using Xcode. Many things have changed since my last encounters with Xcode and Objective-C in the iOS 4.x days, but I am really enjoying Swift so far. CocoaPods is still around and remains the best dependency manager, although Apple has recently released the Swift Package Manager which still seems to be in alpha stages, until the release of Swift 3.

Xcode remains largely similar to previous versions, although there is now an excellent plugin manager called Alcatraz. I have installed a few plugins and wanted to share a few very useful ones. All of these are available on Alcatraz, so install it via the link above.

  1. Tomorrow Night
    Screen Shot 2015-12-31 at 5.19.59 PM
    A very popular dark color scheme available for many platforms and tools. Looks great with Swift!
  2. SCXcodeMinimap
    minimap
    If you have ever used SublimeText, then you’re familiar with its iconic code minimap feature. This brings that functionality to Xcode.
  3. Backlight
    Screen Shot 2015-12-31 at 5.25.21 PM
    A very subtle but useful tweak. Highlights the current selected line with a custom background color. Sometimes the cursor is hard to see and you lose sight of which line you’re actually on when jumping around code.
  4. MarvinPlugin
    Screen Shot 2015-12-31 at 5.27.45 PM
    A collection of text manipulation commands with customizable keyboard shortcuts. As someone who is used to using PHPStorm, I really missed the “Duplicate Line” shortcut which I assigned to ⌘+D.
  5. BBUDebuggerTuckAway
    Xcode already hogs so much screen real estate with all its frames, and this automatically hides the debugger once you start typing into the source code window.
  6. FuzzyAutocomplete
    Screen Shot 2015-12-31 at 5.45.32 PM
    Normally code autocompletion requires contiguous characters to be input, but this plugin will let autocomplete use the same algorithm as the “Open Quickly” option for fuzzy search.
  7. XAlign
    xalign
    Neat freaks and readability snobs will love this one. Allows you to automatically align your lines for example based on the ‘=’ sign.

That’s all for now. I’ll try to keep this post updated as I run into more plugins. Please also share your favorites in the comments!

Hired

At the beginning of this year, I started a new position as a software engineer through a job I had found through Hired, a service that connects employers to job seekers. After a few coding challenges, participation on their marketplace quickly led to several interviews with a bunch of tech companies, mostly startups.

Fast forward ~8 months. I receive a mysterious package in the mail.

IMG_0051 IMG_0052 IMG_0053

Overall, a very pleasant surprise from Hired. Some cool swag and an expensive bottle of Dom to celebrate, albeit a bit late. Why are they doing this? Probably so people post about it online, case in point. They also make a nice chunk of change from the finders fee for placed candidates as well. My only complaint? They got my t-shirt size wrong.

 

My dotfiles

It wasn’t until my first real full-time job that I really started using vim. I had used emacs for a few courses in college, but never really got used to it. Now that I’ve been using vim for about 3 years, I have it configured to the point that I am comfortable performing most code editing in it.

Another tool that I recently (~1 year) picked up is tmux. It is the natural alternative to screen, which I did not particularly like. I have also customized tmux to a certain point that I am comfortable doing most terminal work in it.

All linux users customize their environment to some degree, so I have decided to upload my dotfiles on github. It contains my custom settings for vim, tmux,  bash, and git. The commenting within the files is pretty sparse at the moment, but I will improve them gradually as I see fit. The repo is available on github: https://github.com/jqin/dotFiles

Here is a screenshot of my setup showcasing a vim session running under tmux through PuTTY on windows:

putty

Initializing a brand new git repo and pushing it to a remote source

Hello world! I wanted some kind of content to go along with my first post, so I decided to make a quick tutorial on starting a new GitHub repo.

GitHub is the most popular git repository hosting service on the web right now. You can create as many public repos as you want with a free account, but private repos will cost you a few dollars a month. I’m sure most git users are familiar with the most common commands ( git status, git commit , etc.) but some people like me still have to look up the commands for initializing a new remote repository. Here I am consolidating all that info to help myself and others streamline this process.

First, create a new repository on GitHub, but do not check the option to initialize the repo with a README. This is because we want the repo to be empty so we can push our local version to it.

On your local box, if this is your first time using git, you will need to set your username and email using these two commands:

Then cd into your working directory

Initialize the repo

Add the files

Make the first local commit

Finally, add the remote GitHub repo and push it out

You should now be able to view your repo on github.com!

github