Skip to content

Instantly share code, notes, and snippets.

@huydx
huydx / gist:4583944
Created January 21, 2013 06:06
grep color
grep -Ri --color=always --include="*.rb" execute .
@huydx
huydx / gist:4634123
Created January 25, 2013 12:35
kill sh
kill $(ps aux | grep 'proc_name' | awk '{print $2}')
@huydx
huydx / gist:4707648
Created February 4, 2013 16:00
count line rb
find . -name "*.rb" | grep -v test | xargs wc -l
@huydx
huydx / gist:4707955
Created February 4, 2013 16:57
load lib into auto load path
config.autoload_paths += %W(#{config.root}/lib)
@huydx
huydx / oshi.rb
Created February 5, 2013 16:03 — forked from anonymous/oshi.rb
require 'rubygems'
require 'eventmachine'
require 'em-websocket'
require 'json'
class Connection
attr_accessor :socket, :user_id
def initialize(socket, user_id)
@socket = socket
require 'benchmark'
require 'ruby-prof'
names = ["matz", "rossum", "ryal", "ritchie", "brendan"]
n = 5000
class Array
def method_missing name, *argv
super unless name =~ /^sort_by_(¥w+)_(asc|desc)$/
condition = ($2 == "asc" ? "{ |a, b| a.%s <=> b.%s }" : "{ |a, b| b.%s <=> a.%s }") % [$1, $1]
@huydx
huydx / gist:5031184
Created February 25, 2013 16:46
convert text to html with simple format
raw sanitize(simple_format(post.content), :tag => %w(br p))
@huydx
huydx / gist:5219891
Last active December 15, 2015 06:59
prompt scheme
export PS1='\e[0;36m\u⌘ \e[0;35m\W \e[0;33m`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`\e[m\]'
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@huydx
huydx / gist:5329449
Created April 7, 2013 07:35
scala coursera course week 2
package funsets
import common._
/**
* 2. Purely Functional Sets.
*/
object FunSets {
/**
* We represent a set by its characteristic function, i.e.