Skip to content

Instantly share code, notes, and snippets.

View benbalter's full-sized avatar
Verified

Ben Balter benbalter

Verified
View GitHub Profile
@benbalter
benbalter / parse-csv.php
Created July 24, 2012 22:28
Parse CSV into Associative Array
<?php
$lines = explode( "\n", file_get_contents( 'input.csv' ) );
$headers = str_getcsv( array_shift( $lines ) );
$data = array();
foreach ( $lines as $line ) {
$row = array();
foreach ( str_getcsv( $line ) as $key => $field )
@benbalter
benbalter / potus-tracker.php
Created September 12, 2012 21:30
JSON feed of president's daily (public) schedule
<?php
include '../wp-load.php';
$url = 'http://www.whitehouse.gov/schedule/president/feed';
$terms_blacklist = array(
'president',
'vice president',
'first lady',
);
@benbalter
benbalter / benchmarks.txt
Created September 29, 2012 20:04
hackshackers.com benchmarks
Old site ( 50 concurrent requests over 30 seconds )
Transactions: 496 hits
Availability: 100.00 %
Elapsed time: 29.03 secs
Data transferred: 12.34 MB
Response time: 2.71 secs
Transaction rate: 17.09 trans/sec
@benbalter
benbalter / gov-repo-cloud.php
Created October 9, 2012 21:21
Generate a tag cloud of the .Gov Open Source Repos on Github
<?php
//social media registry
$account_query = 'http://registry.usa.gov/accounts.json?service_id=github&agency_id=&tag=';
//URL to query GitHub API to retreive repos
$repo_query = 'https://api.github.com/users/%s/repos';
//max size
$max_size = 60;
@benbalter
benbalter / benchmarks.txt
Created October 9, 2012 23:51
WiFi Benchmarks
WiFi Benchmarks
===============
Before
------
ping / down / up
Laptop | Office: 17 / 3.51 / 1.18
Phone | Office: 30 / 3.4 / .768
@benbalter
benbalter / Example--text.txt
Created October 18, 2012 19:37
Markdown Example
Markdown Example
===============
This is the raw markdown used to generate the below web content.
Bulleted List
-------------
* Foo
* Bar
@benbalter
benbalter / clone-org.sh
Created October 23, 2012 17:43
Clone all Repos in a GitHub Organization
curl -s "https://api.github.com/orgs/project-open-data/repos?per_page=100" | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["clone_url"]} ]}'
@benbalter
benbalter / into-to-json.md
Created October 25, 2012 13:35
Into to JSON

JSON is a lightweight and simple way to represent machine-readable data. It is quickly becoming the defacto standard for shuttling data across the internet, fueled primarily by the rise of mobile and APIs. Most if not all modern programing languages can interpret and produce JSON out of the box.

The most basic element of JSON is a JSON object. JSON objects are bound by curly braces ( { and }). WIthin the object is a series of key, value pairs, both enclosed with double quotes and separated by a colon and a space. Individual elements within the object (each key/value pair) are separated by commas just as you would in english. For example, an object representing a dog may be:

{ "name": "Fido", "type": "Golden Retriever" }

Multiple objects are grouped into an array, denoted by square braces ( [ and ] ). Each object within the array is separated by a comma, just as you would in a list of english words. Thus a group of two dogs would be:

@benbalter
benbalter / fork-a-branch.sh
Created December 11, 2012 19:39
How to fork a single branch of a repo, preserving commit log
mkdir target-repo
cd target-repo
git init
git remote add origin [email protected]...
git remote add upstream [email protected]....
git fetch upstream
git pull upstream master
git push origin master
Alternative:
@benbalter
benbalter / like.rb
Created December 27, 2012 04:12
Auto like a given user's foursquare checkins
require 'foursquare2'
access_token = ''
target_user_id = ''
#URL to request access token
#https://foursquare.com/oauth2/authenticate?client_id=XXX&response_type=token&redirect_uri=http://local.dev
client = Foursquare2::Client.new( :oauth_token => access_token, :api_version => '20120505' )