Skip to content

Instantly share code, notes, and snippets.

View joshed-io's full-sized avatar

Josh Dzielak joshed-io

View GitHub Profile
class VersionParentObserver < ActiveRecord::Observer
observe MyModel, MyOtherModel
[:create, :update, :destroy].each do |action|
define_method("after_#{action}") do |record|
increment_version_for_observed(record, action)
end
end
private
module Blippin
def self.included(base)
base.class_eval do
before_filter :create_blip
after_filter :update_blip
end
end
def create_blip
begin
create_table "blips", :force => true do |t|
t.string "uri"
t.string "method"
t.string "ip_address"
t.string "referrer"
t.string "user_agent"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "login_id"
class TouchParentObserver < ActiveRecord::Observer
observe MyModel, MyOtherModel
[:create, :update, :destroy].each do |action|
define_method("after_#{action}") do |record|
touch_parents_of_observed(record, action)
end
end
private
class CreateModelVersions < ActiveRecord::Migration
def self.up
create_table :model_versions do |t|
t.string :model_name
t.integer :version
t.timestamps
end
end
def self.down
class ModelVersionObserver < ActiveRecord::Observer
observe MyReferenceDataModel
[:create, :update, :destroy].each do |action|
define_method("after_#{action}") do |record|
increment_model_version_of_observed(record, action)
end
end
private
@joshed-io
joshed-io / apple_store.rb
Created November 20, 2010 05:59
You can has program at apple store
while true do print "I CAN HAS TEH MACS #{" "*rand(1000)} "; sleep (rand(250.0).to_f/1000.0) end
@joshed-io
joshed-io / apple_store_ufo_snowflake_upside_down.rb
Last active August 11, 2019 15:03
Run this on a handful of macs at the Apple Store and then shout "We've been hacked!"
while true do print "[ **** ] #{" "*rand(50)} "; sleep (rand(50.0).to_f/1000.0) end
@joshed-io
joshed-io / meta_regexp.js
Created April 27, 2011 00:19
Regular expression to determine if a string contains a valid regular expression
var regexpMatcher = /^\/([^\/]|\\\/)+\/[$gim]*$/;
function assert(value) { return regexpMatcher.test(value); }
function isRegexp(value) { if (!assert(value)) alert("Failed " + value); }
function isNotRegexp(value) { if (assert(value)) alert("Failed " + value); }
isRegexp("/foo/");
isRegexp("/foo/gim");
isRegexp("/foo/img");
@joshed-io
joshed-io / yepnope_preload_prefix_test.js
Created June 9, 2011 00:25
yepnope.js preload! prefix not working out of box
//on Chrome 12 on OSX
//after loading in vanilla yepnope js from
//https://github.com/SlexAxton/yepnope.js/blob/master/yepnope.js
//calling this results in application.js loading into an <img> tag then *executing* despite !preload prefix
yepnope("preload!/javascripts/application.js");
//on line 410 of the lib there is a resource.noexec check, but no other refs in the lib to 'noexec'
//when setting this to true, the desired load-but-dont-execute behavior works.