Skip to content

Instantly share code, notes, and snippets.

"mandrill_events": [
{
"event": "send",
"msg": {
"ts": 1365109999,
"subject": "This an example webhook message",
"email": "example.webhook@mandrillapp.com",
"sender": "example.sender@mandrillapp.com",
"tags": [
"webhook-example"
@waseem
waseem / example.rb
Last active August 29, 2015 14:07 — forked from anonymous/example.rb
class someController < ApplicationController
def a
set_instance_variable
#How would i access @instance_variable in this method.
#I could make it a class variable right?
@instance_variable == 'whatever' #=> true
end
def b
set_instance_variable
@waseem
waseem / company.rb
Last active December 15, 2015 05:29 — forked from anonymous/gist:5209780
class Company
attr_reader :title
def initialize(title)
@title = title.capitalize
@users = []
end
def add_company_name(new_comp)
@title = new_comp
@waseem
waseem / deploy.rb
Created December 1, 2012 01:14 — forked from markoa/deploy.rb
Ingredients to monitor Resque with God automatically via Capistrano (on Ubuntu)
namespace :deploy do
desc "Hot-reload God configuration for the Resque worker"
task :reload_god_config do
sudo "god stop resque"
sudo "god load #{File.join(deploy_to, 'current', 'config', 'resque-' + rails_env + '.god')}"
sudo "god start resque"
end
end
# append to the bottom:
- options = { :as => :string, :label => false }
= f.input :date_start, options.merge(:placeholder => "Start Date")
= f.input :time_start, options.merge(:placeholder => "Start Time")
= f.input :date_end, options.merge(:placeholder => "End Date")
= f.input :time_end, options.merge(:placeholder => "End Time")
@waseem
waseem / gist:3945472
Created October 24, 2012 11:01 — forked from whitmanc/gist:3943844
MP3 File Recognizer
package recognizer;
/*
* Copyright 1999-2004 Carnegie Mellon University.
* Portions Copyright 2004 Sun Microsystems, Inc.
* Portions Copyright 2004 Mitsubishi Electric Research Laboratories.
* All Rights Reserved. Use is subject to license terms.
*
* See the file "license.terms" for information on usage and
* redistribution of this file, and for a DISCLAIMER OF ALL
@waseem
waseem / description.markdown
Created September 15, 2012 19:00 — forked from runemadsen/description.markdown
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@waseem
waseem / cards_controller.rb
Created August 17, 2012 10:03
CardsController
class CardsController < InheritedResources::Base
require 'aws/s3'
require 'builder'
def show
@card = Card.find(params[:id])
if (@card)
respond_to do |format|
format.xml #{ render @card, :template => '#{Rails.root}/app/views/cards/show.xml.builder', :type => :builder, :layout => false }
format.html
@waseem
waseem / cars_controller.rb
Created August 17, 2012 09:13
Controller for Card rendering
def show
@card = Card.find(params[:id])
if (@card)
respond_to do |format|
format.xml
format.html
end
end
end
@waseem
waseem / gist:3220182
Created July 31, 2012 20:26 — forked from gotjosh/gist:3220028
How can I avoid to create the array on the first line?
@vidoes = @publisher.sources.map do |s|
s.videos.paginate(:per_page => params[:limit] ||= 10, :page => params[:page] ||= 1)
end