Skip to content

Instantly share code, notes, and snippets.

@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 / cmuBlackboardAutoLogin.py
Created July 31, 2012 19:09
Auto login script for CMU blackboard
import requests
import re
# Initial request for blackboard
r = requests.get('http://blackboard.andrew.cmu.edu/')
# Authenticaton
payload = { 'j_username' : '<your username>', 'j_password' : '<your password>', 'j_continue' : '1', 'submit' : 'Login' }
r2 = requests.post(r.url, data=payload, cookies=r.cookies)
# Manually proceed with the form
url = 'https://blackboard.andrew.cmu.edu/Shibboleth.sso/SAML2/POST'
@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()
@grapeot
grapeot / xkcd.sh
Created May 3, 2013 04:12
Mount it on crontab, and it will send you daily xkcd pick.
num=$(curl -s xkcd.com | grep -oh -m 1 'v" href="/[0-9]*' | sed 's/v" href="\/'//)
n=$[ $RANDOM % $num ]
curl -s xkcd.com/$n/ | grep '<img.*comics' | mail -a 'Content-Type: text/html' -s 'xkcd daily pick' <email>