This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Signup::CustomersController < ApplicationController | |
| inherit_resources | |
| defaults :resource_class => User, :collection_name => 'users', :instance_name => 'user' | |
| actions :new, :create | |
| def create | |
| create! do |success, failure| | |
| success.html do | |
| resource.roles |= [Role.find_by_name('customer')] | |
| flash[:notice] = "Customer #{resource.name} successfuly registered" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source :gemcutter | |
| gem 'rails', '3.0.0' | |
| gem 'sqlite3-ruby', :require => 'sqlite3' | |
| gem 'haml' | |
| gem 'inherited_resources' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module InheritedResources | |
| module DefaultActions | |
| def self.included(base) | |
| base.send :extend, ClassMethods | |
| end | |
| module ClassMethods | |
| def default_actions(*actions_to_keep) | |
| options = actions_to_keep.extract_options! | |
| actions_to_keep.map!(&:to_sym).uniq! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ==begin | |
| def self.options_for_select(story) | |
| options = [] | |
| options << ["",""] if story.story_type_id.nil? | |
| all.map{|story_type| options<<[story_type.title,story_type.id]} | |
| options | |
| end | |
| ==end | |
| irb(main):021:0> [1,2,5].inject( true ? [nil] : [] ){|a, b| a + [b, 1]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pg = require("pg"); | |
| pg.connect('pg://postgres:password@localhost:5432/postgres', function(err, client) { | |
| if (err) { console.log(err) ; } else { | |
| client.query("select tablename from pg_tables;", function(err, result) { | |
| if (err) {console.log(err)} else | |
| { for (var i=0; i < result.rows.length; i++) { console.log(result.rows[i].tablename) } | |
| } | |
| }); | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Then in your features you'll only need to call the `login_as` or `logout` | |
| # methods. More info here: http://wiki.github.com/hassox/warden/testing | |
| feature "Home page" do | |
| background do | |
| @user = User.create(...) # Or use fixtures, factories or whatever, even a | |
| # stub user | |
| login_as @user | |
| visit home_page |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| git-timesheet | |
| #!/usr/bin/env ruby | |
| email = `git config --get user.email` | |
| history = `git log --date=iso --since="1 week ago" --format="%ad %s" --no-merges --simplify-merges --reverse --committer=#{email}` | |
| history.split(/\n/).group_by { |event| event[0,10] }.sort.reverse.each do |date, commits| | |
| puts "#{date}\n#{"=" * 10 }"; puts commits.map { |commit| commit[10, 1024] }.sort; puts | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cap web:deploy:desable & cap web:deploy:enable | |
| server { | |
| ... | |
| if (-f $document_root/system/maintenance.html) { set $maintenance 1; } | |
| if ($request_uri ~* (jpg|jpeg|gif|js|css)$) { set $maintenance 0; } | |
| if ($maintenance) { rewrite ^(.*)$ /system/maintenance.html; break; } | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/sh | |
| ### BEGIN INIT INFO | |
| # Provides: nginx | |
| # Required-Start: $all | |
| # Required-Stop: $all | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: starts the nginx web server | |
| # Description: starts nginx using start-stop-daemon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Rails 3.x | |
| snippet vale | |
| validate ${1:method_name} | |
| snippet vals | |
| validates ${1:column} | |
| snippet valsp | |
| validates ${1:column}, :presence => ${$1:true} | |
| # RSpec 2.x | |
| snippet desc |