Saturday, September 27, 2008

Remove Gems By Prefix

If you are working with Merb or DM you know that approximately a gazillion gems are involved.  When, for whatever reason, I want to remove them it is a pain to do by hand.

Here is a simple script to help:

gem list --local | grep $prefix  | awk '{ print $1 }' | xargs sudo gem uninstall

I saved mine as remove_gem_by_prefix, gave it executable permissions and placed it in my path.

Now I can issue the commands:

$ remove_gem_by_prefix merb


$ remove_gem_by_prefix dm

And they all get blasted.  You do need to be careful to make sure the prefix you provide is unique to the gems you wish to remove.

Monday, September 15, 2008


Inspired by Rein Henrichs Hack && Ship, I have created Git-O-Mator.

Git-O-Mator is more name than these 2 simple scripts deserve, but what fun is naming small?

Git-O-Mator can be found on GitHub, and contains the scripts new_repo and hack.  

New_repo was originally mentioned in the last blog post "Quick Remote Git Repository Creation Script", and has the syntax of:

new_repo foo

Which will create a Git repository locally and on a remote host account that you configure.

Hack is very similar to Hack && Ship.  Syntax is:

hack on

This will automatically switch to the default branch which you can easily configure. Alternatively you can use:

hack on foo

Where "foo" is the name of the specific branch you wish to use.  If the branch does not exist, it is created.  

To rebase with the master, you have:

hack sync

To merge and push to your remote repository:

hack push

It also supports Rein's ssp (Simple Software Process) with:

hack ssp

Which is equivalent to hack sync && hack push.  If you prefer hack sync && rake && hack push, then you may use the -t flag for testing:

hack ssp -t

Silly little experiment.  If you see room for improvement, feel free to fork and improve!

Saturday, September 13, 2008

Quick Remote Git Repository Creation Script

If you are using Git for your source code management, GitHub is an awesome tool. It especially shines for public projects where you freely allow others to fork your code and possibly pull patches back in.

Sometimes I'm just working on a project that I would prefer to keep in a private repository. GitHub provides paying accounts with such an option. However, I already have hosting accounts that are terribly underused. Here is a little script I use to create a remote git repository on one of my VPS accounts that I can then pull from and push to.

A hosting account which you can ssh / scp into.

The Script

$ vim new_repo

#! /bin/sh

# You must adjust these variables for your specifc hosting account.
# Remote user you will connect as.
# The IP address you will SSH / SCP to.
# The remote path you wish to store your .git repositories in.

if [ -d $1 ]; then
  echo "EXITING: Local directory '$1' already exists."
  exit 0
  mkdir $1
  cd $1
  git init-db
  touch README
  git add .
  git commit -m "Initial Repository Creation"
  cd ..
  git clone --bare $1/.git $1.git
  echo "** Copying new repository $1.git to $REMOTE_HOST:$REMOTE_REPO_PATH"
  rm -rf $1.git
  rm -rf $1
  echo "** Cloning locally at $PWD/$1"

exit 0

Or get it from GitHub


Of course, you will need to REMOTE_USER="admin" with an actual user on your hosting account, adjust REMOTE_HOST="123.456.123.456" to point to your accounts IP address, and edit REMOTE_REPO_PATH="/home/admin/repos/" with whatever path you wish to contain your Git repositories.

Once that is done, provide executable permissions.

$ chmod +x new_repo

That's it. Now if you execute:

$ ./new_repo testing

You will end up with /home/user/repos/testing.git on your remote host, and ./testing locally. From ./testing you can git push to send commits to the remote repository, and git pull to retrieve from the remote repository.

If you see room for improvement, I'm sure there is some, please leave a comment with your revision!