Skip to content

Instantly share code, notes, and snippets.

Bradley Schaefer soulcutter

Block or report user

Report or block soulcutter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@soulcutter
soulcutter / xor.txt
Created Feb 8, 2016
What am I xorring?
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
@soulcutter
soulcutter / sns_publisher.js
Created Dec 11, 2015
Publishing to an SNS topic in AWS lambda (as a promise)
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 }
@soulcutter
soulcutter / tracked_let.rb
Created Jun 10, 2015
RSpec helper for automatically cleaning up database models
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 }
@soulcutter
soulcutter / mail_chimp.rb
Last active Aug 29, 2015
Toggling interest groups in list subscriptions in MailChimp's v2.0 API
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
@soulcutter
soulcutter / mailing_list.rb
Last active Aug 29, 2015
Dealing with crazy nested hashes in MailChimp API responses
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
@soulcutter
soulcutter / implicit_hashing_struct.rb
Created Feb 17, 2015
Struct destructuring and keyword args
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))
You can’t perform that action at this time.