Insights on Ruby, Git, jQuery, Cappuccino, WordPress, Debian and OS X. Please subscribe if you find something useful!

Managing Broken Symlinks

Posted: November 5th, 2009 | Author: Jerod | Filed under: Bash | Tags: , , | Comments

I just added two new functions to my bashrc which make it super-simple to find & remove broken symbolic links on your system.

They’re simple wrappers around the ever-useful “find” utility:

function find_broken_symlinks() { find -x -L "${1-.}" -type l; }
function rm_broken_symlinks() { find -x -L "${1-.}" -type l -exec rm {} +; }

You can call the functions with a specific path:

jerod@mbp:~$ find_broken_symlinks /usr/local/bin

Or you can call them sans argument to search your current working directory:

jerod@mbp:~$ find_broken_symlinks

Enjoy!


Avoid Sore Fingers While SSHing Around

Posted: May 14th, 2009 | Author: Jerod | Filed under: Debian | Tags: , | Comments

If you’re anything like me, you’ve gotten accustomed to commands like this:

ssh [user]@[remote.server.com]

If you find yourself connecting to the same machines repeatedly, save a few keystrokes by creating a handy alias for them. Create (or edit) “~/.ssh/config” and add as many of these as your little heart desires:

Host [the alias]
HostName [domain name or IP address]
User [the account to login as]

Now you don’t have to use the full command to access the machine, just use the alias! For example, here is how I access one of my DreamHost servers:

ssh dh

The same goes for SCP! So, to secure copy a file (my_file.txt) in my current directory to the same machine I would simply issue:

scp my_file.txt dh:

Ahh… that is easy on the fingers! What else can we do with SSH config files?


Easy Configuration with Ruby and Yaml

Posted: August 19th, 2008 | Author: Jerod | Filed under: Ruby | Tags: , | Comments

Even trivial apps need to be configured. I used to simply define my app config somewhere near the top of the file, as many others do.

However, this becomes troublesome in a few common scenarios:

  1. You want to share your source code with somebody else, but not your super-secret password
  2. Your application becomes more complex and multiple areas need access to configuration variables

Abstracting configuration out of your Ruby app and into a separate Yaml file is super-simple. Here’s some codey code to use as an example:

# this is 'myapp.rb'
require 'yaml'
CONFIG = Yaml.load_file("config.yml") unless defined? CONFIG
 
puts "Your super-secret password is #{CONFIG['password']}"

Can it get any easier than that? I submit that it, in fact, cannot get any easier. You probably want to know what the config.yml file looks like, huh:

 # this is my 'config.yml'
username: sant0sk1
password: awesome

Now if you want to share your source with a friend, perhaps via git, you can just add config.yml to the .gitignore file in your repository and create a config-sample.yml which holds dummy values.

Any questions?