Skip to content

Instantly share code, notes, and snippets.

@baopham
baopham / prompt.sh
Created April 27, 2012 18:10
Glue the bash prompt to the first column
PS1="\[\033[G\]$PS1"
@baopham
baopham / rails-note.md
Created April 22, 2012 02:09
Rails Note

Asset directories

In versions of Rails before 3.0 (including 3.0 itself), static assets lived in the public/ directory, as follows:

public/stylesheets
public/javascripts
public/images

Files in these directories are (even post-3.0) automatically served up via requests to http://example.com/stylesheets, etc.

@baopham
baopham / autovivification.py
Created April 18, 2012 17:45
Python Autovivification
class AutoVivification(dict):
"""Implementation of perl's autovivification feature."""
def __getitem__(self, item):
try:
return dict.__getitem__(self, item)
except KeyError:
value = self[item] = type(self)()
return value
a = AutoVivification()
@baopham
baopham / css-tips.css
Created April 12, 2012 19:16
CSS notes
/* Opacity */
filter:alpha(opacity=95); /* For IE */
-moz-opacity:0.95; /* Older versions of Mozilla */
-khtml-opacity: 0.95; /* For Sarari 1.x */
opacity: 0.95; /* General Usage */
@baopham
baopham / mobile-redirect.mkd
Created April 11, 2012 22:29
Mobile Redirect js Snippets

Redirect Mobile Devices

<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "mobile.html";
}
//-->
@baopham
baopham / .osx
Created April 4, 2012 17:45
Defaults commands for OSX
# GistID: 2304197
# Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Enable subpixel font rendering on non-Apple LCDs
defaults write NSGlobalDomain AppleFontSmoothing -int 2
# Enable the 2D Dock
defaults write com.apple.dock no-glass -bool true
@baopham
baopham / .git-completion.sh
Created April 1, 2012 01:13
git-completion
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
@baopham
baopham / bash_completion.sh
Created April 1, 2012 01:12
bash_completion
#
# bash_completion - programmable completion functions for bash 3.2+
#
# Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
# © 2009-2011, Bash Completion Maintainers
# <bash-completion-devel@lists.alioth.debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
@baopham
baopham / .bash_profile
Created February 23, 2012 20:35
bash_profile
# bash prompt
if [ -n "$SSH_CONNECTION" ] ; then
export PS1="\[\033[G\]\[\033[0;32m\]\u@\h\[\033[0;32m\] \w\$(__git_ps1) \$\[\033[00m\] "
else
if [ "$USER" != "baopham" ] ; then
export PS1="\[\033[G\]\[\033[0;32m\]\u \w\$(__git_ps1) \$\[\033[00m\] "
else
export PS1="\[\033[G\]\[\033[0;32m\]\w\$(__git_ps1) \$\[\033[00m\] "
fi
fi
@baopham
baopham / mvim.sh
Created February 23, 2012 20:32
Modified mvim script to have options of opening files in tabs or new windows
#!/bin/sh
#
# This shell script passes all its arguments to the binary inside the
# MacVim.app application bundle. If you make links to this script as view,
# gvim, etc., then it will peek at the name used to call it and set options
# appropriately.
#
# Based on a script by Wout Mertens and suggestions from Laurent Bihanic. This
# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
# Weber and Bjorn Winckler, Aug 13 2007).