Skip to content

Instantly share code, notes, and snippets.

View incoming_emails_controller.rb
# Add to config/routes.rb
# post 'incoming_emails' => 'incoming_emails#create'
require 'mail'
class IncomingEmailsController < ApplicationController
skip_before_filter :verify_authenticity_token, only: :create
def create
mail =[:message])
View bash_profile
echo Entering vagrant... Ctrl-C to abort
sleep 1
cd ~/
vagrant up && vagrant ssh && exit
choonkeat / activerecord.stack.rb
Last active Aug 29, 2015
Drop this file into config/initializers/ and enjoy SQL logging with stacktrace
View activerecord.stack.rb
# set env FULL_STACKTRACE=1 for full stacktrace
# set env DEBUG_LOG=1 to turn this on (default off)
if defined?(ActiveRecord::LogSubscriber)
module ActiveRecord
class LogSubscriber
def sql(event)
self.class.runtime += event.duration
return unless logger.debug?
choonkeat / hash.csspath.rb
Created Jun 2, 2014
Inefficient but expressive
View hash.csspath.rb
Hash.class_eval do
# returns an array of values
def csspath(path, options = {})
Nokogiri::HTML(self.to_xml).css(path.dasherize).collect {|element|
result = Hash.from_xml(element.to_s)
(options[:include_keys] ? result : result.values.first)
choonkeat / mitm.bash
Created Jun 3, 2014
peep at traffic e.g. elasticsearch request & response
View mitm.bash
# usage: [proxy port] [target port]
socat -v -d -d -d TCP4-LISTEN:$1,reuseaddr,retry,fork TCP4:localhost:$2,retry
choonkeat / routes.patch.rb
Last active Aug 29, 2015
make "GET /assets/yourfile.css" redirect to the correct "<asset host>/assets/yourfile<-digest suffix>.css" url
View routes.patch.rb
match "/assets/*path" => lambda {|env|
path = env['REQUEST_PATH']
Rails.cache.fetch("v9.assets.#{path}", expires_in: 1.hour) do
if found = Rails.application.assets.find_asset(File.basename(path))
[302, { 'Location' => "#{Rails.application.config.action_controller.asset_host}#{File.dirname(path)}/#{found.digest_path}" }, []]
[404, {}, []]
}, via: [:get] # /lambda

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF


To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

View generateUUID.js
function generateUUID(){
var d = (window.performance && && ||
( && ||
(new Date().getTime());
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x7|0x8)).toString(16);

Keybase proof

I hereby claim:

  • I am choonkeat on github.
  • I am choonkeat ( on keybase.
  • I have a public key whose fingerprint is 5615 96F6 F675 FBD1 EE75 A2AF 6B5C 347F 317F DF7C

To claim this, I am signing this object:

View application.js
(function() {
function direct_upload() {
console.log('direct_upload', this);
var ele = this;
new DirectUpload({
file_element: ele,
onProgress: function(percent, message) {
console.log('onProgress', arguments);
onError: function(status) {