Skip to content

Instantly share code, notes, and snippets.

View nzifnab's full-sized avatar

Nathan Benes nzifnab

  • Westin Consulting
  • Denver, CO
View GitHub Profile
@nzifnab
nzifnab / gist:464059
Created July 5, 2010 06:09
Crappy Weather
# Somewhere in heaven...
rainy_regions = Region.find(:all, :conditions => ["name IN (?)", [:denver, :loveland, :fort_collins]])
rainy_regions.each{ |rain_here| rain_here.saturate_clouds! }
# Meanwhile, in the stratosphere...
if (saturated_regions = Cloud.find_all_by_density(MAX_CLOUD_SATURATION_DENSITY).map{|cloud| cloud.region}).any?
current_weather = Rain.new( :regions => saturated_regions )
current_weather.quantity = :downpour
current_weather.duration = 6.hours
class Array
def find_duplicates(other_array)
hsh = {}
other_array.each{|val| hsh[val] = true}
# Ya, could be done easier using Array.select{}, but that feels like cheating
# return test_array.select{|val| hsh[val] == true}
result_array = []
self.each{ |val| result_array << val if hsh[val] }
result_array
@nzifnab
nzifnab / conten_ui_log.rb
Created April 30, 2011 00:12
Get content_ui for log
acts_as_event_logger(
:attributes => [:active, :contact, :company_name, [:primary_address, :address_change], [:primary_address, :phone_change], [:primary_address, :phone2_change],
[:primary_address, :fax_change], :url, :description, :services, :coverage, :memberships, :business_since, :license_number, [:owners, :email], content_x_log_array ],
:cache_values => [:owners],
:event_type => "Profile Update"
)
#return an array of arrays for the act event logger track changes in content_ui fields
# [ profile content real name, "displayed field name: displayed field value"]
@nzifnab
nzifnab / account.rb
Created May 4, 2011 22:16
update_amount method
def update_amount(amt, change_type)
if change_type == 'Withdraw'
self.amount -= amt
elsif change_type == 'Deposit'
self.amount += amt
else
raise ArgumentError.new("Unknown type #{change_type} when altering account funds.")
end
end
@nzifnab
nzifnab / jqueryTemplate.js
Created May 7, 2011 02:23 — forked from tosh/jammit-jquery-tmpl.coffee
jquery tmpl templating function for use with jammit
// It's more advisable to store the compiled version of the jQuery template in JST,
// And then use a separate function that renders on a per-use basis from that pre-compiled template.
function jqueryCacheTemplate(templateString){
return $.template(null, templateString);
}
function jqueryTemplate(name){
return $.tmpl(JST[name], arguments[0], arguments[1]);
}
@nzifnab
nzifnab / monkey_jammit.rb
Created May 7, 2011 08:38
Monkeypatch of Jammit to pre-compile using Haml
module Jammit
class Compressor
# Compiles a single JST file by writing out a javascript that adds
# template properties to a top-level template namespace object. Adds a
# JST-compilation function to the top of the package, unless you've
# specified your own preferred function, or turned it off.
# JST templates are named with the basename of their file.
# We are monkey-patching it so that we get Haml compilation *before* it hits the client.
def compile_jst(paths)
@nzifnab
nzifnab / who_called.rb
Created May 11, 2011 20:06
Who called me!
# file_1.rb
#-----------------------------
require 'file_2'
where_am_i()
#-----------------------------
# file_2.rb
#-----------------------------
@nzifnab
nzifnab / help.rb
Created June 28, 2011 17:53
helping stuff
# <-- This is a comment
# Array of cards:
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# and the player's current hand:
my_hand = []
# In ruby it can also be written like this:
# arr = [1..10]
# Now let's get a random value from the array (deck of cards):
start
declarations
arrFull_Deck [2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14]
arrP1_hand [ ]
arrP2_hand [ ]
arrTable [ ]
num Full_DeckCardCount = 52
num Table = 0
num P1_CardValue
num P2_CardValue
start
declarations
arrFull_Deck [2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14, 2,3,4,5,6,7,8,9,10,11,12,13,14]
arrP1_hand [ ]
arrP2_hand [ ]
arrTable [ ]
num Full_DeckCardCount = 52
num Table = 0
num P1_CardValue
num P2_CardValue