Skip to content

Instantly share code, notes, and snippets.

View seamusabshere's full-sized avatar

Seamus Abshere seamusabshere

View GitHub Profile
@seamusabshere
seamusabshere / shopify_import_orders.rb
Created May 25, 2020 22:51
Import orders into (paid) Shopify store
Thread.abort_on_exception = true
require 'bundler/setup'
require 'thread/pool'
require 'csv'
require 'shopify_api'
pool = Thread.pool 2
mutex = Mutex.new
# ActiveResource::Base.logger = Logger.new($stderr)
# ActiveResource::Base.logger.level = Logger::DEBUG
### 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 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) {}
#!/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 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'
-- 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 January 24, 2014 22:21
bigml's list of values that count as null
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 January 18, 2023 01:40
hcsv - dump id + values from one hstore column
#!/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 December 17, 2015 12:49
~/bin/gg and ~/bin/mmv
#!/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 December 12, 2015 04:38
hstore that works with jdbc
/* 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'