Legacy Deploy With Capistrano
So, you’re on a rescue project with some legacy code (and by “legacy” I almost always mean PHP). The old developer probably just FTP’ed changes up to the server. You could do the same, but frankly that fills me with dread. On a good day I don’t like deploys. What if something goes wrong?!?!?! To help me to relax, I use good tools that let me trust my deploy and allow me to rollback if something doesn’t work.
In a Rails project you’d get that security from Capistrano. Turns out that’s the right tool for you legacy project as well. Capistrano 2 had a few, easily addressed, Rails-centric tasks. However, Capistrano 3 is framework agnostic by default. (Am I implying PHP is a framework? No, I am not.)
Patching Between Git Repos
While the fame and free cars are nice, the reason I blog is to learn, or, as in this case, to help me remember things.
I work across a number of distinct Rails projects that share a common ancestry. Often a bug fix or a new feature in one needs to be ported to (some of) the others.
Because projects all live in their own repos, the changes can not be merged using Git. No, this is a job for patches. And when it comes to patching with Git, there are two posts about the process I can not live without.
When patching, three Git commands that come into play, git format-patch, git apply, and the somewhat obscure git am.
iTerm Tear Off Tabs
I like iTerm 2 (and I can not lie). I use a Mac and spend most of my days in the terminal (and Emacs). When a window system first came into my life, it was X Windows. It’s terminal software, xterm, had a pair of features that are hardwired into me, copy on select and paste on middle button (though these days getting a decent middle button is a pain). OS X’s Terminal does not do either of these things, so it’s out.
Let’s look at another feature of I like iTerm 2. Normally, opening a new window or tab creates a new login in your home directory, exactly what you’d expect from a terminal program. However, you can choose instead to open a shell in the current directory, letting you add another window on whatever you are doing.
Backups With Rsync and Launchd
Previously, I wrote about backing up files to Dropbox with rsync. I automated the process with cron the ancient UNIX “time-based job scheduler”. While OS X ships with cron, newer versions of the operating system favor launchd. launchd is much more than a cron replacement, on OS X it also fills the rolls of init, init.d/rc.d scripts, and inetd. It can be told to watch for changes in directories or drives to be mounted and run processes when those events happen.
launchd is powerful, but it’s use of XML config files makes it overkill for simple tasks that can be handled by cron. However, if the task isn’t so simple…
Debuging RAMPS Stepper Problems
This is a bit of a departure from my usual Ruby, Ops, and Security posts. However, recently I acquired a mostly completed RepRep 3D printer and wanted to document an issue I had to debug. One of the reasons I blog is to share the answers to problems for which the Google couldn’t find me an easy answer. And this problem was “Why does the y-axis stepper motor only move in one direction?”.
Quick and Dirty Backups With Rsync
One simple way to back up files is to copy them to Dropbox. However, manually copying files does not constitute a good backup, you’re going to forget.
Also, you want to be smart about it and just copy things that have changed or are new. My favorite tool for smart copies is rsync.
If you aren’t familiar with rsync, it’s a program for intelligently syncing one directory tree with another. It looks for additions, changes, and, optionally, deletions in a source directory (and it’s subdirectories) and make the destination an exact copy. After an initial copy is created, rsync is very efficient as further syncs only copy changes.
In my last post about an alias that opened a URL from the command line, I said:
open is OS X specific. On Linux you’d want xdg-open or gnome-open, on Windows, start, under Cygwin, cygstart.
A friend of mine reminded me that I forgotten a simple option for Ruby developers, his cross platform solution, Launchy.
Open Github Repos From the Command Line
If you’re ever sitting in a Git repository in the shell and want to view it on Github, here’s some quick laziness.
(The $ after the = is an example of using Bash’s ANSI C quoting mechanism.)
(CSH single quote escaping is even more convoluted…)
Basically, we grab the remote URL from with
git config, strip out
the repo path and slap https://github.com/ in front of it with
and then use
open to feed the new URL the default web browser.
This makes a couple presumptions:
- You are in a Git repo.
- You are using SSH style URLs.
- open is OS X specific. On Linux you’d want xdg-open or gnome-open, on Windows, start, under Cygwin, cygstart.
Making it smarter is left as an exercise to the reader.
(Symmetric) Encryption With Ruby (and Rails)
I wrote and maintain (though not as attentively as I’d like) a Ruby Gem, Strongbox, which adds Public-key Encryption support to Rails’ ActiveRecord. Simply put, Public-key Encryption is a form of encryption with two password, one to encrypt data and another to decrypt it. This is handy for web applications, any visitor can encrypt data using encryption password (the public key). However, if an attacker gains access to the server and steals the data and the app’s code, they still can’t decrypt the data because they lack the decrypt password (the private key).
The problem is you’re doing it wrong.
Open the iOS Simulator From the Command Line
When I need to test web apps on an iPhone or iPad, I use the iOS
Simulator that ships with Xcode1. The Simulator is intended for
developers testing native apps, however, Mobile Safari is installed
and I can use it to debug apps without a physical device. I’m
lazy and don’t want to open up Xcode just to
get to the Simulator. Fortunately, it’s a standalone app that lives in
/Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app. That’s way too much to type, aliases to the rescue.