Skip to content

Instantly share code, notes, and snippets.

Documenting things

Brandon Weaver baweaver

Documenting things
Block or report user

Report or block baweaver

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
View hash_set_extension.rb
class Hash
alias_method :+, :merge
def -(other)
other_keys =
# Irrelevant value method
# reject { |k, _v| other_keys.include?(k) }
# Relevant value method
View proposed_pipeline.rb
def double(n) n * 2 end
increment = -> n { n + 1 }
|> double # Method
|> increment # Proc
|> to_s(2) # self.to_s

Tales of the Ruby Grimoire


The council of 3.0 had been called, and Scarlet was readying to join them to discuss the future of the land of Ruby. With her was her student, Red, carrying out his latest lesson.

"Now be sure to finish the remaining problems by the time I return, Red. I expect I'll have many fun things to tell you of when I return." said Scarlet.

Red nodded, still writing away on his scrolls, but as Scarlet exited the castle a sly sort of grin grew on his face.

View contramap.rb
class Proc
def contramap(&fn) self << fn end
adds = -> a, b { a + b }.curry
[1, 2, 3].map(&adds[2])
# => [3, 4, 5]
# What if the type on the left doesn't work with `adds`?
baweaver / async_helpers.js
Created Apr 12, 2019
Helpers for working with ActionCable async on the client side
View async_helpers.js
// Helpers
const MAX_WAIT = 10000;
const POLLING_RATE = 500;
export function timedOut (maxWait) {
const startTime =;
return () => - startTime > maxWait;
baweaver /
Created Jan 26, 2019
Raw notes from my TracePoint session


What is TracePoint?

A class that provides the functionality of Kernel#set_trace_func in a nice Object-Oriented API.

Well what is set_trace_func?

Establishes proc as the handler for tracing, or disables tracing if the parameter is nil.

View tutor_subjects.rb
user_id_tp = tutor_profiles.index_by(&:user_id)
tutor_subjects = TutorSubject
.where(tutor_id: user_id_tp.keys)
.to_h { |uid, subjects| [user_id_tp[uid],] }
# Faster
user_id_tp = tutor_profiles.index_by(&:user_id)
hash_of_arrays = { |h,k| [] }
baweaver /
Last active Jan 28, 2019
Pre 2019 article difficulty rankings for some of my writings

Pre 2019 Articles by Difficulty Ranking

Posts are referenced doubly by difficulty then by chronological release order. Articles with a (+x) notation contain an advanced section that is not necessary reading, but dives into more advanced subject matter as a post-article exploration.


Requires no prerequisite knowledge. Frequently these articles are not directly programming related, and address other topical areas.

This ranking is more likely to grow in 2019, but in the mean time I would suggest reading the content that Mehdi has been writing over the past few years.

baweaver / argument_ripper.rb
Created Dec 31, 2018
First round of argument ripper
View argument_ripper.rb
# Based on:
require 'method_source'
require 'parser/ruby25'
module ArgRipper
class << self
def get_args(meth)
baweaver / sf.rb
Created Dec 27, 2018
Experimental version of Sf, pre-release
View sf.rb
class Sf
attr_reader :operations
OPERATORS = %i(+ - * / % < > <= >= == && & || |)
INSTANCE_OP = -> name {
-> method_name, *args, **kwargs, &fn {
@operations.push(method_name: name, args: args, kwargs: kwargs, fn: fn)
You can’t perform that action at this time.