Skip to content

Instantly share code, notes, and snippets.

View bcho's full-sized avatar
💍
一起来发财吧!Let's make some money!

hbc bcho

💍
一起来发财吧!Let's make some money!
View GitHub Profile
@bcho
bcho / taxi driver: dialogue 1.txt
Created November 1, 2014 02:42
taxi driver: dialogue 1
Travis: I can't sleep nights.
Personnel Officer: There's porno theatres for that.
Travis: I know. I tried that.
Personnel Officer: So whaddaya do now?
Travis: I ride around nights mostly. Subways, buses. Figure you know, I'm gonna do that, I might as well get paid for it.
Personnel Officer: Wanna work uptown nights - South Bronx, Harlem?
Travis: I'll work any time, anywhere.
Personnel Officer: Will ya work Jewish holidays?
Travis: Any time, anywhere.
Personnel Officer: All right. Let me see your chauffeur's license. How's your driving record?
//------------------------------------------------------------------------
// Start compiling program.
// 10/30/14 19:22:22
//------------------------------------------------------------------------
1 PROGRAM MAIN;
2 CONST A = 2;
3 VAR B;
4 BEGIN
5 B := 5;
6 write(B);
@bcho
bcho / concat.sql
Created October 27, 2014 14:47
trick
/* string concat update in postgresql */
/* check before submit changes: */
SELECT 'prefix' || col
FROM tb
WHERE id in (1, 2, 3);
/* concat update */
UPDATE tb
@bcho
bcho / uint.go
Last active August 29, 2015 14:07
trick
package main
import "fmt"
type Year uint
type Month uint
func (year Year) isLeap() bool {
return ((year%4 == 0) && (year%100 != 0)) || (year%400 == 0)
}
# coding: utf-8
# By default, fabric will use `/bin/bash` as shell.
# Which means it won't process our aliases in the `~/.bashrc`
# (or `~/.bash_profile`).
from fabric.api import env
# We can fix this by invoking bash as a login shell: (quoted from `man bash`):
@bcho
bcho / chunks.py
Created October 15, 2014 12:51
trick
# coding: utf-8
def chunks(seq, chunk_size):
'''Split a sequence into chunks.
Source: http://stackoverflow.com/a/312464/1158494
:param seq: sequence to be split.
:param chunk_size: chunk size.
@bcho
bcho / daemonize.c
Created October 13, 2014 15:24
trick
/*
* We said a process is a daemon when:
*
* - its parent process terminates,
* - the daemon process attach to init (1) process.
*
* Usually we will close its STDIN / STDOUT / STDERR and chroot to ``/``.
*/
#include <fcntl.h>
@bcho
bcho / left_recur.c
Last active August 29, 2015 14:07
trick
// Consider a left recursion grammar:
//
// exp = exp + num | num
// num = 0|1|2|3|4|5|6|7|8|9
//
// We can remove left recursion by employing exp':
//
// exp = num exp'
// exp' = + num exp' | eps
//
@bcho
bcho / trap.c
Created October 9, 2014 05:49
trick
// Store current instruction.
tf->esp -= 4;
*((uint *) (tf->esp)) = tf->eip;
// Run alarm handler.
tf->eip = (uint) proc->alarmhandler;
vimshell% ./sf
!!!vimshell: exit 1 "./sf"!!!
vimshell%