$ rails g model User
belongs_to
has_one
#!/usr/bin/env ruby -w | |
require "benchmark" | |
TIMES = 100_000 | |
ARRAY = (1..1_000).to_a | |
Benchmark.bm(30) do |b| | |
b.report "each" do | |
TIMES.times do |i| | |
ARRAY.each do |element| |
/** Use with a default value, for example: | |
* runningScalaVersion getOrElse "2.8.0" | |
*/ | |
lazy val runningScalaVersion = { | |
val matcher = """version (\d+\.\d+\.\d+).*""".r | |
util.Properties.versionString match { | |
case matcher(versionString) => Some(versionString) | |
case _ => None | |
} | |
} |
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
http://guides.rubyonrails.org/migrations.html
// ==UserScript== | |
// @match https://yourwebsite.com/xyz | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js | |
// @require http://cdnjs.cloudflare.com/ajax/libs/sugar/1.3/sugar.min.js | |
// ==/UserScript== | |
alert('Hello, I got jQuery included and sugarJs too'); | |
var runEverySecond = function(){ | |
$('p').find('img').attr('width', '0px'); |
#!/bin/sh | |
set -e | |
# Feel free to change any of the following variables for your app: | |
TIMEOUT=${TIMEOUT-60} | |
APP_ROOT=/home/you/apps/app_name/current | |
PID=$APP_ROOT/tmp/pids/unicorn.pid | |
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production" | |
AS_USER=andy | |
set -u |
namespace :deploy do | |
namespace :assets do | |
task :precompile, :roles => :web, :except => { :no_release => true } do | |
begin | |
from = source.next_revision(current_revision) # <-- Fail here at first-time deploy | |
rescue | |
err_no = true | |
end | |
if err_no || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0 | |
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile} |
// With an enumeration like... | |
// object Color extends Enumeration{...} | |
// Create a format (or reads or writes) like this: | |
// val fmt = EnumJson.enumFormat(Color); | |
// The implementation | |
object EnumJson { | |
def enumReads[E <: Enumeration](enum: E): Reads[E#Value] = new Reads[E#Value] { |
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.before(:each) do | |
DatabaseCleaner.strategy = :transaction | |
end | |
config.before(:each, js: true) do |