Skip to content

Instantly share code, notes, and snippets.

@physacco
physacco / about-erlang-references.txt
Created June 18, 2013 02:44
Erlang references are unique indentifiers. They are commonly used to identify timers, rpc calls, etc.
Erlang references are unique indentifiers. They are commonly used to
identify timers, rpc calls, etc.
make_ref() -> ref()
Returns an almost unique reference.
The returned reference will re-occur after approximately 2^82 calls;
@physacco
physacco / pyc2xml.py
Created June 18, 2013 02:37
Dump a .pyc file to XML, with decompilation.
import pdb
import cgi
import dis
import time
import struct
import marshal
def dump_code_object(code, ident=0):
print '%s<code_object>' % (' '*ident,)
ident += 2
@physacco
physacco / tcp_keepalive.c
Created June 16, 2013 17:10
Play with TCP socket options related to keep-alive.
/* tcp_keepalive.c
*
* References:
* http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html
* http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@physacco
physacco / git-change-origin.md
Created May 16, 2013 06:56
Move the `origin' of a git repository to another host.

把一个git仓库的origin搬到另一台服务器上

  1. 在旧服务器上删除这个仓库

    rm -r /home/$USER/repo/$REPO

  2. 在新服务器上创建一个同名的仓库

    cd /home/$USER/repo git init --bare $REPO

@physacco
physacco / install_ruby-1.9.sh
Created May 9, 2013 09:09
Bash scripts for installing MRI ruby 1.9.3 & 2.0.0 from source.
#!/bin/bash
set -e
PREFIX="$HOME/local/ruby/1.9.3"
RUBY_DIST_URL="ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p392.tar.gz"
RUBY_DIST_PKG=`basename $RUBY_DIST_URL`
RUBY_DIST_DIR=`basename $RUBY_DIST_PKG .tar.gz`
@physacco
physacco / script_dir.sh
Created May 8, 2013 09:02
A utility function for getting the directory of the shell script itself.
#!/bin/bash
script_dir()
{
local SCRIPT_PATH=${BASH_SOURCE[0]}
while [ -L "${SCRIPT_PATH}" ]; do
SCRIPT_PATH=`readlink "$SCRIPT_PATH"`
done
local SCRIPT_DIR=`dirname "${SCRIPT_PATH}"`
@physacco
physacco / parse_config_file.py
Created May 6, 2013 06:44
Functions to parse config.py.
def parse_config_stream(str_or_file):
_myglobals, mylocals = {}, {}
exec str_or_file in _myglobals, mylocals
return mylocals
def parse_config_file(filename):
_myglobals, mylocals = {}, {}
with open(filename) as f:
exec f in _myglobals, mylocals
$ gem sources
*** CURRENT SOURCES ***
http://rubygems.org/
http://gems.github.com/
$ gem sources --remove http://rubygems.org/
http://rubygems.org/ removed from sources
$ gem sources --add http://ruby.taobao.org/
@physacco
physacco / ejabberdctl.txt
Last active December 16, 2015 18:49
ejabberd control commands.
# ejabberdctl
Usage: ejabberdctl [--node nodename] [--auth user host password] command [options]
Available commands in this ejabberd node:
backup file
connected_users
connected_users_number
delete_expired_messages
delete_old_messages days
dump file
@physacco
physacco / post-receive
Created April 20, 2013 17:10
Git post-receive hook for auto-updating a static website generated by nanoc. Nanoc project path is /home/www/mysite; the docroot is /home/www/mysite/output.
#!/bin/sh
# Unset GIT_DIR or you will get a `fatal: Not a git repository: '.'` error.
# Refer to: http://stackoverflow.com/questions/10507942/git-checkout-in-post-receive-hook-not-a-git-repository
unset GIT_DIR
cd /home/www/mysite || exit
git pull
nanoc compile