Skip to content

Instantly share code, notes, and snippets.

View shivabhusal's full-sized avatar

Shiva Bhusal shivabhusal

View GitHub Profile
@mcjim
mcjim / .bashrc
Last active July 21, 2023 22:16 — forked from henrik/.bashrc
Git branch, dirty and stash state in Bash prompt.
# Quick fork by @mcjim to add stash status and tweak to suit his style.
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# host dir master $ # clean working directory
# host dir master* $ # dirty working directory
# host dir master*^ $ # dirty working directory with stash
# host dir master^ $ # clean working directory with stash
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
@jcasimir
jcasimir / friendly_urls.markdown
Created September 11, 2011 15:48
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@mdunsmuir
mdunsmuir / mdop.rb
Created October 17, 2012 22:59
ruby alternative option parser
#
# simple option parser that supports negative numbers as arguments, because I needed to do that
#
# should mostly be a drop-in replacement for OptionParser's basic usage patterns
#
class MDOP
#
# class to hold each option's data (including its Proc)
#