Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Bensoussan mickey

View GitHub Profile
View gist:3792639
{
"theme": "Soda Dark.sublime-theme",
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"drawWhiteSpace": true,
"font_size": 12,
"highlight_modified_tabs": true,
"matchBracketsAngle": true,
"matchBracketsBraces": true,
"matchBracketsSquare": true,
"rulers": [80],
View gist:3728045

Tips and tricks

ri documentation

With RVM:

#> rvm docs generate      # => takes some time ^^
#> ri Array
#> ri Array.push
View gist:3105697
module LIC
class Recorder
# If the file doesn't exists, dump the response body to a file.
# If it does and the response body is different than what is in the file
# prints a nice diff.
def self.record_to file
require 'yaml'
require 'differ'
require 'colored'
View gist:3046449
require 'rubygems'
require 'yaml'
require 'base64'
require 'openssl'
require 'net/https'
require "rexml/document"
class CloudfrontInvalidator
def initialize(cf_id, *urls)
@batch = "purging " + Time.now.to_s
View lighbox.js
$("#image_id").load(function(){
// stuff to do after the image is loaded
});
View activity.rb
def self.batch_add(users, activity_type, target)
return false if users.blank? or activity_type.blank? or target.blank?
inserts = []
users.each {|user| inserts.push "('#{user.id}', '#{activity_type}', '#{target.id}', '#{target.class}', UTC_TIMESTAMP())" }
sql = "INSERT INTO activities (`user_id`, `activity_type`, `target_id`, `target_type`, `created_at`) VALUES #{inserts.join(", ")}"
ActiveRecord::Base.connection.execute sql
end
View activity.rb
def batch_add(users, activity_type, target)
return false if users.blank? or activity_type.blank? or target.blank?
inserts = []
users.each {|user| inserts.push "('#{user.id}', '#{activity_type}', '#{target.id}', '#{target.class}', UTC_TIMESTAMP())" }
sql = "INSERT INTO activities (`user_id`, `activity_type`, `target_id`, `target_type`, `created_at`) VALUES #{inserts.join(", ")}"
ActiveRecord::Base.connection.execute sql
end
View audition_observer.rb
class AuditionObserver < ActiveRecord::Observer
# ACTIVITY OBSERVER : new audition posted
def after_create(audition)
if audition.actor
Activity.add(audition.actor.user, Activity::AUDITION_POSTED, audition)
end
end
end
View audition_observer.rb
class AuditionObserver < ActiveRecord::Observer
# ACTIVITY OBSERVER : new audition posted
def after_create(audition)
if audition.actor
Activity.add(audition.actor.user, Activity::AUDITION_POSTED, audition)
end
end
end