Skip to content

Instantly share code, notes, and snippets.

View amolpujari's full-sized avatar
💭
I may be slow to respond.

Amol Pujari amolpujari

💭
I may be slow to respond.
  • Pune
View GitHub Profile
@amolpujari
amolpujari / test_alert.rb
Created August 2, 2012 19:03
adding a new alert to the rails app
class TestAlert < AlertComposer
set_alert :name => 'Test alert',
:description => 'budget reached and get alerts',
:level => 'error', # or 'warning', 'danger' or default => 'info'
:flash => true # default false, to ensure system notification is flashed to get attention
def notify receiver, related_id, extra={}
"this is test system alert :) or return nil to avoid"
end
@amolpujari
amolpujari / main.rb
Created August 13, 2012 02:15
app/channels/
require 'goliath'
require 'active_record'
require 'active_support'
#require 'em-synchrony'
#require 'em-synchrony/em-http'
# The location of the Rails app to integrate
RAILS_APP ||= "#{File.expand_path File.dirname(__FILE__)}/../.."
@amolpujari
amolpujari / gist:3887565
Created October 14, 2012 06:08
override rassoc
class Array
def rassoc obj, place=1
if place
place = place.to_i rescue -1
return if place < 0
end
self.each do |item|
next unless item.respond_to? :include?
@amolpujari
amolpujari / reverse_geocode_example.rb
Created October 18, 2012 06:06
Location model example
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",
@amolpujari
amolpujari / mail_watcher.rb
Created October 29, 2012 17:16
ruby based mail watcher to trigger jenkin jobs passing args
require 'net/imap'
class MailWatcher
Server = 'imap.gmail.com'
Username = ''
Password = ''
Folder = 'INBOX'
PollingInterval = 60
CheckFileLocation = "#{File.dirname(__FILE__)}/../../tmp/checks/"
@amolpujari
amolpujari / handle_redirect_loop_if_appears.rb
Created October 31, 2012 11:17
handle_redirect_loop_if_appears
class ApplicationController < ActionController::Base
...
before_filter :handle_redirect_loop_if_appears
...
after_filter :set_session_back_url
...
def handle_redirect_loop_if_appears
@amolpujari
amolpujari / csv_reports.rb
Created December 19, 2012 08:51
quick write csv files CSVReports::Base.new objects, columns=[ :attr1, :attr2]
require 'csv'
module CSVReports
class Base
attr_accessor :columns, :column_separator, :row_separator
def initialize items, columns=[]
@items = items
self.columns = columns
Food
1405 - Amol/Renuka
184 - Omkar/Shruti
0 - Yogesh/Radhika
490 - Pushkar/Tejal
___________________
2079 that means 520 per couple
require 'active_support/core_ext'
class PricingCalc
attr_reader :bill, :usage
def initialize entire_usage
@bill = 0
@usage = 0
@entire_usage = entire_usage
end
@amolpujari
amolpujari / dashboard.rb
Last active March 24, 2021 11:36
activeadmin dashboard with table rows count graph
ActiveAdmin.register_page "Dashboard" do
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
content :title => proc{ I18n.t("active_admin.dashboard") } do
# div :class => "blank_slate_container", :id => "dashboard_default_message" do
# span :class => "blank_slate" do
# span "Welcome to Active Admin. This is the default dashboard page."
# small "To add dashboard sections, checkout 'app/admin/dashboards.rb'"
# end