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
Parsing... | |
Calculating ------------------------------------- | |
nokogiri 127 i/100ms | |
libxml 130 i/100ms | |
ox 716 i/100ms | |
------------------------------------------------- | |
nokogiri 1334.7 (±15.1%) i/s - 6604 in 5.215835s | |
libxml 1287.5 (±1.9%) i/s - 6500 in 5.050367s | |
ox 7228.3 (±3.7%) i/s - 36516 in 5.059256s |
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
module Foo | |
class Application < Rails::Application | |
# Keep the credit card data out of your logs | |
config.filter_parameters += [:password, :credit_card] | |
end | |
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
require 'active_record' | |
require 'pg' | |
ActiveRecord::Base.establish_connection host: 'localhost', | |
database: 'jamie', | |
adapter: 'postgresql' | |
class ARModel < ActiveRecord::Base | |
def initialize(attributes={}) | |
# AR::Base#create w/o args passes nil because lol. |
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
# Add these two gems | |
gem 'thread_safe' | |
gem 'cache_digests' |
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' | |
def fib n | |
if n <= 1 | |
n | |
else | |
fib(n - 1) + fib(n - 2) | |
end | |
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
# If it were possible to override && and || in Ruby, this is how it might look. | |
class NilClass | |
def && other | |
self | |
end | |
def || other | |
other | |
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
class Foo | |
def initialize: (attributes={}) -> | |
# Set default day to Monday | |
# This broke for Sunday (attributes.day == 0) | |
@day = attributes.day || 1 | |
# How I ended up doing it | |
@day = if attributes.hasOwnProperty('day') then attributes.day else 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
class ArticlesController < ApplicationController | |
# with ActiveRecord | |
def create | |
@article = Article.new(params[:article]) | |
if @article.save | |
redirect_to @article, notice: 'Article created!' | |
else | |
render :new | |
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
#!/usr/bin/env ruby | |
puts ARGF.read |
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 'perpetuity/postgres' | |
require 'securerandom' | |
require 'pp' | |
Perpetuity.data_source 'postgres://localhost/customer_stuff' | |
module Customer | |
class User | |
attr_accessor :name, :email, :api_key, :accounts |
OlderNewer