Skip to content

Instantly share code, notes, and snippets.

Avatar

Julio Cesar Ody juliocesar

View GitHub Profile
View fails.coffee
describe "Asynchronous specs", ->
funcRunInBackground = ->
value = 1
wrapFuncRunInBackground = (done) ->
# setup for simmulating the async operation, a function run in the background
setTimeout ->
funcRunInBackground()
done()
, 3000
View sync-localStorage.coffee
sync: ( method, collection, options ) ->
return Backbone.sync(method, collection, options) unless 'localStorage' in window
content = localStorage.getItem( @url() )
if content and not navigator.onLine
options.success JSON.parse content
else
return Backbone.sync( method, collection, options ).done ( response ) =>
localStorage.setItem( @url(), JSON.stringify( response ) )
View rack_enforce_valid_encoding.rb
module Rack
class EnforceValidEncoding
def initialize app
@app = app
end
def call env
full_path = (env.fetch('PATH_INFO', '') + env.fetch('QUERY_STRING', ''))
if full_path.valid_encoding? && Rack::Utils.unescape(full_path).valid_encoding?
View invisibility_spec.rb
module Invisibility
def self.included base
base.send :attr_reader, :visible
end
def activate
@visible = false
end
View Julio’S router.js
function on() {
for (var i = 0, len = arguments.length - 1; i < len; i++) if (RegExp(arguments[i]).test(document.location.pathname)) {
arguments[len]()
break;
}
}
View mock_ajax.js
// jQuery._ajax = jQuery.ajax;
// jQuery.ajax = function(opts){
// var self = this;
// return setTimeout(function(){
// jQuery._ajax.call(self, opts);
// }, 2000);
// };
// As if man :-)
View alert_me
#!/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
##
View 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?
View gist:57892
var table = $([
'<table>',
'<thead>,
'<tr'>,
'<th>Foo</th>',
'<th>Bar</th>',
'</tr>',
'</thead>',
'<tfoot />',
'<tbody />'