This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
def b = yield() + 1 | |
l = -> (x) { x + 1 } | |
p = proc { |x| x + 1 } | |
Benchmark.ips do |x| | |
x.report('block') { b { 1 } } | |
x.report('lambda') { l.call(1) } | |
x.report('proc') { p.call(1) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faker' | |
require 'ffaker' | |
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
x.warmup = 2 | |
x.report("Faker::Name.name") { Faker::Name.name } | |
x.report("FFaker::Name.name") { FFaker::Name.name } | |
x.compare! | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
That is 266 microseconds vs 2 microseconds. When compared OpenStuct is a lot slower, but when used infrequently, microseconds are minimal. | |
Just don't use OpenStruct where it will be instantiated a lot or in a performance critical spot in your app. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pp' | |
NAMES = %w[Frank Sean Bryn Quinn Beckett Katie Brent Brook Katelynn Adrian].freeze | |
pickers = NAMES.clone | |
available = NAMES.clone.shuffle | |
matches = {} | |
pickers.each do |picker| | |
picked = available.shift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# Switch to git branch by matching part of a name | |
results = `git branch -l | grep -i #{ARGV[0]} | cut -f 1` | |
branchNames = results.split("\n").map { |bn| bn.sub(/^\*/, '').strip } | |
if branchNames.length == 1 | |
`git checkout #{branchNames.first}` | |
else | |
puts 'More than one branch name matched' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# creates in Seattle using 2 core, 2GB RAM, 64GB storage on Ubuntu 19.04 | |
# note I was using a custom script to install docker. Basically "snap install docker" | |
vultr-cli server create --region 4 --plan 401 --os 338 --script-id <redacted> --label="docker-dev" | |
echo "" | |
echo "Wait about a minute to auto-connect..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
set -u | |
set -o pipefail | |
service_name="${1:-monolith}" | |
container_id="$(docker container ls | grep "opal_$service_name" | head -n1 | cut -d " " -f 1)" | |
docker logs -f $container_id |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date/Time: 2020-01-21 22:46:49 -0800 | |
End time: 2020-01-21 22:47:10 -0800 | |
OS Version: Mac OS X 10.15.2 (Build 19C57) | |
Architecture: x86_64h | |
Report Version: 29 | |
Data Source: Stackshots | |
Shared Cache: 0x6b67000 1C9C4B5C-0A12-39CC-965C-B305BF7F36AA | |
Command: VimR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "2" | |
options: | |
verbose: true | |
syncs: | |
rails-app-sync: | |
compose-dev-file-path: 'docker-compose-dev.yml' | |
notify_terminal: false | |
src: './' | |
sync_strategy: 'native_osx' | |
sync_host_ip: '127.0.0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a ActiveRecord STI class | |
class Hyundai < Car | |
has_one :hyundai_details | |
delegate *HyundaiDetails::ACCESSIBLE_ACCESSOR_METHODS, to: :hyundai_details | |
default_scope { includes(:hyundai_details) } | |
def initialize(args = {}) | |
hyundai_details_attrs = {} | |
args.each do |key, _val| |
NewerOlder