Skip to content

Instantly share code, notes, and snippets.

View benbalter's full-sized avatar

Ben Balter benbalter

View GitHub Profile
benbalter /
Last active April 23, 2024 13:16
Bulk convert shapefiles to geojson using ogr2ogr
# Bulk convert shapefiles to geojson using ogr2ogr
# For more information, see
# 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 /
Last active April 21, 2024 15:50
Example of how to embed a Gist on GitHub Pages using Jekyll.

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 / wp-db.tutorial.php
Created January 13, 2012 18:41
WordPress DB Tutorial
//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:
global $wpdb;
benbalter /
Last active March 12, 2024 07:39
Example of using drafts in Jekyll

Let's say your Jekyll site's directory structure looks like:

|-- _config.yml
|-- _drafts/
|   |--
|-- _layouts/
|   |-- default.html
|-- _posts/
| |-- 2013-05-10-a-published-post
benbalter / parse-csv.php
Created July 24, 2012 22:28
Parse CSV into Associative Array
$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 /
Created August 17, 2015 20:03
Mirror all organization repositories
for repo in $(curl -v -s "$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 "$" -L "$repo/archive/"
benbalter / regex.rb
Last active March 5, 2023 03:46
Regular expression to find government domains for websites / email addresses
# regex to match government emails. Should detect:
# note: foo.gouvt, foo.gc,, 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 /
Last active December 15, 2022 20:28
Example of how to use Jekyll's `excerpt` tag.

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 / app-store.scpt
Created December 30, 2015 23:07
Programmatically install OS X app store apps
-- 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
on FileExists(theFile) -- (String) as Boolean
tell application "System Events"
if exists file theFile then
return true
benbalter /
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
git remote add upstream
git fetch upstream
git pull upstream master
git push origin master