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' | |
count = 1_000_000 | |
Benchmark.benchmark do |bm| | |
bm.report("concat") { count.times { 11.to_s + '/' + 12.to_s } } | |
bm.report("interp") { count.times { "#{11}/#{12}" } } | |
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
# Logging some action in the console or log file | |
# Prevents lots of references to a variable | |
# Maybe not the best example, but potentially cleaner than the alternative | |
class ApplicationController | |
after_filter :log_action_without_tap | |
after_filter :log_action_with_tap | |
private | |
def log_action_with_tap | |
"[ACTION LOG]: #{current_account.name} tried to #{action_name} #{controller_path}".tap{|l| | |
l << flash.map{|k,v| "#{k}: #{v}"}.join(',') if flash.any? |
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 AccountDecorator | |
attr_accessor :account | |
def initialize(account) | |
@account = account | |
end | |
def method_missing(method_name, *args, &blk) | |
if account.respond_to?(method_name) | |
account_method_result(method_name, *args, &blk) |
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 | |
require 'optparse' | |
require 'ostruct' | |
require 'pathname' | |
class Text | |
attr_reader :string |
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_relative './example_logger' | |
class ExampleClass | |
def initialize | |
ExampleLogger.info("Initializing ExampleClass") | |
end | |
end | |
ExampleClass.new |
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
// My first Rust program | |
// Simply outputs fibbonaci numbers from 20 to 0 | |
use core::task::spawn; | |
fn fib(number: int) -> int { | |
if number > 1 { | |
return fib(number - 1) + fib(number - 2); | |
} else { | |
return number; |
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' | |
ITERATIONS = 10_000 | |
Benchmark.bm do |bm| | |
bm.report("#<< -> #flatten!: ") do | |
array = [1,2,3] | |
ITERATIONS.times do | |
array << [4,5,6] | |
array.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
#!/bin/sh | |
# | |
# Script built from the reference at | |
# http://digitalsanctum.com/2009/10/01/installing-erlang-on-mac-os-x/ | |
sudo -v | |
wget http://www.erlang.org/download/otp_src_R16B01.tar.gz | |
tar -xzf otp_src_R16B01.tar.gz |
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 | |
sudo apt-get -y update | |
sudo add-apt-repository ppa:nginx/stable | |
sudo apt-get -y update | |
sudo apt-get install -y git-core postgresql-9.1 mysql-server libpq-dev \ | |
curl build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev | |
cd /tmp |
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 Book < Airrecord::Table | |
class Endorser < Airrecord::Table | |
self.base_key = "" | |
self.table_name = "Endorser" | |
end | |
self.base_key = "" | |
self.table_name = "Books" | |
has_many :endorsements, class: 'Book::Endorser', column: 'Endorsements' |