Skip to content

Instantly share code, notes, and snippets.

View imran31415's full-sized avatar

Imran Hassanali imran31415

View GitHub Profile
import sys
import itertools
#itertools used for permutations to create sets
'''
Author: Imran Hassanali
Email: develop.imran@gmail.com
'''
import itertools
from collections import Counter
# gets the most common element from a list
def Most_Common(lst):
data = Counter(lst)
return data.most_common(1)[0]
import itertools
from collections import Counter
# gets the most common element from a list
def Most_Common(lst):
data = Counter(lst)
return data.most_common(1)[0]
import random
import itertools
from collections import Counter
''' BEGIN UTILITY SCRIPTS'''
# gets the most common element from a list
def Most_Common(lst):
data = Counter(lst)
return data.most_common(1)[0]
#gets card value from a hand. converts A to 14, is_seq function will convert the 14 to a 1 when necessary to evaluate A 2 3 4 5 straights
def convert_tonums(h, nums = {'T':10, 'J':11, 'Q':12, 'K':13, "A": 14}):
@imran31415
imran31415 / example_1.py
Last active August 29, 2015 14:04
orchard
'''
trivial orchard example
exploring multidimensional dynamic data types
'''
def create_orchard():
return {'orchard':[]}
def add_tree_row(orchard, n=1):
for x in xrange(n):
orchard['orchard'].append({'tree_row':[]})
@imran31415
imran31415 / coach_sync.py
Last active August 29, 2015 14:06
This is an example script of a program that uses CSV files for data storage, and every transaction with the program will sync the CSV. upon starting the script, it will look for a CSV file to load data from. 2 way sync: CSV-script Script-CSV
import time
import pprint
import os.path
def list_tocsv(list, filename):
import csv
with open(filename, 'wb') as f:
writer = csv.writer(f)
writer.writerows(list)
@imran31415
imran31415 / torproxy.py
Created April 28, 2015 22:28
Torproxy.py
import os
from selenium import webdriver
import subprocess
ff_prof = webdriver.FirefoxProfile()
#set some privacy settings
ff_prof.set_preference( "places.history.enabled", False )
ff_prof.set_preference( "privacy.clearOnShutdown.offlineApps", True )
ff_prof.set_preference( "privacy.clearOnShutdown.passwords", True )
ff_prof.set_preference( "privacy.clearOnShutdown.siteSettings", True )
@imran31415
imran31415 / tutorialbuilder.py
Created November 28, 2015 03:32
A python script to build web page tutorial templates based on JSON data
import pprint
MANUAL_TEMPLATE = {
"title": "",
"header": "",
"warning": "Please make sure you have the following setup before starting",
"requirements":[],
"setup":
import sys
import mailbox
import email
import quopri
import json
from BeautifulSoup import BeautifulSoup
def cleanContent(msg):
import mailbox
import email.utils
from mboxparse import convert_to_json
filename = "metadatatest2525.mbox"
#the following returns a list containing message objects. Each message objects is composed of the components listed on line 20.
mbox = mailbox.mbox(filename)