Skip to content

Instantly share code, notes, and snippets.

@beaugaines
beaugaines / cat.rb
Last active August 29, 2015 14:25 — forked from spraints/cat.rb
require 'benchmark'
puts "#{RUBY_ENGINE rescue ''} #{RUBY_ENGINE == 'jruby' ? JRUBY_VERSION : RUBY_VERSION}"
def a ; "abc"*100 ; end
def b ; "def"*100 ; end
n = 1000000
Benchmark.bm(12) do |x|
x.report('"#{a}#{b}"') { n.times { "#{a}#{b}" } }
x.report('"" + a + b') { n.times { "" + a + b } }
x.report('"" << a << b') { n.times { "" << a << b } }
end

true and false vs. "truthy" and "falsey" (or "falsy") in Ruby, Python, and JavaScript

Many programming languages, including Ruby, have native boolean (true and false) data types. In Ruby they're called true and false. In Python, for example, they're written as True and False. But oftentimes we want to use a non-boolean value (integers, strings, arrays, etc.) in a boolean context (if statement, &&, ||, etc.).

This outlines how this works in Ruby, with some basic examples from Python and JavaScript, too. The idea is much more general than any of these specific languages, though. It's really a question of how the people designing a programming language wants booleans and conditionals to work.

If you want to use or share this material, please see the license file, below.

Update

class AddHstoreExtension < ActiveRecord::Migration
def up
execute 'CREATE EXTENSION hstore'
end
def down
execute 'DROP EXTENSION hstore'
end
end

This re-styles your sublime text 2 sidebar to be darker, so it doesn't blind you when using a dark theme.

Dark sublime text 2 sidebar

Save the Default.sublime-theme file into packages/Theme - Default, make a backup of your original if you want to be able to go back easily.

gem 'pg'
group :development do
gem 'ruby-debug'
end
gem 'rake', '~> 0.8.7'
gem 'devise'
gem 'oa-oauth', :require => 'omniauth/oauth'
gem 'omniauth'
gem 'haml'
gem 'dynamic_form'