Skip to content

Instantly share code, notes, and snippets.

View sampottinger's full-sized avatar

A Samuel Pottinger sampottinger

View GitHub Profile
@sampottinger
sampottinger / insert_sorted_array.c
Created March 1, 2013 04:57
Shows how to insert into an array in C
/**
* Inserts a value into an array, shifting elements over as needed.
*
* @param target: The array to insert into.
* @param index: The index to insert the new element into.
* @param newVal: The value to insert.
* @param targetSize: The size of the array before inserting the new element.
* Not capacity, the number of existing elements.
* @warn Does not check that the array is large enough to hold the new element.
# Mitchell Wolfe
# [email protected]
###########################################################
# Find longest subsequence
def subsequence(numbers):
# create a list with the first number of inputed sequence
# Go through entire list
subseq_found = []
@sampottinger
sampottinger / gist:5954366
Created July 9, 2013 03:05
Browse button for entry box: Tkinter
def __browse_for_entry(self, entry_box, dialog_type):
"""Browse for a file and put that filename in an entry box.
@param entry_box: The entry box to put the filename in.
@type entry_box: tkinter.Entry
@param dialog_type: The type of dialog to display. Should be 'open' or
'save as'
@type dialog_type: str
"""
dialog_type = dialog_type.lower()
@sampottinger
sampottinger / setup.bash
Created July 30, 2013 21:16
Candidate setup script for denver_streets, creating the denver_streets local development database with the postgis extensions.
# Convenience script to create a local development database for denver_streets.
#
# Convenience script to create the local development database needed for
# denver streets, adding the postgis extensions as necessary. Note that this
# does not create the test database.
#
# @author A. Samuel Pottinger (samnsparky, Gleap LLC)
# @param $1 The name of the user to create for manipulating the dev database.
# this is typically the user specified in config.yaml. Optional but user
# will only be created if a password is specified.
@sampottinger
sampottinger / temp_file_retriever.js
Last active December 20, 2015 23:19
Loads a local file into the current PhoneGap application's temporary directory.
// Thanks http://stackoverflow.com/questions/16065494
// WARNING: Untested. Please provide feedback.
/**
* Request a local file into the PhoneGap application's temporary directory.
*
* Get a local file into the the current PhoneGap application's temporary
* directory given a larger filesystem file URI.
*
* @param {String} uri The URI to load the file from.
@sampottinger
sampottinger / mongo_agg_example.py
Created August 21, 2013 07:27
Pycotracer mongo aggregation example
import pycotracer
import pymongo
client = pymongo.MongoClient()
db = client['tracer-records-db']
all_data = pycotracer.get_report(2013)
contribution_data = all_data['ContributionData'][:100]
expenditure_data = all_data['ExpenditureData'][:100]
loan_data = all_data['LoanData'][:100]
@sampottinger
sampottinger / account_manager_manual_test.js
Created August 21, 2013 15:52
Manual test for account_manager.
var q = require('q');
var account_manager = require('./account_manager');
var testQuery = {
targetCollection: 'contributions',
params: {
minAmount: 1,
maxAmount: 5000
},
offset: 100,
@sampottinger
sampottinger / new_aggregator.py
Created August 21, 2013 22:25
New aggregator code
import pycotracer
import pymongo
client = pymongo.MongoClient()
db = client['tracer-records-db']
all_data = pycotracer.get_report(2013)
pycotracer.mongo_aggregator.insert_contribution_entries(db,
all_data['ContributionData'])
@sampottinger
sampottinger / pycotracer_sync_insert.py
Last active December 22, 2015 21:09
Insert data into a local mongodb database using insert as opposed to update.
import pycotracer
import pymongo
client = pymongo.MongoClient()
db = client['tracer-records-db']
for year in range(2000,2014):
print "fetching tracer records for year",year
@sampottinger
sampottinger / pycotracer_sync_update.py
Last active December 22, 2015 21:09
Insert TRACER data into a local db using update to avoid duplicate data (checks for equality using recordID field).
import pycotracer
import pymongo
client = pymongo.MongoClient()
db = client['tracer-records-db-2']
for year in range(2013,2014):
print "fetching tracer records for year",year