Skip to content

Instantly share code, notes, and snippets.

@bf4
bf4 / all_aws_lambda_modules.txt
Created December 15, 2016 16:09 — forked from gene1wood/all_aws_lambda_modules_python.md
AWS Lambda function to list all available Python modules and post the list to Pastebin
# module list (generated by listmodules.py)
#
# 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'
#
BaseHTTPServer
Bastion
CDROM
@bf4
bf4 / bash_trap_template.sh
Created November 1, 2016 15:01 — forked from sechiro/bash_trap_template.sh
Bash signal trap template. Bashでよく使うシグナルトラップのテンプレート。
#!/bin/bash
set -u # Check unset variables only
#set -ue # Check unset variables. Exit on error
LANG=C
# Trap signals
trap_HUP() {
echo "Trap HUP signal."
exit 1
}
@bf4
bf4 / everytimezone.coffee
Created October 31, 2016 00:42 — forked from madrobby/everytimezone.coffee
First conversion of http://everytimezone.com/ 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
bf4 / post.md
Created September 7, 2016 22:16 — forked from fxn/post.md
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
bf4 / registrations_controller.rb
Created July 13, 2016 21:31 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@bf4
bf4 / spec_features_samplefeature.rb
Created July 6, 2016 19:41 — 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.
require 'spec_helper'
feature "Login" do
scenario "remembered user" do
password = "12345678"
user = create(:user, password: password)
access_protected_page_should_ask_to_login
current_path.should eq login_path
@bf4
bf4 / summary.md
Created June 16, 2016 21:45 — forked from steveklabnik/summary.md
my summary of "using Rust with Ruby: a deep dive with Yehuda Katz"

My summary of https://www.youtube.com/watch?v=IqrwPVtSHZI

TL;DR:

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: https://github.com/rails/rails/blob/b3eac823006eb6a346f88793aabef28a6d4f928c/activesupport/lib/active_support/core_ext/object/blank.rb#L99-L117

It's pretty slow. So Discourse (which you may know from {users,internals}.rust-lang.org) uses the fast_blank gem, which provides this method via a C implementation instead. It looks like this: https://github.com/SamSaffron/fast_blank/blob/master/ext/fast_blank/fast_blank.c

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

@bf4
bf4 / irb3.rb
Created May 16, 2016 22:50 — forked from peterc/irb3.rb
irb3 - Run an IRB-esque prompt over multiple Ruby implementations at once using RVM
#!/usr/bin/env ruby
# encoding: utf-8
# irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple
# versions of Ruby at once (using RVM)
#
# By Peter Cooper, BSD licensed
#
# Main dependency is term-ansicolor for each impl:
# rvm exec gem install term-ansicolor
for f
do
# Change this value to increase maximum size
GIF_MAX_SIZE=480
dir="$(dirname "$f")"
name="$(basename "$f")"
cd "$dir"
@bf4
bf4 / 20160307172445_change_paperclip_attachment_path.rb
Created April 29, 2016 03:38 — forked from 121onto/20160307172445_change_paperclip_attachment_path.rb
Example migration for changing paperclip storage path
class MoveAttachmentsToNewLocation < ActiveRecord::Migration
def initialize(name = self.class.name, version = nil)
access_key = Rails.application.secrets.g3_access_key_id
secret_key = Rails.application.secrets.g3_secret_access_key
storage = Fog::Storage::Google.new google_storage_access_key_id: access_key,
google_storage_secret_access_key: secret_key
@bucket_name = Rails.application.secrets.g3_bucket
@bucket = storage.directories.get(@bucket_name)
super(name, version)