Skip to content

Instantly share code, notes, and snippets.

bf4 / all_aws_lambda_modules.txt
Created Dec 15, 2016 — forked from gene1wood/
AWS Lambda function to list all available Python modules and post the list to Pastebin
View all_aws_lambda_modules.txt
# module list (generated by
# timestamp='20160226T200954Z'
# sys.version='2.7.10 (default, Dec 8 2015, 18:25:23) \n[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]'
# sys.platform='linux2'
# platform='Linux-4.1.13-19.31.amzn1.x86_64-x86_64-with-glibc2.2.5'
bf4 /
Created Nov 1, 2016 — forked from sechiro/
Bash signal trap template. Bashでよく使うシグナルトラップのテンプレート。
set -u # Check unset variables only
#set -ue # Check unset variables. Exit on error
# Trap signals
trap_HUP() {
echo "Trap HUP signal."
exit 1
bf4 /
Created Oct 31, 2016 — forked from madrobby/
First conversion of JavaScript code to CoffeeScript
# Two things are important to note:
# 1) The code is fugly, because it was a JavaScript/iPad experiment.
# I know that it is ugly, so pretty please don't comment on that part.
# 2) I tried to use as many CoffeeScript features as possible,
# including but not limited to list comprehensions,
# heredocs, destructuring assignment and also the "do" operator
# I welcome comments about stuff that is not CoffeeScripty enough, or what I should
# write differently.
bf4 /
Created Sep 7, 2016 — forked from fxn/
GeoPlanet data with ancestor chain cache imported in 10 minutes

GeoPlanet data with ancestor chain cache imported in 10 minutes

Yahoo! provides its GeoPlanet data as three separate TSV files, available for download here.

That's a database with some 17 million records:

  • 5.7 million records: locations (aka places).
  • 2.2 million records: alternative names for each place (aka aliases).
  • 9.6 million records: matrix of neighbourhoods per place (aka adjacencies).
bf4 / registrations_controller.rb
Created Jul 13, 2016 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
View registrations_controller.rb
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user =[:user])
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>, :status=>201
bf4 / spec_features_samplefeature.rb
Created Jul 6, 2016 — forked from andreypronin/spec_features_samplefeature.rb
A little spec library I use to test session/persistent cookies behavior in Rails apps with Capybara. Plus, example on how I use it. Implemented for Rack::Test and Poltergeist (PhantomJS) drivers only, as these are my default test preferences.
View spec_features_samplefeature.rb
require 'spec_helper'
feature "Login" do
scenario "remembered user" do
password = "12345678"
user = create(:user, password: password)
current_path.should eq login_path
bf4 /
Created Jun 16, 2016 — forked from steveklabnik/
my summary of "using Rust with Ruby: a deep dive with Yehuda Katz"

My summary of


Rails has a library, ActiveSupport, which adds methods to Ruby core classes. One of those methods is String#blank?, which returns a boolean (sometimes I miss this convention in Rust, the ?) if the whole string is whitespace or not. It looks like this:

It's pretty slow. So Discourse (which you may know from {users,internals} uses the fast_blank gem, which provides this method via a C implementation instead. It looks like this:

For fun, Yehuda tried to re-write fast_blank in Rust. Which looks like this:

bf4 / bm_throw_raise.rb
Created Jun 14, 2016
Ruby raise/rescue vs. throw/catch. tl;dr throw/catch is much faster
View bm_throw_raise.rb
require 'benchmark/ips'
Benchmark.ips do |x| do
raise ArgumentError
rescue ArgumentError
bf4 / fix_n_plus_one_queries_on_accepts_nested_attributes.rb
Created Jun 10, 2016
Rails 4.2.6 patch for autosave and accepts_nested_attributes_for from issuing N+1 queries on each eager loaded association
View fix_n_plus_one_queries_on_accepts_nested_attributes.rb
# We noticed that adding `accepts_nested_attributes_for :comments, allow_destroy: true`
# caused extra queries to be run when serializing comments in a post
# and including the post name in each comment resource object (this is JSON API, names changed):
# blog_id = params.permit(:id)[:id]
# Blog = Blog.where(id: blog_id).includes(posts: [:comments]).first
# comments = blog.posts.flat_map(&:comments)
# comment_fields = {comments: [:id, :title, :body, :post], posts: [:name]}
# comment_includes = [:post]
View rails_rendering_stack.txt
#<Class:ActionController::Parameters>#always_permitted_parameters=:126 ([[:req, :obj]])
ActionDispatch::Http::ParameterFilter#initialize:6 ([[:opt, :filters]])
ActionDispatch::Http::ParameterFilter#initialize:6 ([[:opt, :filters]])
ActiveSupport::Callbacks::ClassMethods#normalize_callback_params:594 ([[:req, :filters], [:req, :block]])
ActiveSupport::Callbacks::ClassMethods#normalize_callback_params:594 ([[:req, :filters], [:req, :block]])
ActiveSupport::Callbacks::ClassMethods#normalize_callback_params:594 ([[:req, :filters], [:req, :block]])
#<Class:ActiveModelSerializers::SerializableResource>#_render_callbacks=:83 ([[:req, :val]])
ActiveModelSerializers::Logging::ClassMethods#instrument_rendering:18 ([])
ActiveModelSerializers::Callbacks::ClassMethods#around_render:50 ([[:rest, :filters], [:block, :blk]])
ActiveSupport::Callbacks::ClassMethods#normalize_callback_params:594 ([[:req, :filters], [:req, :block]])