Skip to content

Instantly share code, notes, and snippets.

Skye Shaw sshaw

Block or report user

Report or block sshaw

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
sshaw / pg_cast.rb
Created Mar 15, 2014
PostgreSQL casting in Rails using the x::typename construct and ActiveRecord's where method
View pg_cast.rb
# Experiment, only tested under Rails 3.2.16, not sure how useful it really is...
# "Works" only with where conditions using a Hash
# Example:
# User.where :created_at::date => "2014-01-01" # :created_at is a timestamp
module PgCast
# All of these are not really viable
TYPES = %w[any char abstime aclitem anyarray anyelement anyenum anynonarray bigint bit bit varying boolean box bytea character character varying cid cidr circle cstring date double precision gtsvector inet int2vector integer internal interval language_handler line lseg macaddr money name numeric oid oidvector opaque path point polygon real record refcursor regclass regconfig regdictionary regoper regoperator regproc regprocedure regtype reltime smallint smgr text tid time with time zone time without time zone timestamp with time zone timestamp without time zone tinterval trigger tsquery tsvector txid_snapshot unknown uuid void xid xml]
sshaw / gist:141bcea8e8362bc2321a
Last active Aug 29, 2015
Iterate over array-like collections in Mojolicious without worrying about references or undef
View gist:141bcea8e8362bc2321a
use Mojo::Base -strict;
use Mojo::Collection;
use Mojo::Util 'monkey_patch';
use Data::Dump 'dd';
monkey_patch 'Mojo::Util',
c => sub { Mojo::Collection->new(Mojo::Util::array(@_)) },
array => sub {
my @data = ( @_ == 1 && ref($_[0]) eq 'ARRAY' ? @{$_[0]} : @_ );
sshaw / gist:5799c2fc39c226823e29
Last active Aug 29, 2015
Syntax for creating directory trees
View gist:5799c2fc39c226823e29
# /a/b.txt
# /a/c.txt
# /a/d/e/
# /a/d/f.txt
:a => [
:d => [ "e/", "f.txt" ]
sshaw / qualified.rb
Last active Aug 29, 2015
Nokorigi HappyMapper Qualified/Unqualified Namespace Parsing
View qualified.rb
# Auto-generated by jaxb2ruby v0.0.1 on 2014-07-05 13:57:07 -0400
require "happymapper"
module Com module Example module Person
sshaw / amazon-affiliate_url.rb
Last active Aug 29, 2015
Ruby Module to Generate Amazon Affiliate URLs for Products and Searches
View amazon-affiliate_url.rb
require "uri"
# Generate Amazon Affiliate URLs for products and searches
# Amazon::AffiliateURL.config do |cfg|
# = "your-id" # required
# cfg.domain = :us # optional, defaults to :us, can be a domain name
# cfg.category = "grocery" # optional, default category for search(),
# = true # optional, use https scheme or not, defaults to false
sshaw / yymmdd.rb
Last active Aug 29, 2015
Small DSL for idiomatic date parsing and formatting in Ruby. => Moved to
View yymmdd.rb
require "date"
# Small DSL for idiomatic date parsing and formatting in Ruby.
# Usage:
# include YYMMDD
# date =
sshaw / gist:1cd69d078cffeebc76cd
Created Aug 25, 2014
Install Ruby SBDB on OS X
View gist:1cd69d078cffeebc76cd
brew install berkeley-db4
gem install sbdb -- --with-db-lib=/usr/local/opt/berkeley-db4/lib --with-db-include=/usr/local/opt/berkeley-db4/include/
sshaw / q.rb
Last active Aug 29, 2015
SuckerPunch + GDBM: Don't think GDBM can be used with 2 writers...
View q.rb
require "gdbm"
require "sucker_punch"
class IdBasedJob
include SuckerPunch::Job
def perform(db, ids)
ids.each do |id| "Running %s [%d]\n", id, Thread.current.object_id)
if do_some_thang
sshaw /
Created Oct 26, 2014
Ruby Classes With Different Equality Behavior

Ruby Classes With Different ==, eql?, and === Behavior


1.0 == 1     # true
1.0.eql? 1   # false
1.0 === 1    # true


sshaw / bh-flash.gemspec
Last active Aug 29, 2015
Render Flash Messages Using Ruby's Bootstrap Helpers (Bh)
View bh-flash.gemspec do |s| = "bh-flash"
s.version = "0.0.2" = "2015-08-02"
s.summary = "Render flash messages using Bootstrap Helpers"
s.description =<<-DESC
Render flash messages using Bootstrap Helpers:
Inspired by:
s.authors = ["Skye Shaw"]
You can’t perform that action at this time.