Skip to content

Instantly share code, notes, and snippets.

View vladvinnikov's full-sized avatar

Vladimir Vinnikov vladvinnikov

View GitHub Profile
@Ball
Ball / bind_example.rb
Created August 22, 2009 16:07
Binding Example
require 'xamltools.rb'
require 'PresentationFramework'
class ViewModel
attr :greeting, true
def initialize(greet)
@greeting = greet
end
end
@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")
@andruby
andruby / deploy.rb
Created January 26, 2011 19:48
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@guilleiguaran
guilleiguaran / spec_helper.rb
Created February 21, 2011 00:43
My spec_helper for Spork with Rails3, RSpec2, Devise, FactoryGirl
require 'spork'
ENV["RAILS_ENV"] = 'test'
Spork.prefork do
require "rails/application"
Spork.trap_method(Rails::Application, :reload_routes!)
require File.expand_path("../../config/environment", __FILE__)
@guilleiguaran
guilleiguaran / acceptance_helper.rb
Created February 28, 2011 20:41
RSpec+Capybara acceptance test example
# acceptance/acceptance_helper.rb
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
# Put your acceptance spec helpers inside /spec/acceptance/support
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
require File.expand_path(File.dirname(__FILE__) + '/request_helper')
feature "Show User Photos Feature", %q{
In order to vote in friends photos
As an User
I want to see the photos of my friends
} do
background do
stub_facebook_profile
@slayer
slayer / gist:935641
Created April 21, 2011 22:46
SQL JOIN via AREL in Rails 3
# Simple JOIN
User.joins(:account) # User -> Account
# Will produce
# SELECT `users`.* FROM `users` INNER JOIN `accounts` ON `accounts`.`user_id` = `users`.`id`
# Complicated JOIN
Trait.joins(:user => :account) # Trait -> User -> Account
# Will produce
# SELECT `traits`.* FROM `traits` INNER JOIN `users` ON `users`.`id` = `traits`.`user_id` INNER JOIN `accounts` ON `accounts`.`user_id` = `users`.`id`
@niquola
niquola / rails31init.md
Created May 24, 2011 21:11 — forked from jraines/rails31init.md
Rails 3.1 with Rspec, Cucumber, Factory Girl, Haml, Devise, and Simple Form

Install Rails 3.1 RC

gem install rails --pre

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

@shokai
shokai / mount_ramdisk
Created August 5, 2011 06:48
mount ramdisk on Mac OSX
#!/usr/bin/env ruby
mount = '/Volumes/ramdisk'
newfs = '/dev/disk1'
if !ARGV.empty? and ARGV.first =~ /^-+u$/i
system "umount #{mount} && hdiutil detach #{newfs}"
else
if File.exists? newfs
STDERR.puts "already mounted - #{mount}"
STDERR.puts "use \"#{$0.split('/').last} -u\""