Skip to content

Instantly share code, notes, and snippets.

View pdarche's full-sized avatar

Peter Darche pdarche

  • Abnormal Security
  • San Francisco, CA
View GitHub Profile
@pdarche
pdarche / open paths oauth2 sinatra implementation
Created July 28, 2012 20:27
This is a Sinatra route that handles authentication and access to the open paths api using the oauth2 gem
get '/op' do
consumer_key = 'key'
consumer_secret = 'secret'
url = 'https://openpaths.cc/'
now = Time.now
#instantiate client
client = OAuth2::Client.new(consumer_key, consumer_secret, :site => url)
#create token
@pdarche
pdarche / Fixnum to string issues
Created July 28, 2012 20:37
This is an example Sinatra code block that should get and print out the last day's worth of data from the Withings api. Unfortunately, the Time class returns Fixnums, which I'm having trouble incorporating into request string (I'm getting type errors).
require 'rest_client'
get '/withings' do
userid = 'id'
public_key = 'key'
now = Time.now.to_i
yestr = now - (24 * 60 * 60)
url = 'http://wbsapi.withings.net/measure?action=getmeas&userid=' + userid + '&publickey=' + public_key +'&startdate=' + yestr.to_s + '&enddate=' + now.to_s ' + &limit=1';
@pdarche
pdarche / Fitbit deployment issues
Last active December 10, 2015 01:38
When I run the code block locally I get the proper response. When I run on my remote server, I get a timestamp error.
require 'fitgem'
client = Fitgem::Client.new( {
:consumer_key => 'consumer_key',
:consumer_secret => 'consumer_secret',
:token =>'access_token',
:secret => 'access_secret'
} )
client.activities_on_date('today')
@pdarche
pdarche / gist:4463867
Created January 5, 2013 21:50
First pass as a ( currently non-functional ) Fitbit authentication mixin for Tronado and a test handler class
################### Fitbit Mixin ###################
import urllib
import tornado.auth
import tornado.httputil
import logging
class FitbitMixin(tornado.auth.OAuthMixin):
"""Fitbit OAuth authentication.
@pdarche
pdarche / gist:5034801
Created February 26, 2013 00:51
Open Paths in Ruby with the Crazylegs gem
require 'crazylegs'
consumer_key = "your consumer key"
consumer_secret = "your consumer secret"
base_url = "https://openpaths.cc/api/1"
credentials = Credentials.new(consumer_key,consumer_secret)
url = SignedURL.new(credentials, base_url,'GET')
signed_url = url.full_url
res = HTTParty.get(signed_url)
parsed = JSON.parse(res.parsed_response)
@pdarche
pdarche / schumer.json
Created March 20, 2013 22:33
charles schumer's sponsored bills, political parties, and biographical info
This file has been truncated, but you can view the full file.
[{"info": {"last": "Schumer", "middle": "E.", "gender": "M", "religion": "Jewish", "birthday": "1950-11-23", "official_full": "Charles E. Schumer", "first": "Charles"}, "event": "born", "time": "-602967600"}, {"info": {"number": 1487, "docs_house_gov_postdate": null, "titles": [["short", "introduced", "I Love New York Tax Deduction Act of 2001"], ["official", "introduced", "A bill to amend the Internal Revenue Code of 1986 to encourage the patronage of the hospitality, restaurant, and entertainment industries of New York City."]], "sponsor": {"name": "Sen. Charles Schumer [D-NY]", "firstname": "Charles", "twitterid": "chuckschumer", "middlename": "E.", "gender": "male", "bioguideid": "S000148", "namemod": "", "birthday": "1950-11-23", "youtubeid": "SenatorSchumer", "sortname": "Schumer, Charles (Sen.) [D-NY]", "lastname": "Schumer", "gender_label": "Male", "osid": "N00001093", "pvsid": "26976", "nickname": "", "id": 300087, "cspanid": 5929}, "id": 119704, "thomas_link": "http://thomas.loc.gov/cgi-bin/bdquery/
@pdarche
pdarche / senate_committee_assignments_103_112.csv
Created April 14, 2013 18:42
csv of Charles Stewart's Senate committee membership data for the 103rd to 112th congress http://web.mit.edu/17.251/www/data_page.html#2
We can't make this file beautiful and searchable because it's too large.
congress,committee_code,id_num,name,maj/min,rank_within_party_status,party,date_of_assignment,date_of_termination,senior_party_member,committee_seniority,committee_period_of_service,committee_status_at_end_of_congress,commitee_continuitiy_of_assignment_next_congress,appointment_citation,committee_name,state,cd,state_names,notes
103.0,305.0,14307.0,"Leahy, Patrick J.",1.0,1.0,100.0,1993-01-07 00:00:00,1995-01-03 00:00:00,,11.0,19.0,1.0,1.0,S. Res. 5,"Agriculture, Nutrition, and Forestry",6.0,83.0,VT
103.0,305.0,10791.0,"Pryor, David",1.0,2.0,100.0,1993-01-07 00:00:00,1995-01-03 00:00:00,,0.0,15.0,1.0,1.0,S. Res. 5,"Agriculture, Nutrition, and Forestry",42.0,82.0,AR
103.0,305.0,14700.0,"Boren, David L.",1.0,3.0,100.0,1993-01-07 00:00:00,1994-10-15 00:00:00,,0.0,15.0,8.0,0.0,S. Res. 5,"Agriculture, Nutrition, and Forestry",53.0,82.0,OK
103.0,305.0,14705.0,"Heflin, Howell",1.0,4.0,100.0,1993-01-07 00:00:00,1995-01-03 00:00:00,,0.0,13.0,1.0,1.0,S. Res. 5,"Agriculture, Nutrition, and Forestry",41.0,82.0,AL
103.0,30
@pdarche
pdarche / house_committee_assignments_103_112.csv
Created April 14, 2013 18:44
csv of Charles Stewart's House committee membership data for the 103rd to 112th congress http://web.mit.edu/17.251/www/data_page.html#2
We can't make this file beautiful and searchable because it's too large.
congress,committee_code,id_num,name,maj/min,rank_within_party_status,party,date_of_assignment,date_of_termination,senior_party_member,committee_seniority,committee_period_of_service,committee_status_at_end_of_congress,commitee_continuitiy_of_assignment_next_congress,appointment_citation,committee_name,state,cd,state_names,notes
103.0,102.0,10716.0,"de la Garza, E. (Kika)",1.0,1.0,100.0,1993-01-05 00:00:00,1995-01-03 00:00:00,11.0,15.0,2.0,1.0,,AGRICULTURE,,,,
103.0,102.0,10573.0,"Brown, George E., Jr.",1.0,2.0,100.0,1993-01-05 00:00:00,1995-01-03 00:00:00,0.0,11.0,2.0,1.0,,AGRICULTURE,,,,
103.0,102.0,14048.0,"Rose, Charlie",1.0,3.0,100.0,1993-01-05 00:00:00,1995-01-03 00:00:00,0.0,11.0,2.0,1.0,,AGRICULTURE,,,,
103.0,102.0,14219.0,"English, Glenn L.",1.0,4.0,100.0,1993-01-05 00:00:00,1994-01-07 00:00:00,0.0,10.0,2.0,0.0,,AGRICULTURE,,,,
103.0,102.0,14444.0,"Panetta, Leon E.",1.0,5.0,100.0,1993-01-05 00:00:00,1993-01-21 00:00:00,0.0,9.0,2.0,0.0,,AGRICULTURE,,,,
103.0,102.0,14422.0,"Glickman, Daniel R.",1.0,6.0,
@pdarche
pdarche / FizzBuzz.py
Created April 29, 2013 07:04
FizzBuzz
for num in range(1,101):
if num % 3 == 0 and num % 5 == 0:
print "FizzBuzz"
elif num % 5 == 0:
print "Buzz"
elif num % 3 == 0:
print "Fizz"
else:
print num
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This program computes my transportation-related carbon footprint using
Moves app data and the Brighter Planet carbon API. The Moves mobile
app tracks personal activity and displays it as a set of activity segments
like walking, running, and using transportation. I collected a sample of
transportation segments, labeled the transportation type
(car, airplane, subway etc), and then trained a ML algo