Skip to content

Instantly share code, notes, and snippets.

View reterVision's full-sized avatar
🍙

Chao Gao reterVision

🍙
View GitHub Profile
#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;

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

  • virtualenv
  • Django
  • nginx
  • uwsgi
@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)):
@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 / 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 / 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 / mount.sh
Created March 24, 2013 09:31
Add new hard disk you Linux.
# Extracted information from below
# http://rbgeek.wordpress.com/2012/05/11/how-to-add-2nd-hard-drive-to-ubuntu/
# http://ubuntuforums.org/showthread.php?t=1659376
# 1. List out all the disk you have in hand now.
sudo fdisk -l
# 2. Create partition on the secondary hard drive.
# Remember to create logical partition.
sudo fdisk /dev/sdb
@reterVision
reterVision / file_options.c
Last active December 15, 2015 08:19
Linux C Programming -- Create Process and File Read & Write
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
int fd, fdw;
int pid;
pid = fork();
@reterVision
reterVision / LRU.py
Last active March 1, 2023 02:32
LRU algorithm implemented in Python.
from datetime import datetime
class LRUCacheItem(object):
"""Data structure of items stored in cache"""
def __init__(self, key, item):
self.key = key
self.item = item
self.timestamp = datetime.now()
@reterVision
reterVision / perm.py
Last active December 12, 2015 04:39
All permulation algorithm written in Python.
"""
Permulation algorithm implemented in Python.
"""
array = range(1, 4)
def perm(array, lower, upper):
if lower >= upper:
print array
else: