Skip to content

Instantly share code, notes, and snippets.

View juliocesar's full-sized avatar

Julio Cesar Ody juliocesar

View GitHub Profile
describe "Asynchronous specs", ->
funcRunInBackground = ->
value = 1
wrapFuncRunInBackground = (done) ->
# setup for simmulating the async operation, a function run in the background
setTimeout ->
funcRunInBackground()
done()
, 3000
@juliocesar
juliocesar / gist:57892
Created February 4, 2009 02:41 — forked from lachie/gist:57891
hmm
var table = $([
'<table>',
'<thead>,
'<tr'>,
'<th>Foo</th>',
'<th>Bar</th>',
'</tr>',
'</thead>',
'<tfoot />',
'<tbody />'
@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 :-)
function on() {
for (var i = 0, len = arguments.length - 1; i < len; i++) if (RegExp(arguments[i]).test(document.location.pathname)) {
arguments[len]()
break;
}
}
module Invisibility
def self.included base
base.send :attr_reader, :visible
end
def activate
@visible = false
end
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?
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 ) )
@juliocesar
juliocesar / calc-sapisidhash.js
Created May 11, 2023 17:02 — forked from eyecatchup/calc-sapisidhash.js
Calculate SAPISIDHASH
async function getSApiSidHash(SAPISID, origin) {
function sha1(str) {
return window.crypto.subtle.digest("SHA-1", new TextEncoder("utf-8").encode(str)).then(buf => {
return Array.prototype.map.call(new Uint8Array(buf), x=>(('00'+x.toString(16)).slice(-2))).join('');
});
}
const TIMESTAMP_MS = Date.now();
const digest = await sha1(`${TIMESTAMP_MS} ${SAPISID} ${origin}`);