Skip to content

Instantly share code, notes, and snippets.

View benmoss's full-sized avatar
🙈

Ben Moss benmoss

🙈
View GitHub Profile
st> String comment
'My instances represent 8-bit character strings. Being a very common
case, they are particularly optimized.
Note that, if you care about multilingualization, you should treat
String only as an encoded representation of a UnicodeString. The I18N
package adds more Unicode-friendliness to the system so that encoding
and decoding is performed automatically in more cases. In that case,
String represents a case when the encoding is either unknown, irrelevant,
or assumed to be the system default.'
describe "#pop" do
subject { [3, 4, 5].pop }
it { should == 5 }
end
class Group < AR::Base
has_many :memberships
has_many :members, through: :memberships, class_name: "User"
has_many :global_admin_members, through: :memberships, class_name: "User", conditions: { admin: true }
end
class User < AR::Base
has_many :memberships
has_many :groups, through: :memberships
end
@benmoss
benmoss / barber.rb
Created August 31, 2012 02:43
Sleeping barber problem with Celluloid
# http://en.wikipedia.org/wiki/Sleeping_barber_problem
require 'celluloid'
class Barbershop
include Celluloid
include Celluloid::Logger
def initialize
@waiting_room = WaitingRoom.new
@barber = Barber.new(Actor.current)
@benmoss
benmoss / gist:3753154
Created September 20, 2012 00:11
lein-tarsier stack trace
╰─$ lein vimclojure
Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/tools/nrepl/ack__init.class or clojure/tools/nrepl/ack.clj on classpath: (lein2.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:5440)
at clojure.lang.Compiler.eval(Compiler.java:5415)
at clojure.lang.Compiler.load(Compiler.java:5857)
at clojure.lang.RT.loadResourceScript(RT.java:340)
at clojure.lang.RT.loadResourceScript(RT.java:331)
at clojure.lang.RT.load(RT.java:409)
at clojure.lang.RT.load(RT.java:381)
at clojure.core$load$fn__4519.invoke(core.clj:4915)
@benmoss
benmoss / gist:4535827
Last active December 11, 2015 03:09
manually computing the Ackermann function (http://en.wikipedia.org/wiki/Ackermann_function) for solving examples from the SICP
(defn A [x y]
(cond
(= y 0) 0
(= x 0) (* 2 y)
(= y 1) 2
:else (A (- x 1)
(A x (- y 1)))))
(A 1 10)
(A 0 (A 1 9))
def method_under_test(&block)
SomethingElse.new(&block)
end
@benmoss
benmoss / ar_master_test.rb
Last active December 15, 2015 20:00
Nested has_many throughs with default scopes don't work as expected
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
function! AckGrep()
let command = "ack ".expand("<cword>")
cexpr system(command)
cw
endfunction
router = ->
@resource 'campaign_pics', {path: '/campaigns'}, ->
@route 'new'
@resource 'campaign_pic', {path: '/campaigns/:campaign_pic_id'}, ->
@route 'edit'
@resource 'email_templates', {path: '/templates'}, ->
@route 'new', {path: '/new'}
@route 'export', {path: ':email_template_id/export'}