This file contains 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
Loading development environment (Rails 3.2.3) | |
1.9.3p194 :001 > l = Location.new 'San Francisco' | |
=> #<Location id: nil, locatable_id: nil, locatable_type: nil, ip: nil, country: "US", state: "California", state_abbreviation: "CA", county: nil, city: "San Francisco", street: nil, address: "San Francisco", zip: "94103", lat: #<BigDecimal:6ea81b0,'0.37775002E2',18(45)>, lng: #<BigDecimal:6ea7f58,'-0.122418297E3',18(45)>, walkscore: nil, transit_score: nil, avg_school_rating: nil, created_at: nil, updated_at: nil> | |
1.9.3p194 :002 > ap l | |
#<Location:0x00000006b82e18> { | |
:id => nil, | |
:locatable_id => nil, | |
:locatable_type => nil, | |
:ip => nil, | |
:country => "US", |
This file contains 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
require 'net/imap' | |
class MailWatcher | |
Server = 'imap.gmail.com' | |
Username = '' | |
Password = '' | |
Folder = 'INBOX' | |
PollingInterval = 60 | |
CheckFileLocation = "#{File.dirname(__FILE__)}/../../tmp/checks/" |
This file contains 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 ApplicationController < ActionController::Base | |
... | |
before_filter :handle_redirect_loop_if_appears | |
... | |
after_filter :set_session_back_url | |
... | |
def handle_redirect_loop_if_appears |
This file contains 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
require 'csv' | |
module CSVReports | |
class Base | |
attr_accessor :columns, :column_separator, :row_separator | |
def initialize items, columns=[] | |
@items = items | |
self.columns = columns |
This file contains 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
Food | |
1405 - Amol/Renuka | |
184 - Omkar/Shruti | |
0 - Yogesh/Radhika | |
490 - Pushkar/Tejal | |
___________________ | |
2079 that means 520 per couple | |
This file contains 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
require 'active_support/core_ext' | |
class PricingCalc | |
attr_reader :bill, :usage | |
def initialize entire_usage | |
@bill = 0 | |
@usage = 0 | |
@entire_usage = entire_usage | |
end |
This file contains 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/bash | |
while : | |
do | |
clear | |
git --no-pager log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --all | |
sleep 1 | |
done |
This file contains 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
# config/initializers/concerns.rb | |
class << ActiveRecord::Base | |
def concerned_with(*concerns) | |
concerns.each do |concern| | |
require_dependency "#{name.underscore}/#{concern}" | |
klass = concern.to_s.classify.constantize rescue nil | |
send(:include, klass) if klass.is_a? Module | |
end | |
end | |
end |
This file contains 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
# config/initializers/config.rb | |
APP_CONFIG = YAML.load_file("#{Rails.root.to_s}/config/config.yml")[Rails.env] | |
def APP_CONFIG.[](key) | |
key = key.to_s | |
if Rails.env=='production' || Rails.env == 'staging' | |
p "APP_CONFIG['#{key}'] not defined." unless self.has_key? key | |
else | |
raise "APP_CONFIG['#{key}'] not defined." unless self.has_key? key |
This file contains 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
#test.rb | |
def mem_usage | |
`ps -o rss= -p #{Process.pid}`.to_i | |
end | |
def random_str(length=1) | |
(Object.new.hash.to_s << Object.new.hash.to_s)[0..(length-1)].to_s | |
end | |
class A |