Skip to content

Instantly share code, notes, and snippets.

View shreyas-satish's full-sized avatar

Shreyas Satish shreyas-satish

View GitHub Profile
@shreyas-satish
shreyas-satish / gist:930765
Created April 20, 2011 08:52
multiple maps on one page
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Resize a Marker</title>
<link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css" />
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map, layer;
@shreyas-satish
shreyas-satish / gist:948141
Created April 29, 2011 10:10
Not able to access instance variable in mailer view
# I'm not able to access the instance variable in my mailer view. I tried naming the instance variables as @xyz, @body_content but nothing worked
# broadcast_email.rb
class BroadcastEmail < ActionMailer::Base
default :from => "[email protected]"
def send_message(message)
@message = "some dummy text"
mail(:to => "[email protected]", :subject => "this is a subject")
end
@shreyas-satish
shreyas-satish / gist:1058535
Created July 1, 2011 13:23
jQuery event fire when all boxes are checked
I have a table. 1st column is a column for checkboxes and 2nd column is normal data.
When I check a check a single box I get an alert due to the following function which is as expected.
//To catch events when check boxes are checked.
$('input:checkbox').live('change', function() {
alert("Checked!");
});
But when I check all checkboxes using the command below, I don't get the alert from the function above.
@shreyas-satish
shreyas-satish / gist:1063015
Created July 4, 2011 07:40
No Method Error while using modules in Rails Controllers
#lib/time_filter.rb
module TimeFilter
def today
where("created_at >= ?", Date.today)
end
end
# In Rails Console
>> include TimeFilter
@shreyas-satish
shreyas-satish / gist:1089960
Created July 18, 2011 16:07
The send method - Ruby metaprogramming
Consider a simple blogging app on Rails. Lets say, I have a list of articles, and I'd like to filter them by today's articles and this week's articles.
I'd like to define two methods in the model that does the actual filtering.
class Article < ActiveRecord::Base
def self.this_week
Article.where("created_at > ?", Date.today.beginning_of_week)
end
def self.today
@shreyas-satish
shreyas-satish / setup_load_paths.rb
Created August 1, 2011 11:52
Load Path Setup for Passenger integration with RVM
#This file should be config/setup_load_paths.rb
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
@shreyas-satish
shreyas-satish / assets.rake
Created August 18, 2011 10:58 — forked from scottwb/assets.rake
Rake task to rebuild all JS/CSS assets with Compass/Jammit, including workaround for the bugs within.
namespace :assets do
task :rebuild do
# Config the base names of all the jammit CSS packages you have defined
# in assets.yml. Could probably parse assets.yml to get this if
# we wanted to.
packages = ['common']
# This is because on OS X, you have to put an explicit empty string to the
# required extension argument with the -i parameter, but on Linux you
# do not.
<% content_for :head do %>
<title><%= @current_city.site_name %> : <%= @current_city.name %> Governance Observatory : Homepage</title>
<% end %>
<div class = 'main-content'>
<!-- Some content -->
</div>
@shreyas-satish
shreyas-satish / config.rb
Created August 28, 2011 14:04 — forked from maccman/config.rb
Rails 3 Config
# Rails 3 Config
#
# In: config/application.yml
#
# development:
# github:
# key: test
# secret: verysecret-dev
# production:
# github:
@shreyas-satish
shreyas-satish / application.rb
Created August 28, 2011 14:39
Rails config
module APPNAME
class Application < Rails::Application
config_file = YAML.load_file("#{Rails.root}/config/settings.yml")
global = config_file['global'].symbolize_keys
config.settings = global.merge( config_file[Rails.env].symbolize_keys )
# Use: APPNAME::Application.config.settings[:setting_var]
end