Skip to content

Instantly share code, notes, and snippets.

Seamus Abshere seamusabshere

Block or report user

Report or block seamusabshere

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:dca36bc5f1a99217af9c
### Keybase proof
I hereby claim:
* I am seamusabshere on github.
* I am seamusabshere (https://keybase.io/seamusabshere) on keybase.
* I have a public key whose fingerprint is 00E8 B10F 062A 1672 DF80 F69A 6417 28F0 0400 349E
To claim this, I am signing this object:
@seamusabshere
seamusabshere / safe_tmp_path.rb
Created Nov 11, 2014
safe tmp paths including keeping extname
View safe_tmp_path.rb
# requires the zaru gem, just get it :)
require 'tmpdir'
require 'zaru'
def tmp_path(name_hint = nil)
name_hint ||= 'tmp'
extname = File.extname name_hint
name_hint = Zaru.sanitize! File.basename(name_hint, extname).to_s.gsub(/\s+/, '_')
path = Dir::Tmpname.create(name_hint) {}
View osx-for-hackers.sh
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
@seamusabshere
seamusabshere / gg
Created Oct 20, 2014
global search and replace for filenames and file contents implemented in ruby with gsed
View gg
#!/usr/bin/env ruby
# USAGE gg "hello world" "hola mundo"
# * requirements: gem install posix-spawn, sudo port install coreutils (gsed)
# * changes file names and file contents (in the right order!)
# * limited regex support - it has to work with `system 'gsed', '--in-place', '-e', "s%#{search}%#{replace}%g", path`
require 'posix/spawn'
require 'fileutils'
force = ENV['FORCE'] == 'true'
View democall.sql
-- SELECT Faraday_JoyDivision('households'::text, 'year_built'::text) AS the_geom
explain analyze WITH
-- Snap the disparate points to a regular grid where theres data for the given filter
grid AS (
SELECT
-- note transform here
ST_SnapToGrid(ST_Transform(the_geom, 4326), 0.002) the_geom,
year_built
@seamusabshere
seamusabshere / bigml_null.rb
Created Jan 24, 2014
bigml's list of values that count as null
View bigml_null.rb
MISSING = %w{ N/A n/a NULL null - #DIV/0 #REF! #NAME? NIL nil NA na #VALUE! #NULL! NaN #N/A #NUM! ? }
@seamusabshere
seamusabshere / hcsv
Last active Jan 19, 2016
hcsv - dump id + values from one hstore column
View hcsv
#!/usr/bin/env ruby
# Usage: hcsv DBNAME TBLNAME HSTORECOL
# Output columns will be id + all the hstore keys
dbname, tblname, hstorecol = ARGV[0..2]
# Get hstore keys
out = `psql #{dbname} --tuples --command "SELECT DISTINCT k FROM (SELECT skeys(#{hstorecol}) AS k FROM #{tblname}) AS dt ORDER BY k"`
headers = out.split(/\n/).map(&:strip)
@seamusabshere
seamusabshere / gg
Last active Dec 17, 2015
~/bin/gg and ~/bin/mmv
View gg
#!/bin/bash
set -x
read -p "Replace contents? (y/n) " RESP
if [ "$RESP" = "y" ]; then
ack --print0 -l "$1" | xargs -0 -n 1 gsed --in-place="" -e "s%$1%$2%g"
fi
read -p "Replace in filenames? (y/n) " RESP
if [ "$RESP" = "y" ]; then
find . -print0 -not -path "*.git*" -a -name "*$1*" | xargs -0 -n 1 mmv "s/$1/$2/"
fi
@seamusabshere
seamusabshere / hstore--1.x.sql
Last active Dec 12, 2015
hstore that works with jdbc
View hstore--1.x.sql
/* contrib/hstore/hstore--1.1.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION hstore" to load this file. \quit
CREATE TYPE hstore;
CREATE FUNCTION hstore_in(cstring)
RETURNS hstore
AS 'MODULE_PATHNAME'
View result1.txt
$ ruby bar.rb
0 ELIZABETH WATERS, MADISON, WI 53706
geocoder latitude +/- longitude +/- quality
AVERAGE 43.07671/43.07689 -89.40950/-89.40921
mapquest 43.07620 +11 -89.40950 +0 zip
google 43.07671 +0 -89.40696 +28 point_of_interest/university/establishment/approximate
yahoo 43.07477 +45 -89.41118 -18 59
geocoda 43.07776 -24 -89.41333 -42 zip
datasciencetoolkit 43.08856 -275 -89.37360 +401 street_address/rooftop
You can’t perform that action at this time.