Skip to content

Instantly share code, notes, and snippets.

View reterVision's full-sized avatar
🍔

Chao Gao reterVision

🍔
View GitHub Profile
@reterVision
reterVision / bsearch.c
Last active December 15, 2015 09:29
Binary Search with C
#include <stdio.h>
#include <stdlib.h>
int binary_search(int a[], int min, int max, int value)
{
if (max < min) {
return -1;
}
int mid = (max + min) / 2;
if (value == a[mid]) {
@reterVision
reterVision / bsearch.py
Created March 26, 2013 00:51
Binary Search in Python
#!/usr/bin/python
"""
Binary Search
"""
def bsearch(array, min, max, target):
if max < min:
return -1
@reterVision
reterVision / maxmin.c
Created March 27, 2013 00:37
__typeof__ example in GCC
#include <stdio.h>
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define min(a, b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _b : _a; })
#define max(a, b) \
@reterVision
reterVision / anagram.py
Created May 5, 2013 07:56
Anagram solution in Python.
def get_anagram(big_phrase, phrase):
"""
Get a sub-string from a big phrase which is the anagram
with the other string.
"""
print 'Problem: ', big_phrase, phrase
big_phrase = big_phrase.lower()
phrase = phrase.lower().replace(' ', '')
for i in range(len(big_phrase)):

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

  • virtualenv
  • Django
  • nginx
  • uwsgi
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
void printdir(char *dir, int depth)
{
DIR *dp;
@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)
@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 / 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 / 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>