Skip to content

Instantly share code, notes, and snippets.

View rishav's full-sized avatar

Rishav Rastogi rishav

View GitHub Profile
# Instance variables in models
# recently i came across code where a friend of mine had written a lot code in models like its below ( without any attr_reader or accessor ) , is this ok or just plain useless,
def coordinates
@coordinates = [latitude, longitude]
end
# should we do something like below make more sense
def coordinates
- No methods more than 10 lines
- Use database migrations
- after committing a db migration, don't change it. Just add Another migration
- Thin Controllers, Avoid sharing more than one or two instance variables b/w controllers and views
- use REST at all times
- Use one type of http request per action, do not use "request.post?" type methods.
- Avoid using comments. If unclear, Refactor.
- use "h" in views, to escape everything
- do not use abbreviations for variable names
- follow naming conventions don't use variable names like photoalbum use photo_album instead
@rishav
rishav / omniauth.rb
Created November 15, 2010 15:21 — forked from madhums/omniauth.rb
require 'openid/store/filesystem'
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
provider :twitter, 'key', 'secret'
provider :facebook, 'app_id', 'secret'
provider :linked_in, 'key', 'secret'
provider :open_id, OpenID::Store::Filesystem.new('/tmp')
end
# you will be able to access the above providers by the following url
# /auth/providername for example /auth/twitter /auth/facebook
namespace :deploy do
task :fast do
run "cd #{current_path} && git pull origin #{branch} && touch #{current_path}/tmp/restart.txt; true"
end
end
$ git clone github:lenary/guides.git
Cloning into guides...
remote: Counting objects: 255, done.
remote: Compressing objects: 100% (216/216), done.
remote: Total 255 (delta 111), reused 163 (delta 35)
Receiving objects: 100% (255/255), 1.49 MiB | 564 KiB/s, done.
Resolving deltas: 100% (111/111), done.
$ cd guides
$ git remote -v
NOTE: Gem.latest_load_paths is deprecated with no replacement. It will be removed on or after 2011-10-01.
Gem.latest_load_paths called from /Users/macpro/.rvm/gems/ruby-1.9.2-p180@veggie/gems/spork-0.8.5/lib/spork.rb:112.
NOTE: Gem.all_partials is deprecated with no replacement. It will be removed on or after 2011-10-01.
Gem.all_partials called from /Users/macpro/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:598.
NOTE: Gem.all_partials is deprecated with no replacement. It will be removed on or after 2011-10-01.
Gem.all_partials called from /Users/macpro/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:598.
class AbstractModel < ActiveRecord::Base
self.abstract_class = true
end
class Foo < AbstractModel
end
class Bar < AbstractModel
end
>> ActiveSupport::SecureRandom.base64(10)
=> "Fa8ILYFgMA12LA=="
>> ActiveSupport::SecureRandom.hex(6)
=> "82c82a15110a"
>> ActiveSupport::SecureRandom.random_bytes(16)
=> "u[\205\326\2654\301;'\340\372\2539r\035\313"
>> ActiveSupport::SecureRandom.random_number(5)
=> 0
@rishav
rishav / gist:1500517
Created December 20, 2011 06:18
Vim : Delete commands
dgg : will delete to the beginning of the file.
d$ : will delete from the current position to the end of the current line.
dG : will delete to the end of the file.
d0 : will delete to the beginning of the file
dw: will delete a word
'user'=>array(
//
//
'identityCookie' => array('domain' => '.domain.com'),
//
),
'session' => array(
'autoStart'=>true,
'cookieParams' => array('domain' => '.domain.com'),
...