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 / controllers.py
Created January 2, 2014 03:46
make a interface/facade here?
@app.route('/search', methods=['POST'])
def handle_search_call():
# todo implement facade for request
q = db_session.query(SubscriberTable.first_name,
SubscriberTable.last_name,
SubscriberTable.last_open,
SubscriberTable.email,
SubscriberTable.company).\
join(SubscriberBriefProfileTable)
for k, v in request.json:
import os
from flask import Flask, request, Response
from flask import render_template, url_for, redirect, send_from_directory
from flask import send_file, make_response, abort, jsonify
from sqlalchemy.orm import sessionmaker
from shark import app
from settings import MSSQL_ENV_CONFIG
from sqlalchemy.orm import sessionmaker
from shark import app
from settings import MSSQL_ENV_CONFIG
from datasource.engines import get_mssql_engine
from schemas.alchemy import BriefTable, LinkSubscriberBriefTable, SubscriberTable, SubscriberBriefProfileTable
from shark.interfaces import ContainsFieldValueSearch
engine = get_mssql_engine(MSSQL_ENV_CONFIG)
@anxiousmodernman
anxiousmodernman / GithubServiceITSpec.scala
Created February 18, 2014 13:40
made use of the FakeApplication() in the Specicification class again
class GithubServiceITSpec extends Specification {
val app = FakeApplication()
val config = Play.configuration(app)
implicit val access_token = AccessToken(config.getString("github.oauth.token") getOrElse {
throw new IllegalStateException("No github.oauth.token")
})
"Github integration" should {
@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
@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 / 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
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 / 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 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