Skip to content

Instantly share code, notes, and snippets.

@dgalarza
dgalarza / jquery_restful.js
Created January 5, 2011 19:46
Restful JSON requests
/**
* Extend the jQuery ajax methods to make JSON requests
* available to all the RESTful CRUD operations
* (POST, PUT, DELETE)
*
* Also overwrites the default getJSON method to provide the option
* for a separate method for handling errors
*
* @author Damian Galarza ([email protected])
*/
@dgalarza
dgalarza / mongoid_inheritance.rb
Created December 10, 2010 03:40
Mongodb Model Inheritance is win
# Base class that all WoW Armory based resources will inherit from
class ArmoryModel
include Mongoid::Document
field :last_armory_update, :type => Date
end
class UserCharacter < ArmoryModel
end
@dgalarza
dgalarza / rgb_to_hex.js
Created December 5, 2010 04:17
Converts an object representation of an RGB color to a hex string
/**
* Takes an RGB object and converts it into a hex string
*
* @param {Object} RGB Colors {r:255, g:255, b:255}
*/
var rgbToHex = function(rgb) {
var hex = rgb.b | (rgb.g << 8) | (rgb.r << 16);
return hex.toString(16); // 'FFFFFF'
};
## /config/initializers/dynamic_job.rb
require 'heroku'
# base class for all jobs that you wish to automatically scale and go down in Heroku
class DynamicJob
#set a cap on maximum number of users ever - just in case.
MAX_CONCURRENT_WORKERS = 100
def initialize
function fetchGuildDkp ($filter = NULL) {
$filter = $this->db->escape_str($filter);
$guild = 'SELECT char_name,char_class,crucApplications.user_id, attendance,sum(transaction_value)AS AvailDkp,round((count(DISTINCT dkp_raids.raid_id)/(SELECT count(raid_id) FROM dkp_raids WHERE raid_date >= join_date)*100))AS RaidAttend,round((count(DISTINCT dkp_raids.raid_id)/(SELECT count(raid_id) FROM dkp_raids)*100))AS OverallAttend, PastMonth.MonthAttend
FROM crucApplications
LEFT JOIN dkp_naxx_attend ON crucApplications.user_id = dkp_naxx_attend.user_id
LEFT JOIN dkp_transactions ON crucApplications.user_id = dkp_transactions.user_id
LEFT JOIN dkp_events ON dkp_transactions.event_id = dkp_events.event_id
LEFT JOIN dkp_raids ON dkp_events.raid_id = dkp_raids.raid_id
LEFT JOIN(
@dgalarza
dgalarza / session_store_middleware.rb
Created August 23, 2010 22:04
Add the following to config/initializers/session_store.rb to call our FlashSessionCookieMiddleware
Rails.application.config.middleware.insert_before(
ActionDispatch::Session::CookieStore,
FlashSessionCookieMiddleware,
Rails.application.config.session_options[:key]
)
@dgalarza
dgalarza / flash_session_cookie_middleware.rb
Created August 23, 2010 22:02
Rails 3 Rack Middleware for attaching a user's session cookie to a request made by Flash.
describe Notifications, :type => :helper do #setting type is necessary
before(:each) do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
it “should sent a nice email with the analyses to the user” do
analysis_observer = AnalysisObserver.instance
@dgalarza
dgalarza / log.js
Created April 9, 2010 21:29 — forked from afahy/log.js
// allows you to log an object while staying in the chain
(function($){
var console = ("console" in window) ? window.console : { "log": alert, "dir": alert };
$.extend($.fn, {
log: function(){
console.log(this);
return this;
},
# Generate 15 random IPs and convert them to Hexadecimal format,
# avoiding Ruby's built in conversion functions
#
# CSCI370 Assignment 1
#
# @author dgalarza (Damian Galarza)
# Create an array to represent hexadecimal numbers
@hexNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']