Skip to content

Instantly share code, notes, and snippets.

View ibolmo's full-sized avatar
🧠

Olmo Maldonado ibolmo

🧠
View GitHub Profile
@ibolmo
ibolmo / Listener.js
Created February 9, 2011 01:30 — forked from cpojer/Listener.js
// Element Listener Mixin
(function(){
// Prototype.. doesn't actually work..
this.Listener = new Class(function(){
var listener = new Events, removeEvent = listener.removeEvent;
listener.removeEvent = function(key, value){
removeEvent(key, value);
element.removeEvent(key, value);
// A memoize function to store function results of heavy functions
(function(slice){
Function.prototype.memoize = function(hashFn, bind){
var cache = {}, self = bind ? this.bind(bind) : this, hashFn = hashFn || JSON.stringify;
return function(){
return ((key = hashFn(slice.call(arguments))) in cache) ? cache[key] : (cache[key] = self(key));
};
(function(){
Class.Mutators.jQuery = function(name){
var self = this;
jQuery.fn[name] = function(arg){
var args = Array.prototype.slice.call(arguments, 1);
if ($type(arg) == 'string'){
var instance = $(this).data(name);
if (instance) instance[arg](args); // ????
@ibolmo
ibolmo / bench.bind.js
Created February 22, 2010 15:13 — forked from fearphage/bind-perf.htm
bench suite for Function.prototype.bind
window.onload = function() {
var noop = function(){ return; }
,results = []
,count = parseInt(location.hash.substr(1)) || 10000
,sequence = (bench_sequence || 'bind_old bind_new bind_newer bind_even_newer bind_researched').split(' ')
,length = sequence.length
,i = 0
,heading = document.getElementsByTagName('h1')[0].firstChild
,start
,name
@ibolmo
ibolmo / reverse.php
Created February 5, 2010 00:35 — forked from asteig/reverse.php
:P
<?php
//reverse string algorithm
function reverse($string) {
return implode('', array_reverse(str_split($string)));
}
echo reverse("mathematics");
// Mythical constructor-based Class Implementation Syntax
// Create a new class by subclassing Class
var MyClass = Class(function(){
this.initialize = function(){
console.log('MyClass::initialize')
};
/**
* Explanation: before compression, remove any first '/' for matched: ^[ \t]*\/\/\*\* *(Compat|Fix)\:?(\w)*
* That are not necessary for the build. E.g. if the build is for 1.3 with no compat, then all Compat
* matches will lose the first '/' and therefore all of that code becomes commented. Similarly for browser
* fixes.
*
* During compression, the user can optionally remove the comments and thereby removing the rest of the code.
*
* Otherwise, there is not JavaScript performance loss due to commenting. Parser will just skip.
*
/*
Script: Color.js
Class for creating and manipulating colors in JavaScript. Includes basic color manipulations and HSB <-> RGB <-> HEX Conversions.
License:
MIT-style license.
*/
function Color(type, color, alpha){
this.type = type.toUpperCase();