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 / amxremit.py
Created December 24, 2013 16:46
Selenium Script to get currencies from AmxRemit
from selenium import webdriver
from selenium.webdriver.support.select import Select
browser = webdriver.Firefox()
browser.get('http://www.amxremit.com')
# get the currency dropdown
select = Select(browser.find_element_by_id("showrate"))
select.select_by_index(3) #for INR currency
@prakhar1989
prakhar1989 / logger2.py
Created December 8, 2013 14:54
Logger file with mailer for python 2.7
#!/usr/bin/python2.7
import requests
import datetime
import smtplib
import logging
import re
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
sender = "uptimebot@test.com"
@prakhar1989
prakhar1989 / logger.py
Created December 8, 2013 14:43
Sending emails with files as attachments in python 2.4
#!/usr/bin/python
import MySQLdb as mdb
import sys
import csv
import smtplib
from datetime import datetime
from email.MIMEBase import MIMEBase
from email.MIMEMultipart import MIMEMultipart
from email import Encoders
@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:
@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 / 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 / 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 / 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 / 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 / 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