Skip to content

Instantly share code, notes, and snippets.

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
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".

class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
git remote prune origin - to remove a deleted remote branch.
git rebase -i - interactive rebase with options to pick, squash, discard and reorder commits.
git update-index --assume-unchanged
Undoing a merge:
$ git pull $REMOTE $BRANCH
# uh oh, that wasn't right
$ git reset --hard ORIG_HEAD
# all is right with the world