Skip to content

Instantly share code, notes, and snippets.

@mikeauclair
mikeauclair / gist:de976a2baeb182bdee61
Last active August 29, 2015 14:21
Post-punk, mod revival, UK New Wave

1977

  • The Clash - The Clash
  • Elvis Costello - My Aim Is True
  • The Jam - In the City
  • The Jam - This Is the Modern World
  • Wire - Pink Flag

1978

  • The Clash - Give 'Em Enough Rope
  • Elvis Costello & The Attractions - My Aim Is True
module AllIfAny
def validates_all_if_any(fields, options={})
fields = [fields].flatten
all_fields = fields.dup
validates_each(fields, options) do |record, attr_name, value|
if !(all_fields.find_all{|f| !record.send(f).to_s.empty?}.empty?)
record.errors.add(attr_name, (options[:message] || 'is invalid')) if value.to_s.empty?
end
end
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@mikeauclair
mikeauclair / gist:1237551
Created September 23, 2011 14:53
bin mongo bundler
$ gem install bin
Successfully installed bson-1.4.0
Successfully installed mongo-1.3.1
Successfully installed multi_json-1.0.3
Successfully installed activesupport-3.1.0
Successfully installed bin-0.7.0
5 gems installed
$ gem dependency bin
Gem bin-0.7.0
activesupport (~> 3.1.0, runtime)
@mikeauclair
mikeauclair / Basic Oi (Cucumber) Kimchi
Created September 24, 2011 19:38 — forked from jamis/Basic Oi (Cucumber) Kimchi
Basic Oi (Cucumber) Kimchi
BASIC OI (CUCUMBER) KIMCHI
--------------------------------------------------------------------------
Oi (cucumber) kimchi is a delicious, refreshing variation on the
traditional Korean kimchi recipe.
This particular recipe is a modified version of the recipe posted by Dr.
Ben Kim, at http://www.drbenkim.com/how-to-make-cucumber-kim-chi.htm.
--------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Keybase proof

I hereby claim:

  • I am mikeauclair on github.
  • I am mikeauclair (https://keybase.io/mikeauclair) on keybase.
  • I have a public key whose fingerprint is 783C 1A28 9EE3 A88F BE4C 0FFB E2C7 0FC4 D157 FFB3

To claim this, I am signing this object:

class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
class Account
#blahblah
def external_management
if appdirect?
@external_management ||= OpenStruct.new(:user_url => 'blah', :accont_url => 'blah')
end
end
#blahblah
end
@mikeauclair
mikeauclair / person.scm
Created January 18, 2014 19:54
Closures are poor man's objects. Objects are poor man's closures.
(define person (lambda (first last)
(define setFirst (lambda (value) (set! first (list-ref value 0))))
(define setLast (lambda (value) (set! last (list-ref value 0))))
(lambda (method . args)
(case method
('first
(if (null? args)
first
(setFirst args)
)