Skip to content

Instantly share code, notes, and snippets.

View prakhar1989's full-sized avatar
I may be slow to respond.

Prakhar Srivastav prakhar1989

I may be slow to respond.
View GitHub Profile
@prakhar1989
prakhar1989 / sinatra template generator
Created April 14, 2011 18:28
Bash script to generate to simple file structure for sinatra
#!/usr/bin/bash
#tr -d '\15' < f1.bash > f2.bash - (windows/cygwin complications - porting to UNIX file type to add newline chars)
[[ $# -ne 1 ]] && {
echo "Error: requires a folder name";
exit 1;
}
mkdir -p $1/public/javascripts $1/public/stylesheets $1/views
cd $1
@prakhar1989
prakhar1989 / gist:1885267
Created February 22, 2012 14:01
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+X delete line
Ctrl+↩ insert line after
Ctrl+⇧+↩ insert line before
Ctrl+⇧+↑ move line (or selection) up
@prakhar1989
prakhar1989 / Remove From Git By Extension
Created March 16, 2012 23:11 — forked from benzittlau/Remove From Git By Extension
Remove all *.swp files from a git repository
git ls-files | grep '\.swp$' | xargs git rm
@prakhar1989
prakhar1989 / reco.py
Created August 14, 2012 14:32
Python interface to the Grouplens database
import sqlite3
class User():
def __init__(self, id, age, occupation, male):
self.id = id
self.male = male
self.age = age
self.occupation = occupation
self.movie_ratings = {}
@prakhar1989
prakhar1989 / reco.py
Created August 14, 2012 18:29
reco engine
import sqlite3
class User():
def __init__(self, id, age, occupation, male):
self.id = id
self.male = male
self.age = age
self.occupation = occupation
self.movie_ratings = {}
self.set_movie_ratings()
@prakhar1989
prakhar1989 / asd.m
Created September 17, 2012 10:48
regularization
function [J, grad] = costFunctionReg(theta, X, y, lambda)
m = length(y); % number of training examples
J = 0;
grad = zeros(size(theta));
[J, grad] = costFunction(theta, X,y);
reg = ( (sum(theta.^2) - theta(1,1)^2) * (lambda/(2*m)) )
J = J + reg;
for iter = 1:size(grad),
if (iter) > 1,
@prakhar1989
prakhar1989 / gist:6247999
Last active December 21, 2015 04:18
Deploying Django apps on Nginx with Gunicorn and Supervisor
There are 4 parts to successfully running django apps on nginx and gunicorn.
1. Set up gunicorn
2. Set up supervisor
3. Set up nginx.
4. Making admin staticfiles work
Step 1
====
Assuming you have gunicorn installed, just run your app using the command - gunicorn_django <ip_address:port>
@prakhar1989
prakhar1989 / birthday_problem.py
Last active December 25, 2015 02:19
The birthday problem
# birthday problem - http://en.wikipedia.org/wiki/Birthday_problem
def get_prob(n):
p, i = 1.0, 0
while (i < n):
p = p * (365 - i) / 365
i += 1
return (1 - p)
def func_get_prob(n):
@prakhar1989
prakhar1989 / letsrevolutionizetesting.py
Last active December 30, 2015 05:29
Python code for letsrevolutionizetesting challenge.
import requests
def check(r):
base_url = "http://www.letsrevolutionizetesting.com/challenge.json?id="
print "Hitting: %s" % r.url
if 'follow' in r.json():
url_to_follow = r.json().get('follow')
new_url = base_url + url_to_follow.split("=")[-1]
check(requests.get(new_url))
else: