Skip to content

Instantly share code, notes, and snippets.

View maetl's full-sized avatar

Mark Rickerby maetl

View GitHub Profile
@maetl
maetl / gist:4542fc2390eb8701284e
Last active September 30, 2015 21:54
Using transproc to compose various hash transformations and mappings
require 'transproc/all'
require 'addressable/uri'
##
# Convert string keys to symbols
#
transform = Transproc(:symbolize_keys)
data = {
'name' => 'Mark Rickerby',
@maetl
maetl / hash_spec.rb
Created March 30, 2015 09:51
Interesting quirk with Structs in Transproc
# spec/integration/hash_spec.rb
describe 'combining transformations' do
it 'applies functions to a struct' do
symbolize_keys = Transproc(:symbolize_keys)
map = Transproc(:map_hash, user_name: :name, user_email: :email)
transformation = symbolize_keys + map
InputUser = Struct.new(:user_name, :user_email)
@maetl
maetl / Rakefile
Created March 22, 2015 02:30
Screen scraping 101
require 'nokogiri'
require 'json'
POPULATION = 'List_of_countries_and_dependencies_by_population'
ISO_CODES = 'ISO_3166-1'
COUNTRY_CODES = {}
COUNTRIES = []
def make_country(code, name, population)
@maetl
maetl / gist:363fe5d7ba14215b054f
Created March 3, 2015 14:09
rom rails stack trace
/Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/support/registry.rb:26:in `block in []': nil doesn't exist in ROM::RelationRegistry registry (ROM::Registry::ElementNotFoundError)
from /Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/support/registry.rb:26:in `fetch'
from /Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/support/registry.rb:26:in `[]'
from /Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/setup/finalize.rb:91:in `block in load_readers'
from /Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/setup/finalize.rb:90:in `each'
from /Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/setup/finalize.rb:90:in `load_readers'
from /Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/setup/finalize.rb:53:in `run!'
from /Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/setup.rb:61:in `finalize'
from /Users/maetl/.rvm/gems/ruby-2.1.4/gems/rom-0.6.0.beta2/lib/rom/global.rb:176:in `finalize'
from /Use
@maetl
maetl / toy_model.rb
Created June 12, 2014 10:50
Proof of concept for a toy ORM that combines some aspects of the ActiveRecord API with an in-memory query model based on the Axiom relational algebra API.
require 'virtus'
require 'axiom-memory-adapter'
module Mementus
# Proof of concept for a toy ORM that combines some aspects of the
# ActiveRecord API with an in-memory query model based on the Axiom
# relational algebra API.
#
# The weirdest trick is that the data stored in the relational model
@maetl
maetl / gist:8914783
Created February 10, 2014 12:10
Heroku Ruby/Bower buildpack with branch that fixes the caching race condition bullshit from Bower
heroku config:set BUILDPACK_URL=git://github.com/qnyp/heroku-buildpack-ruby-bower.git#workaround-for-bower-cache-bug
@maetl
maetl / geography_model.js
Created September 3, 2013 11:03
Mozart models in raw JS... can they work?
var Geography;
window.Geography = this.Geography = Geography = {};
Geography.Country = Mozart.Model.create({
modelName: "Country"
});
Geography.Country.attributes({
name: "string",
String::endsWith = (s) -> this[this.length-s.length...] == s
@maetl
maetl / gist:1312672
Created October 25, 2011 13:09
Epiphyte Syntax for TextMate
{ scopeName = 'source.epiphyte';
fileTypes = ( 'phyte' );
foldingStartMarker = '(client|resource|collection).*$';
foldingStopMarker = '^\s*end';
patterns = (
{ name = 'keyword.other.declaration';
match = '\b(collection|end)\b';
},
{ name = 'meta.client.epiphyte';
match = '(client)(\s+[A-Za-z0-9\_]+)*';
@maetl
maetl / gist:1245106
Created September 27, 2011 13:57
PHP Reserved Words
<?php
function is_reserved_word($word)
{
return (in_array($word, array(
"abstract",
"and",
"array",
"as",
"break",