Skip to content

Instantly share code, notes, and snippets.

View vijaydev's full-sized avatar

Vijay Dev vijaydev

  • India
  • 09:18 (UTC +05:30)
View GitHub Profile
desc "Make sure there is something to deploy"
task :check_revision, :roles => :web do
unless `git rev-parse HEAD` == `git rev-parse origin/production`
puts "WARNING: HEAD is not the same as origin/production"
puts "Run `git push` to sync changes."
exit
end
end
Rails.logger.info self.weightage.to_f
Rails.logger.info self.weightage.to_f/100.0
self.weightage = self.weightage.to_f/100.0
Rails.logger.info self.weightage
11.0
0.11
0
require 'graphviz'
def each_model
ObjectSpace.each_object(Class) do |klass|
yield klass if klass.ancestors.include?(ActiveRecord::Base) && klass != ActiveRecord::Base
end
end
graph_viz = GraphViz::new('Gemfile', {:concentrate => true, :normalize => true, :nodesep => 0.55})
graph_viz.edge[:fontname] = graph_viz.node[:fontname] = 'Arial, Helvetica, SansSerif'
*Gist.vim* Vimscript for creating gists (http://gist.github.com)
Usage |gist-vim-usage|
Tips |gist-vim-tips|
Requirements |gist-vim-requirements|
License |gist-vim-license|
Install |gist-vim-install|
This is a vimscript for creating gists (http://gist.github.com)
railsrc_path = File.expand_path('~/.railsrc')
if ( ENV['RAILS_ENV'] || defined? Rails ) && File.exist?( railsrc_path )
begin
load railsrc_path
rescue Exception
warn "Could not load: #{ railsrc_path }" # because of $!.message
end
end
imap <silent> <C-K> <% %><Esc>2hi
imap <silent> <C-L> <%= %><Esc>2hi
@vijaydev
vijaydev / gist:1472145
Created December 13, 2011 13:35
Rails 3.2.0 Changelogs

The latest release notes is available at http://edgeguides.rubyonrails.org/3_2_release_notes.html

Railties 3.2.0 (unreleased)

  • Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting config.reload_classes_only_on_change to false. José Valim

  • New applications get a flag config.active_record.auto_explain_threshold_in_seconds in the environments configuration files. With a value of 0.5 in development.rb, and commented out in production.rb. No mention in test.rb. fxn

  • Add DebugExceptions middleware which contains features extracted from ShowExceptions middleware José Valim

def visit_Arel_Nodes_SelectStatement o
puts caller
[
(visit(o.with) if o.with),
o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
(visit(o.limit) if o.limit),
(visit(o.offset) if o.offset),
(visit(o.lock) if o.lock),
].compact.join ' '
require 'benchmark'
def time(times = 1)
unless block_given?
puts "No block provided"
return
end
ret = nil
Benchmark.bm do |x|
x.report { times.times { ret = yield } }
@vijaydev
vijaydev / gist:2170020
Created March 23, 2012 11:59 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide

A Capistrano Rails Guide

by Jonathan Rochkind, http://bibwild.wordpress.com

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".