Skip to content

Instantly share code, notes, and snippets.


Huy Thái huyttq

  • Perth, Australia
View GitHub Profile
huyttq / AASM_FactoryGirl.rb
Created November 10, 2011 02:37
Override initial state of AASM by using 'mocha' mock
View AASM_FactoryGirl.rb
huyttq / gist:1354244
Created November 10, 2011 06:14
Using yield to execute
View gist:1354244
def send_task
self.class.execute { self.prepare!; self }
def self.execute
ActiveRecord::Base.connection.execute("LOCK TABLE tasks WRITE")
tasks = [*yield]
ActiveRecord::Base.connection.execute("UNLOCK TABLE")
huyttq / gist:1354248
Created November 10, 2011 06:17
Slice specific param to work well with cabybara
View gist:1354248
<%= link_to("Send", send_task_admin_path(task, params.slice(:page))) %>
huyttq / gist:1363082
Created November 14, 2011 02:15
.vimrc for ruby
View gist:1363082
" General
set nocompatible
set history=1024
set cf " enable error files and error jumping
set ffs=unix,dos,mac " support these files
filetype on
filetype plugin on
filetype indent on
huyttq / gist:1380019
Created November 20, 2011 08:54
Useful bash commands
View gist:1380019
History: Ctrl + r
Find: find /home/user -name abc.txt
Pipeline: vi `find /home/user -name abc.txt`
Ctrl-x, Ctrl-e will bring up an $EDITOR containing whatever is currently entered into the prompt. (opposed to editing last command actually entered)
Managing remote systems and trying to figure out what hardware you're on and whether it's healthy or not: dmidecode
Repeat last command with "sudo" prepended: sudo !!
Execute <command> with the argument to your previous command: <command> !$ / !* for get all args.
huyttq / gist:1813644
Created February 13, 2012 04:22
Zero downtime when migration
View gist:1813644
class << self
RemovedColumns = {'column_to_remove' => true}
def columns
cols = super
cols.reject { |col| RemovedColumns.has_key? }
huyttq / gist:1814612
Created February 13, 2012 07:28
Rails & Jenkins notes
View gist:1814612
Setup Redis server
huyttq / gist:1814610
Created February 13, 2012 07:27
Ruby code quality
View gist:1814610
huyttq / gist:1862679
Created February 19, 2012 09:06
Useful Vim commands
View gist:1862679
# Replace text across files
:args dir_path/*/* #(for 2 levels)
:argdo %s/, :expire.*)/)/gc | update
huyttq / gist:2000353
Created March 8, 2012 10:42
Install imagemagick
View gist:2000353
mkdir -p ~/local
command -v identify > /dev/null
if [ $? -eq 1 ]; then
echo "${bldgrn}Installing imagemagick into ${txtwht}$HOME/local/imagemagick${txtrst}"
wget -N --retr-symlinks
tar -xzvf ImageMagick.tar.gz
cd ImageMagick-*
./configure --prefix=$HOME/local/imagemagick