Skip to content

Instantly share code, notes, and snippets.

@grapeot
grapeot / .zshrc
Last active August 29, 2015 13:55
my .zshrc
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Example aliases
set -g default-terminal "screen-256color"
set -g status-right '#[fg=black] #(hostname), %H:%M, #(uptime | egrep -o "average.*"|perl -pe "s|average: ||")'
setw -g automatic-rename
# mouse mode
set -g mode-mouse on
setw -g mouse-select-window on
setw -g mouse-select-pane on
setw -g mode-keys vi
@grapeot
grapeot / gist:3209996
Created July 30, 2012 20:40
Gitolite Setup @ EC2
# Install git
cd $HOME
sudo yum -y update
sudo yum -y install git
# Prepare the public key, which will be used later
cp ~/.ssh/authorized_keys /tmp/Default.pub
chmod a+r /tmp/Default.pub
# Use the user git to install gitolite from source.
@grapeot
grapeot / install_gitlab
Created August 1, 2012 22:44
Configure gitlab in ubuntu
Basically just Follow the install instructions in https://github.com/gitlabhq/gitlabhq/blob/stable/doc/installation.md.
If you encounter problems, check this:
1. If the system complains about pid files in the very last step, change 'restart' to 'start'.
If it doesn't work, use 'sudo ./resque.sh' in Step 6.
2. I encountered 502 Bad Gateway error. Solution is in https://groups.google.com/forum/?fromgroups#!topic/gitlabhq/u9AMESyd-N0
Restart the server after the modification.
@grapeot
grapeot / lsh.m
Created August 14, 2012 19:31
Inuitive example for LSH with toy data
% Inuitive example for LSH with toy data
dimension = 30;
sampleNum = 1000;
hashBitCount = 16;
x = rand(sampleNum, dimension); % data points to hash
w = rand(dimension, hashBitCount); % w vector in hash function
w = w ./ repmat(sqrt(diag(w' * w)'), dimension, 1); % normalization
projection = x * w; % Do the projection
t = median(projection); % empirically provides good result
hashCode = sign(x * w - repmat(t, sampleNum, 1)); % replace x with test data in test phase
@grapeot
grapeot / hashTableDemo.m
Created August 16, 2012 16:38
A toy example of implementig a hash table in matlab
function demo
% This is a toy example of implementig a hash table in matlab
hashBits = 20;
function h = hash(s)
% A toy hash function for vectors/strings
% Note this function accepts a matrix as input thus is fast in matlab
h = mod(sum(s, 2), 2^hashBits) + 1; % Note this produces a 16-bit hash code.
% Plus one to prevent outputting 0 as hash code, which will cause
% problems in the following code.
@grapeot
grapeot / semaphore.cs
Created September 5, 2012 16:42
An example using semaphore to manage async downloading requests
var semaphor = new Semaphore(50, 50); // We allow at most 50 threads for crawling
var resultPins = new List<Pin>(); // Results stored here
foreach (var pin in new HashSet<string>(pinIdList))
{
semaphor.WaitOne();
Console.Write(">");
var pinClient = new WebClient();
pinClient.DownloadStringCompleted += (sender, ex) =>
{
var html = ex.Result.Replace("\n", "");
@grapeot
grapeot / reHtml.py
Created September 17, 2012 13:48
Use python to extract info from html
# Not sure why this example doesn't work, but the framework is like this.
# Welcome to point out the bug. Thanks in advance!
import re
content = '<html><p class="name">John</p><p class="profile">http://facebook.com/john</p></html>'
# More info about re in http://docs.python.org/library/re.html
name_result = re.match('class="name">(\w+)<', content).group(1)
profile_result = re.match('class="profile">(.+)<', content).group(1)
@grapeot
grapeot / vimrc
Last active December 11, 2015 08:58
My .vimrc
" regular settings
syntax on
set si ai nu et
set shiftwidth=4
set tabstop=4
set bs=2
colorscheme wombat
set autochdir autoread autowrite
set incsearch ignorecase smartcase
#include <amp.h>
#include <iostream>
#include <ctime>
#include <cstdlib>
#define TS 16
using namespace std;
using namespace concurrency;
int main()