Showing posts with label Cheatsheet. Show all posts
Showing posts with label Cheatsheet. Show all posts

Tuesday, August 21, 2012

Rails daily usage cheat sheet


Task Command
Start server rails s
Start console rails c
Generate a db migration to add columns
rails generate migration add_column_to_some_table column_name:string...
  • class AddColumnBankAccountNameToRequests < ActiveRecord::Migration
    def self.up
    add_column :direct_debit_requests, :bank_account_name, :string
    end
    def self.down
    remove_column :direct_debit_requests, :bank_account_name
    end
    end
Generate a db migration to add index
rails generate migration add_index_to_some_table
  • class AddIndexToActionAudits < ActiveRecord::Migration
    def self.up
    add_index :action_audits, [:controller, :action, :action_failed]
    end
    def self.down
    remove_index :action_audits, [:controller, :action, :action_failed]
    end
    end
Generate new model
  • class CreateLoanCharges < ActiveRecord::Migration
    def self.up
    create_table :loan_charges do |t|
    t.references :product
    t.string :listener_reference
    t.integer :fixed_charge
    t.integer :min_charge
    t.integer :max_charge
    t.float :percentage_change
    t.timestamps
    end
    end
    def self.down
    drop_table :loan_charges
    end
    end

Monday, July 9, 2012

Git daily usage cheat sheet


TaskCommand
Initialize a new git repository
git init
View local branchesgit branch
Create new local branchgit branch [new_branch_name]
Delete local branchgit branch -d [branch_name]
Switch to a branchgit checkout [branch_name]
Add files to gitgit add .
Undo all current changes.git checkout .
Commit changesgit commit -a -m "Log message"
Show git logsgit log
Push local to remotegit push origin [branch_name]
Pull from remotegit pull origin [branch_name]
Merge branchgit merge [from_branch]
Show diffgit diff
Show all branchesgit branch -a
Fix a tagged release
git checkout -b [tag_name]_fixes [tag_name]
OR (for getting a remote branch)
git checkout -b [new_local_branch] origin/[remote_branch]

e.g.

git checkout -b myfeature origin/myfeature
Create a new taggit tag [tag_name]
Push tags to remotegit push --tags
Overwrite existing taggit tag -f [tag_name]
Delete tag
git tag -d 12345
git push origin :refs/tags/12345
Merge individual commitsgit cherry-pick [commit_hash]
Stashing
git stash
git stash apply
git stash list
Create an empty repositorygit --bare init
Adding a remote repository
git remote add origin [server_name]:[directory_name]

Checkout a single file on another branch:
$ git checkout branch_name file_full_path

More on: http://gitref.org/index.html

Capistrano cheat sheet


Description Command
List cap details cap -T
backup database cap bullitt db:backup:adhoc
Deployment without migration cap bullitt deploy
Deployment with migrations cap bullitt deploy:migrations