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
# Expirable is a module that lets you easily cache | |
# groups of records, either across an entire record: | |
# cache(Snippet) => cache(Snippet.cache_key) | |
# or, across a scope: | |
# cache(page.blocks) => cache(page.blocks.cache_key) | |
# | |
# Why not just use `maximum(:updated_at)`? | |
# Because it requires 2 queries: the total count, | |
# and the updated_at timestamp |
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
/** | |
* Definition for singly-linked list. | |
* type ListNode struct { | |
* Val int | |
* Next *ListNode | |
* } | |
* Runtime: 8 ms, faster than 88.19% of Go online submissions for Add Two Numbers. | |
* Memory Usage: 4.3 MB, less than 100.00% of Go online submissions for Add Two Numbers. | |
*/ | |
var one = ListNode{ Val: 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 isn't mine | |
# I can't remember where I found it, but mad props to whoever created it | |
class Hash | |
def filter | |
result = self.map do |k, v| | |
r = yield v | |
[k, r] | |
end | |
Hash[*result.flatten] |
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
console: bundle exec rails console | |
rake: bundle exec rake | |
web: daemonized-worker & web | |
worker: worker |
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
# setup | |
RAILS_VERSION="5.1.1" | |
gem install rails -v $RAILS_VERSION && \ | |
rails _${RAILS_VERSION}_ new rails-${RAILS_VERSION}-test && \ | |
cd rails-${RAILS_VERSION}-test && \ | |
rails generate model User && \ | |
rails db:migrate && \ | |
echo 'class User < ActiveRecord::Base; FOO = where(id: [1]); end' > app/models/user.rb && \ | |
echo 'Rails.application.routes.draw { User }' > config/routes.rb |
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
# Say you want to look up the attrs of a Stripe Event for logging to your internal database. | |
attrs = begin | |
retriable(Stripe::APIConnectionError, Stripe::APIError, max: 25) do | |
# ... retrieve attrs from the Stripe event here... | |
end | |
rescue Stripe::APIConnectionError, Stripe::APIError | |
# We're inside an SQS queue block | |
throw :skip_delete # we'll just have to wait on this event, come back later | |
rescue Stripe::Error | |
notify $! |
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
-- user_workspaces_v01 | |
-- Pull Organizations and Workspaces affiliated with, | |
-- and also organizations we have projects we are collaborating on | |
-- first version :: ugly and super slow, see updated version next | |
WITH user_workspaces AS ( | |
SELECT a.user_id, | |
o.name | |
FROM user_affiliations a |
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
bundler: bundle exec guard --plugin bundler --no-interactions | |
db: postgres -D /opt/boxen/homebrew/var/postgres | |
integration: bundle exec guard --plugin cucumber --no-interactions | |
mailcatcher: mailcatcher --foreground --verbose | |
redis: redis-server /opt/boxen/homebrew/etc/redis.conf | |
test: bundle exec guard --plugin rspec --no-interactions | |
web: bundle exec guard --plugin unicorn --no-interactions | |
worker: bundle exec sidekiq |
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
@mixin blur($much: 10px) { | |
-webkit-filter: blur($much); | |
// Force hardware acceleration for vastly improved performance | |
-webkit-transform: translate3d(0, 0, 0); | |
} |
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
# Quiz Exercise, Part One | |
# | |
# Quiz for a list of names & birthdays, | |
# then list out their ages | |
# | |
# For example: | |
# | |
# Hey there! Please enter a list of names: | |
# > John, Sam, Bob, Alisha, Henry | |
# |
NewerOlder