Skip to content

Instantly share code, notes, and snippets.

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
View parse-csv.php
<?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 / gist.md
Last active May 5, 2023 11:03
Example of how to embed a Gist on GitHub Pages using Jekyll.
View gist.md

Here's an example of how to embed a Gist on GitHub Pages:

{% gist 5555251 %}

All you need to do is copy and paste the Gist's ID from the URL (here 5555251), and add it to a gist tag surrounded by {% and %}.

@benbalter
benbalter / mirror-org-repos.sh
Created August 17, 2015 20:03
Mirror all organization repositories
View mirror-org-repos.sh
org="whitehouse"
for repo in $(curl -v -s "https://api.github.com/orgs/$org/repos?per_page=100&type=sources" 2>&1 | grep '"full_name": "*"' | cut -d':' -f2 | sed s'/,$//' | sed s'/"//g' ); do
filename=$(echo "$repo" | cut -d'/' -f2)
echo "Downloading $repo..."
curl -o "$filename.zip" -L "https://github.com/$repo/archive/master.zip"
done
@benbalter
benbalter / regex.rb
Last active March 5, 2023 03:46
Regular expression to find government domains for websites / email addresses
View regex.rb
# regex to match government emails. Should detect:
# foo.gov, foo.mil
# foo.gov.uk, foo.mil.uk
# foo.fed.us
# foo.govt.nz, foo.gc.ca, foo.guv.ro, gub.uy
# note: foo.gouvt, foo.gc, foo.fed.uk, etc. will technically pass, but they are invalid domains
regex = /(\.g[ou]{1,2}(v|b|vt)|\.mil|\.gc|\.fed)(\.[a-z]{2})?$/i
@benbalter
benbalter / wp-db.tutorial.php
Created January 13, 2012 18:41
WordPress DB Tutorial
View wp-db.tutorial.php
<?php
//absolute path to wp-load.php, or relative to this script
//e.g., ../wp-core/wp-load.php
include( 'trunk/wp-load.php' );
//grab the WPDB database object, using WP's database
//more info: http://codex.wordpress.org/Class_Reference/wpdb
global $wpdb;
@benbalter
benbalter / excerpt.md
Last active December 15, 2022 20:28
Example of how to use Jekyll's `excerpt` tag.
View excerpt.md

If your post looked something like:

# Awesome Blog Post

Here is an example post to show how to use the new `excerpt` tag.

The excerpt tag provides a quick and easy way to tease a post by exposing only the first paragraph such as on a blog index page.
@benbalter
benbalter / geojson-conversion.sh
Last active November 10, 2022 21:05
Bulk convert shapefiles to geojson using ogr2ogr
View geojson-conversion.sh
# Bulk convert shapefiles to geojson using ogr2ogr
# For more information, see http://ben.balter.com/2013/06/26/how-to-convert-shapefiles-to-geojson-for-use-on-github/
# Note: Assumes you're in a folder with one or more zip files containing shape files
# and Outputs as geojson with the crs:84 SRS (for use on GitHub or elsewhere)
#geojson conversion
function shp2geojson() {
ogr2ogr -f GeoJSON -t_srs crs:84 "$1.geojson" "$1.shp"
}
@benbalter
benbalter / app-store.scpt
Created December 30, 2015 23:07
Programmatically install OS X app store apps
View app-store.scpt
-- List of app store apps to install, if not installed
-- Name must exactly match name as it appears on the "Purchased" tab of the App Store
set myApps to {"Chroma for Hue", "Pushbullet", "Thessa", "TweeDeck by Twitter", "Calca", "Gif Brewery", "Twitter"}
-- via http://stackoverflow.com/a/3469708
on FileExists(theFile) -- (String) as Boolean
tell application "System Events"
if exists file theFile then
return true
else
@benbalter
benbalter / fork-a-branch.sh
Created December 11, 2012 19:39
How to fork a single branch of a repo, preserving commit log
View fork-a-branch.sh
mkdir target-repo
cd target-repo
git init
git remote add origin git@github.com...
git remote add upstream git@github.com....
git fetch upstream
git pull upstream master
git push origin master
Alternative:
@benbalter
benbalter / Example--text.txt
Created October 18, 2012 19:37
Markdown Example
View Example--text.txt
Markdown Example
===============
This is the raw markdown used to generate the below web content.
Bulleted List
-------------
* Foo
* Bar