Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# Install Postgres 9.2 on a clean Ubuntu 12.04
"""
LC_ALL issue
comment out the AcceptEnv LANG LC_* line in the remote /etc/ssh/sshd_config file.
sudo apt-get install language-pack-en-base
sudo dpkg-reconfigure locales
comment out the SendEnv LANG LC_* line in the local /etc/ssh/ssh_config file.
openssl s_client -connect github.com:443 -showcerts 2>&1 < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sed -ne '1,/-END CERTIFICATE-/p' > /tmp/github.com.pem
openssl x509 -in /tmp/github.com.pem -sha1 -noout -fingerprint
@rainly
rainly / .tmux.conf
Created October 26, 2012 03:23 — forked from terrywang/.tmux.conf
Terry's tmux conf
# Terry's ~/.tmux conf file
# Based on tmux book written by Brian P. Hogan
# c-a o to switch to another panel
# c-d to close shell
# c-a ! to close panel
# c-a w to list windows
# c-a " split pane horizontally
# c-a % split pane vertically
# Setting the prefix from C-b to C-a
@rainly
rainly / gist:3883133
Created October 13, 2012 03:36
Youdao for Shell
#########################################
RED_ORG="\033[0;31m"
GREEN_ORG="\033[0;32m"
NO_COLOR_ORG="\033[0m"
# youdao helpers
function t {
if [ $1 == "-a" ]; then
all=1
query=$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$2" "" | sed -e "s/\/\?//g")
@rainly
rainly / gist:3856759
Created October 9, 2012 05:17 — forked from dnagir/gist:1573414
Run Postgres Specs in Ramdisk
  • This creates a 560mb ramdisk. Adjust the size accordingly. I think the number at the end of the command is the number of disk blocks. They are 2kb in size for me.
  • Restarting postgres is not necessary; you can create the ramdisk and tablespace while postgres is running.
  • You will lose all data in the ramdisk tablespace when you shut your machine down

  $ diskutil erasevolume HFS+ "postgres_ramdisk" `hdiutil attach -nomount ram://1165430`
  Started erase on disk1
  Unmounting disk
  Erasing
 Initialized /dev/rdisk1 as a 569 MB HFS Plus volume
@rainly
rainly / gist:3637224
Created September 5, 2012 14:11 — forked from liweinan/gist:3629763
out

#对non-lock queue的简单分析#

今天看到 @梁斌penny 在打擂:http://coderpk.com

内容如下:

游戏规则: 比赛由pennyliang,就是本人梁斌同志坐庄,我提交baseline代码(可执行程序),和部分代码,方便统一游戏规则。 10亿数据(每个数据看作一个同志),1个队列,10个线程push,10个线程pop,走完一遍,考察总耗时,耗时最短的获胜。我的代码在我自己机器10亿数据排队进出,耗时1分28秒,内存峰值256MB(CPU16核,真8核那种,Intel(R) Xeon(R) CPU E5540 @ 2.53GHz)

@rainly
rainly / setup.sql
Created August 30, 2012 09:17 — forked from imperialwicket/setup.sql
PostgreSQL monthly table partitions
--
-- Setup - Add plpgsql, create a parent table, create an initial child table,
-- create the trigger and the initial trigger function.
--
-- We'll need plpgsql, so create it in your db if it's not already available.
CREATE LANGUAGE plpgsql;
-- Create a table to act as parent with the appropriate columns for your data.
CREATE TABLE my_schema.my_data (name varchar(24), create_date timestamp);
@rainly
rainly / youku-video-parser.py
Created August 12, 2012 12:15
A simple python script that takes a youku video url or video id as argument and output the video playlist.
#!/usr/bin/env python2
import sys
import urllib
from HTMLParser import HTMLParser
class FlvcdParser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == "a":
@rainly
rainly / vagrant_postinstall.sh
Created August 3, 2012 01:39 — forked from dholbrook/vagrant_postinstall.sh
vagrant centos 5.8 post install
####################
# centos 5.8
# post installation
# adapted from
# https://github.com/jedi4ever/veewee/tree/master/templates/CentOS-5.7-i386-netboot
####################
yum -y install sudo
/usr/sbin/groupadd vagrant
@rainly
rainly / gist:3065231
Created July 7, 2012 07:31 — forked from newhouseb/gist:1620133
MySQL vs PostgreSQL Schema changes benchmarks
The basic idea here is to substantiate the claims made by this square post:
http://corner.squareup.com/2011/06/postgresql-data-is-important.html
In PostgreSQL, and MySQL (MyISAM and InnoDB) I create millions of rows and then add
and remove columns and add and remove indexes. For columns without defaults this is
basically free in PostgreSQL and O(n) in MySQL. For adding indexes its at best O(n)
everywhere, but with PostgreSQL it claims not to do any locking that would otherwise
prevent table interaction.
Also, PostgreSQL has _awsome_ documentation (it has real examples!). I always get