View summarize_gh_discussions_bookmarklet.rb
def bookmarkletify(js)
'javascript:' + js.lines.map(&:strip).join(';')
end
puts bookmarkletify <<~JS
([...document.querySelectorAll('.discussion-post')].forEach(discussion => {
let top = discussion.getBoundingClientRect().top
let bottom = discussion.querySelector('.comment-body.markdown-body.js-comment-body').getBoundingClientRect().top
discussion.style.height = `${bottom - top}px`
discussion.style.overflow = 'hidden'
View tweetable_ruby.sh
# https://twitter.com/josh_cheek/status/1020504489302904834
# This version is slightly different from what's in the tweet,
# I like the spacing better, it feels more smooth to me.
ruby -e'
r,w,n="\e[41m ","\e[47m ",13
print r,"\e[H\e[2J\n"
9.times{|i|
j=(13-i*1.6).to_i
k=n-j
print r,r*j,w*k,r,w*j,r*3,w*2*k,w*2,r*3,w*j,r,w*k,"\n"
View sib_example.rb
# Something I thought of at 25:06 in this talk: https://www.youtube.com/watch?time_continue=1&v=FDs-sSxo2iY
class If
def initialize(condition)
@condition = condition
end
def then(result)
@condition.then result
end
def inspect
"<if #{@condition.inspect}>"
View tree_resolve.js
// I *think* this is what he was asking for?
// https://twitter.com/trevorbrindlejs/status/1019357853709225984
const treesolve = tree =>
Object.keys(tree).reduce((promise, key) =>
promise.then(newTree =>
(tree[key].then ? tree[key] : treesolve(tree[key]))
.then(value => ({...newTree, [key]: value}))
),
Promise.resolve({})
View fix_fn_binding_with_js_proxies.js
class Human {
constructor(name) {
this.name = name
}
greet(name) {
console.log(`Hi, ${name}, I'm ${this.name}!`)
}
}
Human = new Proxy(Human, {
View bring_back_oldschool_rspec.rb
module MahAssertions
refine BasicObject do
def is(val)
return true if self == val
::Kernel.raise RSpec::Expectations::ExpectationNotMetError, "#{inspect} is not #{val.inspect}", caller
end
end
end
require 'rspec/autorun'
View best_birthday.rb
# I wrote the below code to verify the results of this video:
# https://www.youtube.com/watch?v=99stb2mzspI&t=399s
# Since you think "`if` statement is always a sign of a design flaw. Period",
# rewrite it without `if` statements in a way that's better (note that `unless <condition>` is `if !<condition>`).
require 'prime'
born = 2184
1.upto 200 do |age|
year = born + age
bases, powers = year.prime_division.transpose
View callback_ordering.rb
require 'active_record'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Schema.define do
self.verbose = false
create_table(:users) { |t| t.string :name }
end
class User < ActiveRecord::Base
after_save :append_context
View go
GO LANG NOTES
=============
resources:
https://www.youtube.com/watch?v=XCsL89YtqCs good 5 min vid on binaries/packages/testing
http://golang.org/doc/code.html html version of the above
https://golang.org language
https://golang.org/doc documentation
https://speakerdeck.com/elliott5/write-your-own-go-compiler write your own go compiler
View complex_json_api_example.rb
# SETUP DB
require 'active_record'
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
# SCHEMA
ActiveRecord::Schema.define do
self.verbose = false
create_table :users do |t|
t.string :name
t.timestamps