Skip to content
View xor.txt
ternary = foo ? !bar : bar
xor = !!(foo ^ bar)
neq = foo != bar
foo | bar | xor | ternary | neq
-------------------------------------
true | true | false | false | false
false | false | false | false | false
true | false | true | true | true
false | true | true | true | true
View sns_publisher.js
var _ = require('lodash');
var Q = require('q');
var AWS = require('aws-sdk-q');
function SnsPublisher(topic, options) {
var topicOptions = {
params: {
TopicArn: topic
}
};
View each_day.rb
def days(range)
Enumerator.new do |yielder|
now = range.begin
begin
yielder << now if now <= range.end
end while (now = now + 1.day) <= range.end
end
end
days((Time.now - 3.days)..(Time.now)).each { |day| puts day }
View tracked_let.rb
# transaction/truncation strategies won't work when you have a
# capybara feature and you must preserve what's already in the
# database
#
# Usage:
# include TrackedLet
#
# track(:foo) { User.create }
# track!(:foo) { User.create }
# specify { expect(track(User.create)).to be_persisted }
View mail_chimp.rb
require "active_support/core_ext"
require "delegate"
require "mailchimp"
require "singleton"
class MailingList::MailChimp
attr_reader :user, :member_info
def initialize(user, member_fetcher = member_info_api)
@user = user
View mailing_list.rb
require "delegate"
require "singleton"
module MailingList
class SafeResponse < SimpleDelegator
def self.safe_delegate(*methods)
methods.each do |method|
define_method(method, ->(*args, &block) {
value = __getobj__.send(method, *args, &block)
value ? SafeResponse.new(value) : BlackHole.instance
View timecop_helper.rb
RSpec.configure do |config|
config.around(:each, :timecop_freeze) do |example|
time = example.metadata[:timecop_freeze]
time = Time.current.change(usec: 0) if TrueClass === time
Timecop.freeze(time) do
example.call
end
end
end
View keybase.md

Keybase proof

I hereby claim:

  • I am soulcutter on github.
  • I am soulcutter (https://keybase.io/soulcutter) on keybase.
  • I have a public key whose fingerprint is C0D8 559D 4B50 7EF5 EE76 E036 BDEB 33DF 2145 14AC

To claim this, I am signing this object:

View gist:4c55548bd742ff26a9a0
class Digest::Jenkins
MAX_32_BIT = 4294967295
def self.digest(string)
hash = 0
string.each_byte do |byte|
hash += byte
hash &= MAX_32_BIT
View implicit_hashing_struct.rb
Flub = Struct.new(:foo, :bar) do
def to_hash; to_h; end
end
def named(foo:, bar:)
p "foo: #{foo}"
p "bar: #{bar}"
end
named(**Flub.new(1, 2))
Something went wrong with that request. Please try again.