Skip to content

Instantly share code, notes, and snippets.

View gist:184843
class Address # Our custom, embedded-value type
orm.map_type do |signature, types|
signature.from [self]
signature.typecast_left method(:__load__)
signature.to [types.string, types.string, types.string, types.string, types.string]
signature.typecast_right method(:__dump__)
end
end
class Zoo
View gist:186797
class Address # Our custom, embedded-value type
accessor :address => String
accessor :address_2 => String
accessor :city => String
accessor :state => String
accessor :zip_code => String
orm.map_type do |signature, types|
signature.from [self]
signature.typecast_left method(:__load__)
View gist:212121
orm.map(Exhibit, "exhibits") do |exhibits, type|
exhibits.field :id, type.serial
exhibits.field :name, type.string(200)
exhibits.field :zoo_id, type.integer
exhibits.key :id
end
orm.map(ZooKeeper, 'zoo_keepers') do |zoo_keepers, type|
zoo_keepers.field :id, type.serial
View gist:1821958
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
DataMapper.setup(:default, 'sqlite::memory:')
class Product
include DataMapper::Resource
property :id, Serial
@fgrehm
fgrehm / gist:1917450
Created Feb 26, 2012
Virtus custom attribute using coercion lib
View gist:1917450
require 'json'
Virtus::Coercion::String.class_eval do
def self.to_hash(value)
JSON.parse(value)
end
end
module MyApp
module Attributes
@fgrehm
fgrehm / Results JRuby
Created Mar 9, 2012 — forked from sam/gist:2002262
Router Benchmark
View Results JRuby
Rehearsal -------------------------------------------------------------
INSERTION STATIC : Tree 0.334000 0.000000 0.334000 ( 0.334000)
INSERTION STATIC : Regexp 0.244000 0.000000 0.244000 ( 0.244000)
MATCHING STATIC : Tree 1.297000 0.000000 1.297000 ( 1.297000)
MATCHING STATIC : Regexp 13.382000 0.000000 13.382000 ( 13.382000)
--------------------------------------------------- total: 15.257000sec
user system total real
INSERTION STATIC : Tree 0.045000 0.000000 0.045000 ( 0.045000)
INSERTION STATIC : Regexp 0.106000 0.000000 0.106000 ( 0.106000)
@fgrehm
fgrehm / ree-1.8.7-2011.03
Created Aug 14, 2012
ruby-build REE definitions for Ubuntu 12.04
View ree-1.8.7-2011.03
build_package_patched() {
# These three patches are included when RVM builds REE
cd source
wget 'https://github.com/wayneeseguin/rvm/raw/master/patches/ree/1.8.7/tcmalloc.patch'
wget 'https://github.com/wayneeseguin/rvm/raw/master/patches/ree/1.8.7/stdout-rouge-fix.patch'
wget 'https://github.com/wayneeseguin/rvm/raw/master/patches/ree/1.8.7/no_sslv2.diff'
patch -p1 < tcmalloc.patch
patch -p1 < stdout-rouge-fix.patch
patch -p1 < no_sslv2.diff
cd ..
@fgrehm
fgrehm / ClientSideValidations_TwitterBoostrap_SimpleForm.coffee Script to Make Client Side Validations Work w/ Twitter Bootstrap & Simple Form
View ClientSideValidations_TwitterBoostrap_SimpleForm.coffee
jQuery ($) ->
$("div.control-group").focusout ->
$this = $(this)
if !$this.hasClass("error")
$this.addClass("success")
ClientSideValidations.formBuilders['SimpleForm::FormBuilder'].wrappers.bootstrap =
add: (element, settings, message) ->
wrapper = element.closest(".#{settings.wrapper_class}")
if element.data('valid') != false
View gist:3744111
window.validarCnpj = (cnpj) ->
cnpj = cnpj.replace(/\/|\.|-/g,"")
allEqual = /^(.)\1+$/
return if (cnpj.length < 14) || allEqual.test(cnpj)
a = []
b = 0
c = [6,5,4,3,2,9,8,7,6,5,4,3,2]
@fgrehm
fgrehm / gist:3841631
Created Oct 5, 2012
guard-rspec with acceptance and unit tests split up
View gist:3841631
guard 'rspec', :version => 2, :spec_paths => ["spec/models", 'spec/controllers'] do
watch(%r{^spec/(models|controllers).+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { ["spec/controllers", 'spec/models'] }
watch('spec/factories/*.rb') { ["spec/controllers", 'spec/models'] }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
You can’t perform that action at this time.