Skip to content

Instantly share code, notes, and snippets.

View just3ws's full-sized avatar

Mike Hall just3ws

View GitHub Profile
@just3ws
just3ws / de_morgans_laws.rb
Last active November 20, 2018 15:22
De Morgan's laws (in Ruby)
puts "<< De Morgan's laws >>\n\n"
PAIRS = [
[false, true],
[true, false],
[true, true],
[false, false]
]
puts "\"NOT (A AND B)\" is the same as \"(NOT A) OR (NOT B)\""
@just3ws
just3ws / forwards_from_grannie.rb
Last active September 1, 2015 17:24
FW: FW: FW:
require 'forwardable'
class Said
attr_reader :msg
def initialize(msg = nil)
@msg = (msg || '').freeze
end
def loud_enough?
@just3ws
just3ws / its_all_just_about_the_view.rb
Created April 20, 2016 15:53
Customizing logic for use by logger
# Simple logger
logger = Logger.new(STDOUT)
# Some object
Foo = Struct.new(:hello, :goodbye)
foo = Foo.new
foo.hello = 'Hola'
foo.goodbye = 'Adiós'
@just3ws
just3ws / getting rubygems to work with libv8 on el capitan.sh
Created April 28, 2016 16:41
Getting RubyGems that depend on an older libv8 to work with El Capitan OS X
brew tap homebrew/versions
brew install v8-315
brew unlink v8-315 && brew link v8-315
brew link --force v8-315
bundle config --global build.libv8 --with-system-v8
bundle install --full-index --jobs 4 --clean
@just3ws
just3ws / refresh-ruby-repo.zsh
Last active March 9, 2017 14:34
Update git repos and install bundler if not present
echo "BEGIN updating: $(pwd)"
cd "$1/.."
git fetch --all --prune --verbose
[[ -a Gemfile && "$(gem query --installed '^bundler$')" == 'false' ]] && gem install bundler --no-document
bundle check || bundle install
@just3ws
just3ws / building_up_module_declarations.sh
Last active April 5, 2017 21:32
Inline vs Nested Ruby Module Declarations
ruby -W2 -v -e ' (ruby-2.2.2@benchprep) wip-simulation-endpoints 9a603b95e ✗
puts "before"
module Foo
puts "- Foo -"
end
puts "more"
module Foo::Bar
puts "- Foo::Bar -"
end
@just3ws
just3ws / all.sql
Last active April 12, 2017 14:34
Refactoring Postgres Queries
explain (analyze on, buffers on, verbose on, timing on)
select l.id, l.simulation_id, l.user_id, l.content_package_id, l.score, l.result, l.total_time_taken, l.created_at, l.updated_at
from simulation_results l
inner join (
select simulation_id, max(created_at) created_at
from simulation_results
where user_id = 827911
group by simulation_id
) r
on l.simulation_id = r.simulation_id and l.created_at = r.created_at
@just3ws
just3ws / explain_explained_notes.md
Created April 19, 2017 14:59
Postgres EXPLAIN Lunch & Learn @ BenchPrep

Postgres EXPLAIN Lunch & Learn @ BenchPrep

EXPLAIN Explained video on YouTube

What EXPLAIN doesn't do

  • Tell you why a particular index isn't used
  • Explain how to rewrite your queries
  • Show what other factors make the DB slow
  • Tell you how much time the request took outside the DB
@just3ws
just3ws / c-p-and-me.txt
Created May 16, 2017 14:40
C, P, and me
yyyyy/:oyyyysyyyyyyyyyysssoooo+++++//+///+/+++++/++oosso/:::+++++ooooossyyyyysssssso+:----.````````````-+ssyyyyyyysssssss/-/hyyyyyyyyyyyyyyyssssssssss+-:yhhhhhhhhhhhhhyyyyyysss+..+so++//:+sdNNNNMMMMMMMMMMMMMMMMMMMMMMMMMNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNNNNmmdhydddy///++/---:-:--/ossoossssyyyyyyyyhho+syyssssoooooo+++++//////:::---::::::://+++++ooo++++++/++/://++++++oooo+/-.:/:.-/::/:://:.:--+oo++oosssoossyssshyyyysossyyhysyyyyyysysoso+oo+ss++++so:.-:::--+:::://-//:--//::+syy
yyyyy+-/yyyyyyyyyyyyyyyyyyyyyyyyyys//ssssssssossssssssso/--:++oo+ooooosysyyyyyyyyyyys/-----````````````.:/:::::::///++oss/-/yyyhhyyyyyyyyyyyssyyssssss+-:shhhhhhhhhhhhhhhhhhyyyyo-.ohyhhyhdmNMNNNMMMMMMMMMMMMMMMMMMMMMMMMMMNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNNNNNmdhhhhys:-o+//----::-:+ooossssyyyyyyyyyhhhys+sssssssooooooo+++///:::::---.---::::////+++++++++++///////++++++++++++++:..:/--.//:/:::::--:-/ooooo+sysssshhsyyyssysyyhhyyyyyyysssyysoooo+ooo++/+::++::+o+/:+o++/-+oo++++ooo++/sy
yyyyy+-/yyyyyyyyyyyyyy
@just3ws
just3ws / RSpec tags and opts for easier test execution.md
Created August 17, 2017 19:44
RSpec tags and opts for easier test execution

To easily limit the execution of RSpec tests while you are developing use the power of the .rspec opts file and RSpec tags.

Tags can be added to any RSpec method describe, context, it, etc.

The are simply arguments passed as a Hash to the method.

describe 'foo', focus: true do
 context 'bar', slow: true do