Skip to content

Instantly share code, notes, and snippets.

@fgrehm
fgrehm / gist:3841631
Created October 5, 2012 18:45
guard-rspec with acceptance and unit tests split up
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"] }
@fgrehm
fgrehm / gist:3744111
Created September 18, 2012 16:28
Validar CNPJ
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 / ClientSideValidations_TwitterBoostrap_SimpleForm.coffee
Created September 18, 2012 14:10 — forked from ddarren/ClientSideValidations_TwitterBoostrap_SimpleForm.js
Script to Make Client Side Validations Work w/ Twitter Bootstrap & Simple Form
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
@fgrehm
fgrehm / Results JRuby
Created March 9, 2012 00:51 — forked from sam/gist:2002262
Router Benchmark
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 / gist:1917450
Created February 26, 2012 15:54
Virtus custom attribute using coercion lib
require 'json'
Virtus::Coercion::String.class_eval do
def self.to_hash(value)
JSON.parse(value)
end
end
module MyApp
module Attributes
@fgrehm
fgrehm / gist:1821958
Created February 14, 2012 00:43
DM #attributes
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
DataMapper.setup(:default, 'sqlite::memory:')
class Product
include DataMapper::Resource
property :id, Serial
@fgrehm
fgrehm / keybase.md
Created September 17, 2015 19:50
keybase.md

Keybase proof

I hereby claim:

  • I am fgrehm on github.
  • I am fgrehm (https://keybase.io/fgrehm) on keybase.
  • I have a public key whose fingerprint is 3C39 3ABD 6DDE 83DF 66EA 245A DEAF 326E 2F12 76F2

To claim this, I am signing this object:

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
@fgrehm
fgrehm / gist:186797
Created September 14, 2009 17:48 — forked from wiecklabs/gist:186777
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__)
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