Skip to content

Instantly share code, notes, and snippets.

View juliocesar's full-sized avatar

Julio Cesar Ody juliocesar

View GitHub Profile
module Rack
class NoIE
def initialize(app, options = {})
@app = app
@options = options
@options[:redirect] ||= 'http://www.microsoft.com/windows/internet-explorer/default.aspx'
@options[:minimum] ||= 7.0
end
def call(env)
@juliocesar
juliocesar / prime.rb
Created November 19, 2009 00:39 — forked from atnan/prime.rb
class Integer
def prime?
!("1" * self).match(/^1?$|^(11+?)\1+$/).nil?
end
end
class DHHException < Exception; end
raise DHHException, 'Whoops!' if !1.prime?
#!/usr/bin/env ruby
##
# alertme
#
# A simple delay timer to send a growl notification at specific time with a
# message. Useful for when you need to check on something later
#
# echo "Go look at system 42" | alertme in 2 hours
##
// jQuery._ajax = jQuery.ajax;
// jQuery.ajax = function(opts){
// var self = this;
// return setTimeout(function(){
// jQuery._ajax.call(self, opts);
// }, 2000);
// };
// As if man :-)
@juliocesar
juliocesar / gist:255668
Created December 13, 2009 23:25
Simple Google Ajax LocalSearch example
// Run the code below after you loaded the API with your key, though a separate file
// or straight onto the body of the document.
(function() {
google.load('search', '1');
function loaded() {
window.localsearch = new google.search.LocalSearch();
};
;(function($) {
$.progressiveFade = function(element) {
var childTag;
switch($(element).get(0).tagName) {
case 'DIV':
childTag = 'div';
break;
case 'UL':
childTag = 'li';
break;
// Say we got: <ul> <li>Foo</li> <li>Bar</li> </ul>
// Fade list entries one by one, with a 200ms interval
//
// $.withChildren('ul:first', 'li', 'fadeOut', [], 200)
//
;(function($) {
$.withChildren = function(element, childSelector, _method, args, after) {
var childTag = childSelector || {'DIV': 'div', 'UL': 'li'}[$(element).get(0).tagName] || 'div';
var children = $(element).find('> ' + childTag);
diff --git a/lib/express/request.js b/lib/express/request.js
index 3f08f4f..62460af 100644
--- a/lib/express/request.js
+++ b/lib/express/request.js
@@ -101,7 +101,7 @@ exports.Request = Class({
return new plugin.klass(plugin.options)
})
this.uri.post =
- this.header('content-type') == 'application/x-www-form-urlencoded' ?
+ /^application\/x-www-form-urlencoded/.test(this.header('content-type')) ?
@juliocesar
juliocesar / jquery.oneateachtime.js
Created December 20, 2009 23:28
Runs a method on each element of a collection, with x milliseconds of interval between each
// Instead of this -> http://gist.github.com/255851
// Use the code below. It's a lot more straightforward.
$.fn.oneAtEachTime = function(method, args, after) {
var collection = this, index = 0;
(function(e) {
$(e)[method].apply($(e), args);
var closure = arguments.callee, next = collection.get(index++);
if (next) { setTimeout(function() { closure(next); }, (parseInt(after) || 1000)); };
})(this.get(index));
not_found do
render_template_if_exists!
end
def render_template_if_exists!
name = File.basename(request.path)
Dir["#{Sinatra::Application.root}/views/#{name}.*"].each do |match|
@_format = File.extname(match).sub(/^./, '')
@_template = File.basename(match, File.extname(match))
end