Archive for the ‘bash’ Category

Great little bash snippet to summarize your daily git commits.

Posted on January 9th, 2012 in bash, git | No Comments »

For general invoicing and hour tracking, I like to post the details of my git commits. Though, I had my own little version of this script, this one posted at stackoverflow was a lot better looking. Posted here for posterity:

function gdaily {
    NEXT=$(date +%F)
    echo "CHANGELOG"
    echo ----------------------
    git log --no-merges --format="%cd" --date=short | sort -u -r | while read DATE ; do
        echo [$DATE]
        GIT_PAGER=cat git log --no-merges --format=" * %s" --since=$DATE --until=$NEXT

Which looks like:

 * Refactor list portfolio page css and js.
 * include to load fake api data until it is ready. Portfolio list working again.
 * CurrentUser model defaults and code cleanup.

 * Upgrade portfolio call from GET and POST. To be discussed in tomorrow's standup.

Convert a file to utf8-encoding via command-line

Posted on June 20th, 2011 in bash, mongodb | No Comments »

I had an issue importing a large CSV to mongodb using mongoimport. I was getting the error:

exception:Invalid UTF8 character detected

Use iconv, a program that seems to be on both mac and most unix systems:

iconv -f ISO-8859-1 -t utf-8 accounts.csv > accounts-utf8.csv

Then continue on your merry way:

mongoimport --type csv --headerline --drop --port 7777  -d dbname -c collectionname --file accounts-utf8.csv

Using make to concatenate JS files

Posted on December 21st, 2010 in bash, git | No Comments »

In a previous project I used a bash script in conjunction with a git hook to concatenate all my js files and increment build numbers in html file references (cache-kill) after every commit. This was convenient at first, but quickly got annoying as I wasn’t always committing js file changes. I eventually opted to just call the script manually before any deployment to qa or production, thinking I would automate it again one day to only be called when JS files were changed (git hooks probably provide this info).

Today I read up on make. I’ve always used make in the past to build versions of a program for my system but never how it actually worked. When ran, it essentially reads in a list of dependencies, and if the source files have modification times newer than the “built” file, it runs your script to rebuild them. Concatenating javascript files seems like the perfect opportunity for this. I’ll rewrite my bash script to use make, set it as a git hook, and should be able to forget it. Will let you know how it goes.

Bash argument unpacking

Posted on September 10th, 2009 in bash | No Comments »

I’m not a bash expert but my .bash_profile is packed with shortcut goodness to do all kinds of things on the quick. Most recently, I wondered how to fix up some of my function shortcuts to take any number of arguments (similar to this argument unpacking entry on how to do it in JavaScript and Ruby).

With a little Googling and IM’ing around to friends (thanks Bryan), my limited argument functions:

function sc {
        svn commit $1 $2 $3 $4 $5 $6               

now take an unlimited number of arguments:

function sc {
        svn commit $@