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
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
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
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 => [
"b.txt",
"c.txt",
:d => [ "e/", "f.txt" ]
]
@sshaw
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
# https://github.com/sshaw/jaxb2ruby
#
require "happymapper"
module Com module Example module Person
@sshaw
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|
# cfg.id = "your-id" # required
# cfg.domain = :us # optional, defaults to :us, can be a domain name
# cfg.category = "grocery" # optional, default category for search(),
# cfg.secure = true # optional, use https scheme or not, defaults to false
@sshaw
sshaw / yymmdd.rb
Last active Aug 29, 2015
Small DSL for idiomatic date parsing and formatting in Ruby. => Moved to https://github.com/sshaw/yymmdd
View yymmdd.rb
require "date"
# Small DSL for idiomatic date parsing and formatting in Ruby.
# https://gist.github.com/sshaw/53c27b148e903a07e494
#
# Usage:
#
# include YYMMDD
# date = Date.today
#
@sshaw
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
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|
SuckerPunch.logger.info(sprintf "Running %s [%d]\n", id, Thread.current.object_id)
if do_some_thang
@sshaw
sshaw / classes-with-diff-eql-==-behavior.md
Created Oct 26, 2014
Ruby Classes With Different Equality Behavior
View classes-with-diff-eql-==-behavior.md

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

Float

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

IPAddr

@sshaw
sshaw / bh-flash.gemspec
Last active Aug 29, 2015
Render Flash Messages Using Ruby's Bootstrap Helpers (Bh)
View bh-flash.gemspec
Gem::Specification.new do |s|
s.name = "bh-flash"
s.version = "0.0.2"
s.date = "2015-08-02"
s.summary = "Render flash messages using Bootstrap Helpers"
s.description =<<-DESC
Render flash messages using Bootstrap Helpers: http://fullscreen.github.io/bh/
Inspired by: https://github.com/planetargon/flash-message-conductor
DESC
s.authors = ["Skye Shaw"]
You can’t perform that action at this time.