Skip to content

Instantly share code, notes, and snippets.

@mkowoods
mkowoods / excel_to_csv.py
Created September 6, 2015 21:08
Simple Example Using xlrd to open an xlsx file run a basic script and write the results to a csv
import xlrd
import csv, codecs, cStringIO
path = "Book1.xlsx"
wb = xlrd.open_workbook(path)
sheet1 = wb.sheet_by_index(0)
@mkowoods
mkowoods / zen_of_python_by_example.py
Created August 24, 2015 04:29
zen of python example
#!/usr/bin/env python
"""
=====================================
PEP 20 (The Zen of Python) by example
=====================================
Usage: %prog
:Author: Hunter Blanks, hblanks@artifex.org / hblanks@monetate.com
@mkowoods
mkowoods / simple_flask.py
Created July 18, 2015 23:23
hello flask
# -*- conding: utf-8 -*-
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_flask():
return 'Hello Flask!'
@mkowoods
mkowoods / venv commands
Last active August 29, 2015 14:24
venv script
virtualenv venv
#source venv/bin/activate
#pip install requests
#pip freeze > requirements.tx
#pip install -r requirements.txt
@mkowoods
mkowoods / .gitignore
Created July 10, 2015 04:21
default gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc
@mkowoods
mkowoods / shortest_path_search_2.py
Last active August 29, 2015 14:24
Generic Shortest Path with Subway Example
-----------------
# User Instructions
#
# Write a function, subway, that takes lines as input (read more about
# the **lines notation in the instructor comments box below) and returns
# a dictionary of the form {station:{neighbor:line, ...}, ... }
#
# For example, when calling subway(boston), one of the entries in the
# resulting dictionary should be 'foresthills': {'backbay': 'orange'}.
# This means that foresthills only has one neighbor ('backbay') and
@mkowoods
mkowoods / lowest_cost_search.py
Created July 4, 2015 17:32
Generic Lowes Cost Search with Examples
# -----------------
# User Instructions
#
# In this problem, you will generalize the bridge problem
# by writing a function bridge_problem3, that makes a call
# to lowest_cost_search.
def bridge_problem3(here):
"""Find the fastest (least elapsed time) path to
the goal in the bridge problem."""
@mkowoods
mkowoods / shortest_path_search.py
Last active August 29, 2015 14:24
Generic Shortest Path Search with Examples
# -----------------
# User Instructions
#
# Write a function, shortest_path_search, that generalizes the search algorithm
# that we have been using. This function should have three inputs, a start state,
# a successors function, and an is_goal function.
#
# You can use the solution to mc_problem as a template for constructing your
# shortest_path_search. You can also see the example is_goal and successors
# functions for a simple test problem below.
@mkowoods
mkowoods / pyodbc_mssql.py
Created June 17, 2015 17:05
Connect pyodbc to Microsoft Sql Server using a secure connection
import pyodbc
driver = '{SQL Server}'
server = 'XXXX'
trusted_conn = 'yes'
conn = pyodbc.connect('driver=%s;server=%s;Trusted_Connection=%s'%(driver,server,trusted_conn))
c = conn.cursor()
@mkowoods
mkowoods / bfs_solution_water_pouring_problem.py
Created June 16, 2015 18:34
Solution To Water Pouring Problem with BFS Search
"""
BFS Solutiontion to the Water Pouring Problem
e.g. Given two glasses 1 with capacity 9 ozs and the other with capacity 4 ozs fill the 9 oz glass to capacity 6 ounces
"""
def fill(glasses, glass_idx):
results = []
for idx, glass in enumerate(glasses):
if idx == glass_idx:
capacity, vol = glass