Skip to content

Instantly share code, notes, and snippets.

View anxiousmodernman's full-sized avatar
🎺
ready for a ska revival

Coleman McFarland anxiousmodernman

🎺
ready for a ska revival
View GitHub Profile
@anxiousmodernman
anxiousmodernman / money-left.py
Last active August 29, 2015 14:13
Budget script
#/usr/bin/python3
from datetime import datetime
import sys
"""
Pass the amount you've spent from the command line like this:
$ python3 money-left.py 2000
@anxiousmodernman
anxiousmodernman / bootyHadMeLike.js
Last active August 29, 2015 14:12
Booty had me like example
var _ = require('underscore');
function bootyService(booty) {
return function() {
if (booty.hadMeLike()) {
throw new BootyError('Damn');
}
@anxiousmodernman
anxiousmodernman / better.go
Last active August 29, 2015 14:09
Go lookin' all JavaScript
func myMethod (myThing myType) (retVal string, val int) {
val = 0
retVal = "Farhan"
}
func main() {
@anxiousmodernman
anxiousmodernman / config.py
Created September 5, 2014 19:58
If I have multiple project roots I can update them all by simply changing the SOURCE variable at the top of my config.py
"""
Set this to the current project you're working on.
"""
SOURCE = 'MLSListings_new'
if SOURCE == 'GEPAR':
PROJECT_ROOT = 'C:\\Users\\cmcfarland\\Dropbox\\Homesnap\\Projects\\GEPAR\\'
sqlfile = PROJECT_ROOT + 'insert_template.sql'
def row_processor(row):
if row['lookupColumn'] == 1:
# add all 3 columns
value = row['colA'] + row['colB'] + row['colC']
return value
elif row['lookupColumn'] == 2:
# add just 2 specific columns referenced by name
value = row['colA'] + row['colB']
return value
@anxiousmodernman
anxiousmodernman / which_field.md
Last active August 29, 2015 14:02
IndexError in the table_instance class

Here is some pdb debugger output from the surrounding code that leads to the IndexError. I put a debug statement in the grabMetadata() method of MLS_Data, and then stepped into the constructor of the table_instance class.

>>> ================================ RESTART ================================
>>> 
What is the prefix for this MLS?XXX
couldnt find saved resource; looking elsewhere.
connecting
def test_parse_activestatus(self):
self.results = fetch_main_briefs()
f = lambda x: x['brief_name'] == 'AAAA'
aaaa = filter(f, self.results).pop()
returned_status = parse_activestatus(aaaa['activestatus'])
self.assertTrue(returned_status, msg="Should parse activestatus code to True.")
@anxiousmodernman
anxiousmodernman / brief.py
Created May 5, 2014 16:15
make Query classes?
def fetch_main_briefs():
"""Fetch list of dict result set from alchemy database"""
q = session.query(BriefTable.briefid,
BriefTable.brief_name,
BriefTable.activestatus)
q = q.filter(BriefTable.parentid == None) # todo abstract this out into a clauses list to prevent duplication
q = q.filter(or_(BriefTable.briefName_alias == '', BriefTable.briefName_alias == None))
result_set = [result.__dict__ for result in q.all()]
return result_set
@anxiousmodernman
anxiousmodernman / ga.py
Created May 3, 2014 18:41
example beginnings of a Query class
class Query:
def __init__(self, params={}):
# make sure params is a dict
if isinstance(params, unicode):
self.params = dict(params)
self.params = params
# QUESTION assign defaults elsewhere?
self.ids = params['ids'] if 'ids' in params else None
self.dimensions = params['dimensions'] if 'dimensions' in params else None
@anxiousmodernman
anxiousmodernman / read_csv_example.py
Created April 21, 2014 23:54
How to import a CSV file in pandas
# cd to a directory with a csv file in it. Any old csv file will do.
# run ipython and type these things at the interactive prompt, line by line:
>>> import pandas as pd
>>> data = pd.read_csv('some_csv.csv') # other arguments to read_csv are available to change the separator char, for example
>>> data
>>> data.keys # access the keys property of the DataFrame object