Skip to content

Instantly share code, notes, and snippets.

View reterVision's full-sized avatar
🍔

Chao Gao reterVision

🍔
View GitHub Profile
@reterVision
reterVision / postgres.go
Created May 22, 2014 11:00
Load Django User table information from PostgreSQL in Go
//
// go get github.com/lib/pq
//
package main
import (
_ "github.com/lib/pq"
"database/sql"
"fmt"
"log"
@reterVision
reterVision / test_rest.go
Last active August 29, 2015 14:01
Test Rest API + Redis usage in Go
package main
import (
"encoding/json"
"fmt"
"strings"
"github.com/garyburd/redigo/redis"
"github.com/ant0ine/go-json-rest/rest"
"log"
"net/http"
@reterVision
reterVision / trie.py
Created January 22, 2014 00:49
A trie in Python.
"""
Implement Trie in Python.
References:
http://www.geeksforgeeks.org/trie-delete/
"""
def make_trie(*args):
"""
@reterVision
reterVision / trie.cc
Created January 18, 2014 08:39
A simple Trie implementation in CPP.
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
struct Node {
char ch;
map<char, Node*> children;
@reterVision
reterVision / algorithms.md
Last active January 3, 2016 04:39
Home made algorithm implementations.
@reterVision
reterVision / semaphor_sample.c
Created January 7, 2014 15:23
Semaphore sample
#include <stdio.h> /* printf() */
#include <stdlib.h> /* exit(), malloc(), free() */
#include <sys/types.h> /* key_t, sem_t, pid_t */
#include <sys/shm.h> /* shmat(), IPC_RMID */
#include <errno.h> /* errno, ECHILD */
#include <semaphore.h> /* sem_open(), sem_destroy(), sem_wait().. */
#include <fcntl.h> /* O_CREAT, O_EXEC */
int main (int argc, char **argv){
@reterVision
reterVision / epoll_sample.c
Last active March 29, 2024 02:07
A sample program of how epoll works.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <errno.h>
@reterVision
reterVision / install.sh
Created December 14, 2013 14:50
Install Python environment on Dragonfly BSD
pkg install python
pkg install git
pkg install wget
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
easy_install pip
pip install ipython
@reterVision
reterVision / tmux.conf
Created November 25, 2013 04:37
A tmux configuration.
# use C-a, since it's on the home row and easier to hit than C-b
set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix
set -g base-index 1
# vi is good
setw -g mode-keys vi
# mouse behavior
@reterVision
reterVision / client.py
Last active December 25, 2015 20:49
An extremely simple example showing you how to write a Redis Client
# Slideshare link: http://www.slideshare.net/ChaoGao1/write-a-redis-client
import socket
tcp_host = '127.0.0.1'
tcp_port = 6379
tcp_timeout = 10000
buffer_size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)