Skip to content

Instantly share code, notes, and snippets.

View fbernier's full-sized avatar
👷‍♂️

François Bernier fbernier

👷‍♂️
View GitHub Profile
require "celluloid"
class MyClass
include Celluloid
def initialize
@a = 0
end
def do_something
@fbernier
fbernier / a.rb
Created July 18, 2012 15:15
difference in execution
trans = Transaction.filter(~{:somecolumn => nil}, :send_time => nil)
trans.each do |t|
# do something
end
@fbernier
fbernier / gist:3307057
Created August 9, 2012 18:48
any reason to break?
require 'celluloid'
class MyClass
include Celluloid
def do_some
'yo'
end
end
a = Myclass.new
@fbernier
fbernier / gist:3682112
Created September 9, 2012 02:18
wtf actor count
require 'celluloid'
class Yo
include Celluloid
end
puts Celluloid::Actor.all.length
@fbernier
fbernier / capybara.md
Created September 14, 2012 00:06 — forked from steveclarke/capybara.md
RSpec Matchers

Capybara

save_and_open_page

Matchers

have_button(locator)
# 2. Include Sweeping module in your controller(s) to have cache_sweeper
# method to be avaliable, or right in ApplicationController so it will be
# available in all controllers inheriting from it.
class ApplicationController < ActionController::Base
include ActionController::Caching::Sweeping
# ...
end
let(:date) do
Time.now
end
it "converts the elements properly" do
p date.zone
mongoized.first.should eq(date)
p date.zone
end
@fbernier
fbernier / meta.rb
Last active December 12, 2015 04:38
# Any difference between:
[:db_create, :db_drop, :db_list].each do |cmd|
#THIS:
define_method(cmd) do |*args|
NoBrainer.run { RethinkDB::RQL.send(cmd, *args) }
end
# OR THIS
@fbernier
fbernier / gist:5319833
Last active December 15, 2015 20:40
Single quote vs double quote in ruby
require "benchmark/ips"
Benchmark.ips do |x|
x.report("double quote assignment:") {a = "yo man"}
x.report("double quote +:") {|i| a = "yo man" + i.to_s}
x.report("double quote <<:") {|i| a = "yo man" << i.to_s}
x.report("double quote interpolation:") {|i| a = "yo man #{i}"}
x.report("single quote assignment:") {a = 'yo man'}
x.report("single quote +:") {|i| a = 'yo man' + i.to_s}
(ns phrase
(:require [clojure.string :as str]))
(defn- strip-punctuation [phrase]
(str/replace phrase #"[^\w\s]" "")
)
(defn word-count [phrase]
(frequencies (str/split(str/lower-case (strip-punctuation phrase)) #"\s+"))
)