Skip to content

Instantly share code, notes, and snippets.

View jimmynguyc's full-sized avatar

Jimmy Ngu jimmynguyc

  • Kuala Lumpur, Malaysia
View GitHub Profile

Pretty prompt

Add this into ~/.bash_profile

parse_git_dirty() {
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo -en ""  
}
parse_git_info() {
   git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ (\1)$(parse_git_dirty)/" 
@jimmynguyc
jimmynguyc / README.md
Last active August 29, 2015 13:57
Sample project readme

Contributing

Setup

Clone the repo and setup Apache / Nginx:

$ cd ~/Sites
$ git clone git@github.com:project-github-account/Project.git
@jimmynguyc
jimmynguyc / .bash_profile
Created August 11, 2014 04:57
.bash_profile
parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo -en "⸕"
}
parse_git_info() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ (\1)$(parse_git_dirty)/"
}
parse_svn_dirty(){
SVN_STATUS="`svn status 2> /dev/null`"
if [ -z "$SVN_STATUS" ]
@jimmynguyc
jimmynguyc / word_wrapper_behavior
Created September 2, 2014 05:03
Word Wrapper Behavior
# assert_equal(expected, actual, msg = nil)
assert_equal "word", wrap("word",4)
assert_equal "word", wrap("word",100)
# within word
assert_equal "wor\nds", wrap("words",3)
assert_equal "word\ns", wrap("words",4)
assert_equal "word\nword", wrap("word word",4)
@jimmynguyc
jimmynguyc / setup-rbenv.sh
Last active September 14, 2015 09:33
Install ruby dependancies
#!/bin/bash
sudo apt-get update
sudo aptitude install -y build-essential git libssl-dev libreadline6 libreadline6-dev libpq-dev nodejs curl
sudo aptitude install -y postgresql redis-server nginx monit
# Rbenv
cd ~/
curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
cat <<'EOF' >> ~/.bashrc
@jimmynguyc
jimmynguyc / install-rails-on-koding.sh
Last active December 15, 2015 14:30
Installing Rails on Koding.io
#! /bin/bash
# Run with: bash <(curl -L http://bit.ly/install-rails-on-koding-v4_2)
date1=$(date -u +"%s")
sudo apt-get update
sudo apt-get -y install build-essential zlib1g zlib1g-dev sqlite3 libsqlite3-dev git libssl-dev libreadline-dev libxml2-dev libpq-dev nodejs
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
@jimmynguyc
jimmynguyc / capistrano-puma-setup-first-time.txt
Last active October 9, 2016 10:46
Setup Capistrano Puma First Time
In Gemfile
=========
gem 'capistrano-rails'
gem 'capistrano-rbenv'
gem 'capistrano-rbenv-install'
gem 'capistrano-safe-deploy-to'
gem 'capistrano-sidekiq'
gem 'capistrano3-puma'
In Capfile
@jimmynguyc
jimmynguyc / first_haiku.rb
Last active September 22, 2015 08:10
My first Ruby haiku
begin ordering pizza for twenty,
people in the meetup; it was still
not enough to last till
the end; so i have decided
to get more pizza before the
end if people != twenty
@jimmynguyc
jimmynguyc / activerecord_without_rails.rb
Last active November 21, 2015 22:07
ActiveRecord without Rails
require 'active_record'
require 'sqlite3'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => "teachers.db"
)
# Migration
ActiveRecord::Schema.define do