Skip to content

Instantly share code, notes, and snippets.

View smoitra87's full-sized avatar

Subhodeep Moitra smoitra87

View GitHub Profile
@smoitra87
smoitra87 / scrape_sp500.py
Created May 16, 2015 12:22
Gets a list of tickers from wikipedia and scrapes csvs from yahoo finance
from lxml import html
import requests
import os, sys
import time
def fetch_table():
page = requests.get('http://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
tree = html.fromstring(page.text)
xpath = '//*[@id="mw-content-text"]/table[1]'
@smoitra87
smoitra87 / python2pdf.sh
Last active August 15, 2019 15:02
Convert python files to pdf and concatenate all pdfs. Requires pygmentize, pdflatex and pdftk
#!/bin/sh
allpdfs=""
for f in "$@" ; do
filename=$(basename "$f")
filename="${filename%.*}"
pygmentize -f tex -O linenos -O title=$( echo $filename | tr '_' '-').py -O full -O style=default -o /tmp/$filename.tex $f
pdflatex -jobname=$filename -output-directory=/tmp /tmp/$filename.tex
allpdfs="$allpdfs /tmp/$filename.pdf"
@smoitra87
smoitra87 / forgenexp.py
Created November 16, 2013 19:49
Using a generator expression to modify a for loop
for x in (x for x in arr if x>0):
print('{} is positive'.format(x))
@smoitra87
smoitra87 / multifract.py
Created November 11, 2013 00:54
Generates Multifractal data
#!/usr/bin/env python
#-*- coding: utf-8 -*-
# Copyright 2013 Subhodeep Moitra, all rights reserved
# subhodeep.moitra@gmail.com
import argparse
import os,sys
def log(n,base) :
return 0 if n==1 else 1+log(n/base,base)
@smoitra87
smoitra87 / toggle_gmail.sh
Created November 7, 2013 01:59
Toggle gmail in /etc/hosts
#!/bin/sh
if [ -n "$(grep gmail /etc/hosts)" ]
then
echo "Gmail found : $(grep gmail /etc/hosts)"
echo "Removing gmail"
sed '/gmail/d' /etc/hosts > /tmp/gmailtoggle
sudo cp /tmp/gmailtoggle /etc/hosts
else
echo "Gmail not found, Adding gmail"
@smoitra87
smoitra87 / .vimrc
Created October 26, 2013 15:06
My vimrc
"" Modified from Mahdi
set nocompatible
syntax enable
set encoding=utf-8
set showcmd
set t_Co=256
filetype off
execute pathogen#infect()
@smoitra87
smoitra87 / Bitshift.py
Last active December 23, 2015 06:49
Bitshift operator in Python
with open('/tmp/bla','w') as fout :
for i in xrange(10) :
print >>fout, i,chr(64+i)
import sys
for i in xrange(10) :
print >>sys.stdout, i,chr(64+i)
@smoitra87
smoitra87 / mechanize_demo.py
Created September 10, 2013 12:54
Follow web links on a page using mechanize
"""
Goes to a HTML forms demo page and tries to submit some data to it
using the mechanize browser
"""
import mechanize
import re
page_link= "http://www.w3schools.com/html/html_forms.asp"
@smoitra87
smoitra87 / min_index.py
Created November 12, 2012 21:53
Index of min - One Liner
import random
arr = range(10)
random.shuffle(arr)
reduce(lambda x,y: (x[1]<y[1])and x or y ,enumerate(x))[0]