Skip to content

Instantly share code, notes, and snippets.

@huydx
huydx / .gitconfig
Created April 11, 2014 07:22
.gitconfig
[core]
pager = less
editor = vim
[alias]
ci = commit -v
st = status
di = diff
co = checkout
br = branch
l = log --date=local
@huydx
huydx / gist:9406254
Created March 7, 2014 06:19
thrift error
gem install thrift -- --with-cppflags='-D_FORTIFY_SOURCE=0'
@huydx
huydx / gist:8911290
Created February 10, 2014 06:28
therubyracer-mavericks
brew tap homebrew/dupes # Thanks Tom
brew install apple-gcc42
export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2
brew uninstall v8
gem uninstall libv8

Set the Mac OS X SOCKS proxy on the command line

a.k.a. what to do when your ISP starts blocking sites :(

Set the SOCKS proxy to local SSH tunnel

networksetup -setsocksfirewallproxy "Ethernet" localhost 8080

To clear the domain and port

@huydx
huydx / proxy.rb
Created January 27, 2014 13:20 — forked from torsten/proxy.rb
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009 Torsten Becker <torsten.becker@gmail.com>
require 'socket'
require 'uri'
@huydx
huydx / ascii.rb
Last active January 3, 2016 08:49
ascii.rb
require 'date'
require 'rugged'
data = File.read('./source.txt').split("\n")
dist = data[0].size.times.map {|i| data.map {|n| n[i] } }.flatten
date = Date.today - 366
date += 1 until date.wday.zero?
@huydx
huydx / ruby-error.log
Created November 26, 2013 14:53
ruby-1.9.2 p320 error mac os 10.9
[2013-11-26 23:45:07] __rvm_make
__rvm_make ()
{
\make "$@" || return $?
}
current path: /Users/doxuanhuy/.rvm/src/ruby-1.9.2-p320
command(3): __rvm_make -j 1
/usr/local/opt/gcc46/bin/gcc-4.6 -O3 -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -fno-common -pipe -I. -I.ext/include/x86_64-darwin13.0.0 -I./include -I. -DRUBY_EXPORT -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -o main.o -c main.c
/usr/local/opt/gcc46/bin/gcc-4.6 -O3 -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -fno-common -pipe -I. -I.ext/include/x86_64-darwin13.0.0 -I./include -I. -DRUBY_EXPORT -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -o dln.o -c dln.c
/usr/local/opt/gcc46/bin/gcc-4.6 -O3 -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -fno-common -pipe -I. -I.ext/include/x86_64-darwin13.0.0 -I./include -I. -DRUBY_EXPORT -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -o dmydln.o -c dmydln.c
@huydx
huydx / faye_hook.rb
Last active December 29, 2015 10:48
faye_hook.rb
require 'rubygems'
require 'faye'
class ServerAuth
def incoming(message, callback)
do_something if message =~ /^\/meta\/subscribe/
do_other_something if message =~ /^\/meta\/unsubscribe/
callback.call(message)
end
@huydx
huydx / online_user_count.rb
Last active December 29, 2015 10:29
online_user_count.rb
class ApplicationController < ActionController:Base
before_action :update_online_status
def update_online_status
now = DateTime.now
expire_time = now + 5.minutes
current_time_key = "online_users:#{now.minute}"
$redis.sadd(current_time_key, current_user.id)
$redis.expireat(current_time_key, expire_time)