Skip to content

Instantly share code, notes, and snippets.

View juliocesar's full-sized avatar

Julio Cesar Ody juliocesar

View GitHub Profile
@juliocesar
juliocesar / best-localStorage-polyfill-evar.js
Created April 18, 2011 23:19
This is the best localStorage polyfill in the world
// I mean, seriously, localStorage is supported even by your mum. How about instead of
// casing the feature out, you give users in-memory (stale) storage instead?
// If they close your application, they deserve to lose data anyway.
// if (!('localStorage' in window)) {
if (!Modernizr.localstorage) {
window.localStorage = {
_data : {},
setItem : function(id, val) { return this._data[id] = String(val); },
getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
@juliocesar
juliocesar / classes.js
Last active September 30, 2023 03:01
ES6 - classes
// ES6 classes example
// ===================
// Currently, with prototypal inheritance:
var Person = function(name) {
this.name = name;
};
Person.prototype.talk = function(words) {
@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}`);
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)
// Prefix mixins
// =============
//
// A set of SASS mixins for abstracting vendor prefixes.
@mixin background-size($parameters)
-webkit-background-size : $parameters
-moz-background-size : $parameters
-o-background-size : $parameters
background-size : $parameters
@juliocesar
juliocesar / for-loops.js
Created May 3, 2013 04:42
ES6 - for loops
// ES6 for loops
// =============
// Things in ES6 can be "iterable". Arrays are iterable by default.
var fruits = ['Apple', 'Banana', 'Grape'];
for (var fruit of fruits)
console.log('Fruit: ' + fruit);
@juliocesar
juliocesar / nazis.md
Created November 21, 2019 01:53
nazis_rise_to_power

(Source)

Sort of, but not quite.

NSDAP (the Nazi Party) won a plurality of seats in the Reichstag (Parliament), but was unable to form a majority government because the Communists won the second-greatest number of seats, and while neither party won a majority, they collectively won enough seats for neither one to be able to muster enough support from the other parties to form a working majority.

I don't remember the exact details (I'm sure someone else can elaborate), but basically the Nazis did their best to paralyze the government. Eventually, there was an alleged terrorist attack (actually staged by the Nazis themselves) that convinced (independent) President Hindenburg to name Hitler as "Chancellor" in exchange for the Nazis agreeing to form a coalition government with other parties. At the time, Chancellor was a largely symbolic and ceremonial role.

The Nazis then did what would, in computer security terms, be classified as a complex m

@juliocesar
juliocesar / testing_front_end_rspec_capybara.md
Created October 21, 2010 23:51
Testing front-end for a Sinatra app with RSpec and Capybara

Testing front-end for a Sinatra app with RSpec and Capybara

I've used Cucumber quite a bit on my last job. It's an excellent tool, and I believe readable tests are the way to the future. But I could never get around to write effective scenarios, or maintain the boatload of text that the suite becomes once you get to a point where you have decent coverage. On top of that, it didn't seem to take much for the suite to become really slow as tests were added.

A while ago I've seen a gist by Lachie Cox where he shows how to use RSpec and Capybara to do front-end tests. That sounded perfect for me. I love RSpec, I can write my own matchers when I need them with little code, and it reads damn nicely.

So for my Rails Rumble 2010 project, as usual, I rolled a Sinatra app and figured I should give the idea a shot. Below are my findings.

Gemfile

@juliocesar
juliocesar / vsjsonp.js
Last active August 8, 2016 03:50
Very simple JSONP
// VSJONP ― Very Simple JSONP
// ==========================
//
// Usage:
// fetchJsonP({
// url: 'http://shit-no-cors.json',
// complete: function(response) {
// console.log(response);
// }
// });
@juliocesar
juliocesar / color.scss
Last active August 3, 2016 05:45
Color palette implementation in Sass
// Color scale function
// ====================
//
// Similarly to dirg, this assists with creating rhythmic colour
// variations from a palette. The definition of the $color-palette var
// is made at build time.
// Granularity of variations.
$step-size: 7.5% !default;