Skip to content

Instantly share code, notes, and snippets.

View seamusabshere's full-sized avatar

Seamus Abshere seamusabshere

View GitHub Profile
-- 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 / gg
Created October 20, 2014 12:53
global search and replace for filenames and file contents implemented in ruby with gsed
#!/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'
#!/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 / safe_tmp_path.rb
Created November 11, 2014 15:48
safe tmp paths including keeping extname
# 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) {}
### 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:
class FriendsController
def index
@friends = @user.friends
@friends_of_friends = slow { @user.friends_of_friends }
end
def import
@result = slow { @user.friends.import(params[:big_csv]) }
end
end
class Gem::Dependency
def to_bundler
args = []
args << name
args << specification.version.to_s if specification.version.to_s.present?
options = {}
options[:require_as] = lib if lib.present?
str = "gem '#{args.join "', '"}'"
str << ", #{options.inspect.gsub(/[\{\}]/, '')}" if options.present?
str
#!/usr/bin/env ruby
require 'rubygems'
require 'activesupport'
class StringReplacer
NEWLINE = "AijQA6tD1wkWqgvLzXD"
START_MARKER = '# START StringReplacer %s -- DO NOT MODIFY'
END_MARKER = "# END StringReplacer %s -- DO NOT MODIFY#{NEWLINE}"
# (1) clone app_production to app_staging
# (2) hit it a couple times so it can cache any s3/etc. data it needs to start up (once you change the data, s3/etc. won't work)
# (3) cap y2k:set DATE="2010-01-01"
# (4) ...test the site...
# (5) cap y2k:unset
task :app_staging do
set :rails_env, 'production'
set :deploy_to, '/data/app'
role :app, "ec2-X-X-X-X.compute-1.amazonaws.com"
role :app, "ec2-Y-Y-Y-Y.compute-1.amazonaws.com"
my-macbook:~/app $ cap y2k:set DATE="2009-12-31 20:59:40"
* executing `y2k:set'
* executing `app_staging'
* executing "sudo -p 'sudo password: ' sh -c \"echo 1 > /proc/sys/xen/independent_wallclock\""
servers: ["ec2-X-X-X-X.compute-1.amazonaws.com", "ec2-X-X-X-X.compute-1.amazonaws.com", "ec2-X-X-X-X.compute-1.amazonaws.com"]
[ec2-X-X-X-X.compute-1.amazonaws.com] executing command
[ec2-X-X-X-X.compute-1.amazonaws.com] executing command
[ec2-X-X-X-X.compute-1.amazonaws.com] executing command
command finished
* executing "sudo -p 'sudo password: ' date --set=\"2009-12-31 20:59:40\""