Skip to content

Instantly share code, notes, and snippets.

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
class GameOfLife
attr_accessor :state, :height, :width, :rules
def initialize options={}
self.rules = options[:rules] || [ [0,0,0,1,0,0,0,0,0], [0,0,1,1,0,0,0,0,0] ]
self.height = options[:size] || options[:height] || 10
self.width = options[:size] || options[:width] || 10
self.state = options[:seed] || grid { rand(2) }
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@dnagir
dnagir / ScottishRubyConf2010-notes.txt
Created May 18, 2011 13:49
The things I learned from Scottish RubyConf 2010
Harmony for browser testing
Capybara.driver = :rack_test # uses Harmony and can run JS
Good talk about Arel: 1LT_04-mp4_500mbs.mp4
Rack GeoIP.
Rack GoogleAnalytics
Rack::Cache (standard)
Rack::CacheBuster
@dnagir
dnagir / deploy.rb
Created May 18, 2011 14:55
Flexible Rails deployment with Capistrano and Nginx
set :domain, ENV["domain"]
set :application, domain
set :user, ENV["user"]
set :destination, ENV["destination"] || domain
set :web_conf, ENV["web_conf"] || ENV["environment"] || 'production'
raise "please set domain=app.domain.name.com" unless domain
raise "please set user=server_username" unless user
set :port, ENV["port"] || 1234
set :repository, "."
@dnagir
dnagir / gist:996813
Created May 28, 2011 11:52
incompatible character encodings: UTF-8 and ASCII-8BIT
dima@me:~$ rvm gemset create rc1
'rc1' gemset created (/home/dima/.rvm/gems/ruby-1.9.2-p180@rc1).
dima@me:~$ rvm gemset use rc1
Now using gemset 'rc1'
dima@me:~$ gem update --system
Latest version currently installed. Aborting.
dima@me:~$ gem install rails --pre
@dnagir
dnagir / application.js
Created August 19, 2011 09:12
HAML example with pakunok gem
// app/assets/javascripts/application.js
// Include the template into the app
//= require_tree backbone/templates
// And here's how you do the templating
var html = JST.comment(commentModel.attributes);
$(".comments").append(html);
Users
should save record when losing focus from input
Expected spy updateFromForm to have been called.
Error: Expected spy updateFromForm to have been called.
@dnagir
dnagir / posts_controller.rb
Created October 26, 2011 05:16
CanCan optional load_and_authorize_resource
class PostsController < InheritedResources::Base
belongs_to :blog, :optional => true # The controller can be nested (/blog/1/posts) or flat (/posts)
# How do make load_and_authorize_resource accept optional :blog?
load_and_authorize_resource :blog
load_and_authorize_resource :post, :through => :blog
end
@dnagir
dnagir / content_switcher.js.coffee
Created October 30, 2011 23:34
Spine.js is not only for CRUD, it is also for TDD with JavaScript
href2selector = (href) -> href.match(/(#.+)/)[1]
class App.ContentSwitcher extends Spine.Controller
elements:
'li': 'items'
events:
'click li a': 'clickLink'
constructor: ->
super