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 = Mail.new(params[:message])
View mail2webhook.node.js
var http = require('http');
var querystring = require('querystring');
var MailParser = require("mailparser").MailParser; // https://github.com/andris9/mailparser
var server = http.createServer();
server.addListener('request', function(req, res) {
var chunks = [];
req.on('data', chunks.push.bind(chunks));
req.on('end', function() {
var mailparser = new MailParser();
View bash_profile
echo Entering vagrant... Ctrl-C to abort
sleep 1
cd ~/
vagrant up && vagrant ssh && exit
@choonkeat
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
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)
}
end
end
@choonkeat
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
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}" }, []]
else
[404, {}, []]
end
end
}, via: [:get] # /lambda
View GIF-Screencast-OSX.md

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

Instructions

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

View generateUUID.js
// http://stackoverflow.com/a/8809472/136558
function generateUUID(){
var d = (window.performance && window.performance.now && window.performance.now()) ||
(Date.now && Date.now()) ||
(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);
});
View keybase.md

Keybase proof

I hereby claim:

  • I am choonkeat on github.
  • I am choonkeat (https://keybase.io/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: