Skip to content

Instantly share code, notes, and snippets.

View reterVision's full-sized avatar
🍔

Chao Gao reterVision

🍔
View GitHub Profile
@reterVision
reterVision / brew_install_postgres.sh
Last active December 10, 2015 02:28
Show you the steps of upgrading postgres to 9.2 on Mac OS X using homebrew
# Update brew & install the latest postgres first
brew update
brew install postgres
# Shut down the old running postgres
# Assume you previously installed postgres using homebrew
pg_ctl -D /usr/local/Cellar/posgres/9.1.1 stop
# If postgres won't stop, you have to do the following step to unload it from LaunchAgents
launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
@reterVision
reterVision / create_and_grant.sql
Last active December 10, 2015 04:08
How to create a role and grant a view to him with the read only privilege in postgres.
CREATE ROLE <newuser> WITH LOGIN ENCRYPTED PASSWORD <password>;
CREATE VIEW <viewname> AS SELECT * FROM <yourtable> LIMIT 20;
GRANT CONNECT ON DATABASE "<databasename>" TO <newuser>;
GRANT SELECT ON schemaname.viewname TO <newuser>;
REVOKE ALL PRIVILEGES ON <schemaname> FROM <newuser>;
# How to merge other branch to master.
# First fetch the changes from your branch, could be made by others
git fetch
# Then commit your changes.
git commit -m "some"
git push origin my-branch
# Switch to master branch and pull the latest code to your local.
# Sometimes we could mistakenly commit something without pull first, so
# here is how we revert this process and keep our master branch clean.
# Reset back to the commit before you last commit.
# git reset --mixed will keep your changes and revert other files back
# to that commit.
git pull
git reset --mixed HEAD-before-your-last-commit
# Commit your changes again.
@reterVision
reterVision / check_python.sh
Created January 22, 2013 03:41
Do pyflakes & pep8 to modified files dicovered by git.
#!/bin/sh
git status | grep 'modified\|added' | awk '{system("pyflakes "$3)}'
git status | grep 'modified\|added' | awk '{system("pep8 "$3)}'
@reterVision
reterVision / lnsym.py
Created February 4, 2013 09:34
A Python Script doing auto symbolic link for you.
#!/usr/bin/env python
import subprocess
import argparse
parser = argparse.ArgumentParser(description='Do the symbolic for you.')
parser.add_argument('--source', dest='folder',
help='Your code directory')
parser.add_argument('--virtual', dest='vfolder',
@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:
@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 / 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 / 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