Skip to content

Instantly share code, notes, and snippets.

View reterVision's full-sized avatar
🍙

Chao Gao reterVision

🍙
View GitHub Profile
@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 / algorithms.md
Last active January 3, 2016 04:39
Home made algorithm implementations.
@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 / 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 / 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 / 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 / lcs.go
Created June 20, 2014 03:25
Longest Common Strings in Go
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
# Build dependencies for OpenResty.
sudo apt-get install build-essential libpcre3-dev libssl-dev libgeoip-dev
# Install standard Nginx first so that you get the relevant service scripts installed too
sudo apt-get install nginx
# If you want to access Postgres via Nginx
sudo apt-get install libpq-dev

This example is based on having a cascading setup, where you have a single master, a single "primary" slave, and cascading slaves which are being replicated from the primary slave. For an example of this setup, check out http://bartek.im/blog/2012/12/04/postgresql-92-streaming-primer.html

On the existing master, if accessible, stop postgres.

$ sudo service postgresql stop

And better to be safe than sorry. We can't have two masters running. (I only use this in an automated script. If you're doing this manually, you'd know if it was shutoff)

$ kill -9 `sudo cat /var/lib/postgresql/9.2/main/postmaster.pid | head -n 1` &> /dev/null
@reterVision
reterVision / insert_pg.go
Created July 5, 2014 08:18
A trivial program that uses goroutine to insert records into Postgres.
/*
Original idea from
http://www.acloudtree.com/how-to-shove-data-into-postgres-using-goroutinesgophers-and-golang/
*/
package main
import (
"log"
"time"
"os"