This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
get '/(:locale)/products/(:category)/(page/:page).:extension', | |
:to => 'products#index', | |
:as => :products, | |
:constraints => { | |
:locale => /[a-z]{2}/, | |
:category => /.+?/, | |
:page => /\d+/ | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_objects.each do |my_object| | |
if my_other_objects.any?{|my_other_object| my_other_object.Name == my_object.name} | |
# do something if we found one | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// used to verify characters and prevent incorrect input as the user is typing. | |
// TODO: detect special characters like period/comma/?/etc. in the first regexp | |
// USAGE: use the keydown event: "return dynamicVerify(e, '[0-9a-zA-Z]');" | |
// e = event, re = regexp for allowed characters, ce = regexp for allowed key codes | |
function dynamicVerify(e, re, ke) { | |
var key = e.keyCode || e.which; | |
var keychar = String.fromCharCode(key); | |
var rexp = new RegExp(re); | |
var kexp = new RegExp(ke); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (v.respond_to?(:empty?) ? v.empty? : !v) is basically rails' .blank? in plain ruby | |
class Hash | |
def delete_blank | |
delete_if do |k, v| | |
(v.respond_to?(:empty?) ? v.empty? : !v) or v.instance_of?(Hash) && v.delete_blank.empty? | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Mathieu 'p01' Henri <http://www.p01.org/releases/> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def bsearch(e, l = 0, u = length - 1) | |
return if l>u;m=(l+u)/2;e<self[m]?u=m-1:l=m+1;e==self[m]?m:bsearch(e,l,u) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _extend(obj) { | |
var sources = Array.prototype.slice.call(arguments, 1); | |
for (var i=0; i<sources.length; i++) { | |
var source = sources[i]; | |
for (var prop in source) { | |
obj[prop] = source[prop]; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var trimmed = str.replace(/^\s+|\s+$/g, ''); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this sucker takes care of validating datetime fields before rails gets there and | |
# messes everything up. it should preserve the local time zone from the user input, | |
# and check for nil. takes date strings of the format m/d/yyyy m:h (am/pm) | |
# this goes in the model | |
validates_with DateTimeValidator, :fields => [:add_date] | |
# this goes in some place like lib/date_time_validator.rb | |
class DateTimeValidator < ActiveModel::Validator | |
DATETIME_FORMAT = "%m/%d/%Y %I:%M %P" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Works for me in IE7+, Webkit, and FF | |
function resizeToContent(frame_id) { | |
var my_frame = document.getElementById(frame_id); | |
var content_width = my_frame.contentWindow.document.documentElement.scrollWidth; | |
var content_height = my_frame.contentWindow.document.documentElement.scrollHeight; | |
my_frame.style.width = content_width + 'px'; | |
my_frame.style.height = content_height + 'px'; | |
} |
OlderNewer