- ruby1.9.3-p327
- rails3.2
- unicorn 4.5
- percona Mysql5.5
- memcache14.14
- redis2.6
33 app servers, 1172 unicorn workers, 5 job servers, 370 job workers
# This is how we use it | |
retry_until_timeout do | |
expect(page).to have_button('Add comment') | |
expect(page).to have_text('Cancell') | |
end | |
def retry_until_timeout(seconds = 10, message: 'Failed with timeout') | |
Timeout.timeout(seconds) do | |
loop do | |
yield |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
// munged from https://github.com/simontime/Resead | |
namespace sead | |
{ | |
class Random | |
{ |
api: sh -c "cd api && bundle exec rails s -p5000" | |
nginx: /usr/bin/nginx -c nginx.conf | |
client: sh -c "cd client && npm start" |
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# README | |
# - gem install git | |
# - Update the ticket prefix | |
# - Update the branch name | |
# - Put this in /usr/local/bin and chmod +x it | |
require 'git' |
tap "caskroom/cask" | |
cask "google-chrome" | |
cask "firefox" | |
brew "chromedriver" | |
brew "geckodriver" |
In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.
A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval
.
You can find instance_eval
used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.
class Article < ActiveRecord::Base
In this article, I'll walk through a basic Rails (3.2.x) setup for creating a nested resource for two models. Nested resources work well when you want to build out URL structure between two related models, and still maintain a RESTful convention. This code assumes you are running RVM to manage Ruby/Gem versions, and Git for version control.
$ mkdir family # create rvm gemset
$ echo "rvm use --create ruby-1.9.2@family" > family/.rvmrc
$ cd family # install rails
$ gem install rails # create new rails project
$ rails new . # version control
class ActiveRecord::Base | |
mattr_accessor :shared_connection | |
@@shared_connection = nil | |
def self.connection | |
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection } | |
end | |
end | |
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection |