Skip to content

Instantly share code, notes, and snippets.

View gregorykremler's full-sized avatar

Gregory Kremler gregorykremler

View GitHub Profile
@gregorykremler
gregorykremler / Preferences.sublime-settings.json
Last active July 4, 2017 19:14
Sublime user settings for Python.
{
"close_windows_when_empty": true,
"color_scheme": "Packages/Theme - Spacegray/base16-ocean.dark.tmTheme",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"find_selected_text": true,
"font_size": 10.0,
"highlight_line": true,
"ignored_packages":
[
@gregorykremler
gregorykremler / csv-wrap.py
Created September 17, 2015 15:02
Script to explore source encoding and parse CSV data.
import codecs
import cStringIO
import csv
import sys
import unicodecsv
from bs4 import UnicodeDammit
########################################################################
@gregorykremler
gregorykremler / geocodio.py
Created May 26, 2015 20:40
geocod.io parse v geocode return objects
# For sample invalid address of:
# "ROYSE CITY TX 75189-, TX 75189-4214"
# parse method return object
# http://api.geocod.io/v1/parse?q=ROYSE%20CITY%20TX%2075189-,%20TX%2075189-4214&api_key=
# {
# address_components: {
# number: "75189-",
# street: "Tx",
@gregorykremler
gregorykremler / xlrd.py
Last active January 24, 2017 23:07
xlrd module sample use
import xlrd
# initialize a workbook
workbook = xlrd.open_workbook('<excel filename>')
# inspect a workbook's sheets
workbook.sheet_names() # returns a list of sheet names
# initialize a worksheet
worksheet = workbook.sheet_by_name('<sheet name>')
@gregorykremler
gregorykremler / args_kwargs.py
Last active August 29, 2015 14:13
Examples of pythons *args + **kwargs magic variables.
# in a function definition
# *args and **kwargs allow you to pass a variable number of args to a function
# *args is for a non-keyworded variable length argument list
def test_var_args(f_arg, *argv):
print "first normal arg:", f_arg
for arg in argv:
print "another arg through *argv:", arg
# test_var_args('Matt', 1, 2, 3, {}, 'bologna')
@gregorykremler
gregorykremler / map.py
Created December 25, 2014 05:30
return of the map
# There are built-in higher order functions
map(add_10, [1, 2, 3]) # => [11, 12, 13]
filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
# We can use list comprehensions for nice maps and filters
[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]
@gregorykremler
gregorykremler / secret_santa.py
Last active August 29, 2015 14:11
Generates secret santa list for Enigma.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
TEAM_MEMBERS = [
'Marc DaCosta',
'Craig Danton',
'Mike Flowers',
'Hicham Oudghiri',
from operator import mul
def get_products_of_all_ints_except_at_index(lst):
"""
Returns array of products of all ints except index, for given array of ints.
e.g., [1, 7, 3, 4] returns [84, 12, 28, 21] by calculating [7*3*4, 1*3*4, 1*7*4, 1*7*3]
"""
product_lst = []
for idx in range(len(lst)):
except_at_index = lst[:idx] + lst[idx+1:]
@gregorykremler
gregorykremler / decorator
Created October 31, 2014 21:49
decorator example
def makebold(fn):
def wrapped():
return '<b>' + fn() + '</b>'
return wrapped
def makeitalic(fn):
def wrapped():
return '<i>' + fn() + '</i>'
return wrapped