Skip to content

Instantly share code, notes, and snippets.

@dgalarza
dgalarza / Ruby IP Generator.rb
Created September 14, 2009 20:42
Simulate creating 10 random IP numbers, converted to Hexadecimal string
# Uses built in ruby functions to handle conversions etc
# Create 10 IPs
for ips in 1...10
ip = ""
#generate a random segment for each IP part (4 parts for each IP)
for segment in 1...4
ip += rand(255).to_s(16).upcase
end
puts ip
end
# 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']
@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;
},
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 / 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.
@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]
)
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(
## /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
@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'
};
@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