Skip to content

Instantly share code, notes, and snippets.

var Something = function(arg){
console.log(['something:', arg]);
};
var Weird = function(fn){
this.Something = function(arg){
console.log(['something weird:', arg]);
};
@subtleGradient
subtleGradient / README.js
Created October 15, 2008 13:44
Event Delegation by Stedia and the MooTools Dev Team
// basic usage:
$('myParentElement').relayEvents({
'a.menuitem':{
'click': function(e){}
},
'input[name=phone]':{
'keydown': function(e){},
@subtleGradient
subtleGradient / mergeAdd.js
Created October 16, 2008 01:24
$mergeAdd({ fred:1 }, { fred:1 }) -> { fred:1 }
function $mergeAdd(){
var mix = {};
var obs = Array.flatten(arguments);
for (var i = 0, l = obs.length; i < l; i++){
var object = obs[i];
if ($type(object) != 'object') continue;
for (var key in object){
var object_prop = object[key], mp = mix[key];
if(!object_prop && $type(object_prop)!='number') continue;
@subtleGradient
subtleGradient / formatCurrency.js
Created October 16, 2008 01:27
formatCurrency( 123 | 123.321 ) -> ( "$0" | "<b class="neg">-$123<i class="cents c123">.123</i></b>" )
function formatCurrency(num){
num = (num||'0').toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
if(num+0 == 0) return '$0';
var sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
var cents = num%100;
num = Math.floor(num/100).toString();
// TODO: Remove this once it's added to MooTools code
Element.implement({
toFormHash: function(){
var formHash = $H();
this.getElements('input, select, textarea', true).each(function(el){
if (!el.name || el.disabled) return;
var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
return opt.value;
}) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
$splat(value).each(function(val){
function pp(object){
switch ($type(object)){
case 'object':
object = $H(object);
var h = '{ ';
object.each(function(value, key){
h += '{key}: {value}, '.substitute({key:key, value: pp(value) })
})
h += ' }'
/*
mkdir -p ~/Library/KeyBindings
mv ~/Desktop/DefaultKeyBinding.dict ~/Library/KeyBindings/DefaultKeyBinding.dict #*/
{
/* Modifier keys: start with C-m */
"^m" = {
"^ " = ("insertText:", "\U2423"); /* C-space space */
"^e" = ("insertText:", "\U21A9"); /* C-e return */
"e" = ("insertText:", "\U2305"); /* e enter */
Class.Mutators.Logs=function(self,methods){
$splat(methods).each(function(methodName){
var method = self[methodName];
self[methodName]=function(){
try{ console.log(Array.flatten([methodName, arguments]).join(',')); }catch(e){};
return method(arguments);
};
});
return self;
};
(?x-m)^
# Yes *+ Open ( Blank |Comments | (No Paren | String) | String | (Nested Parens ) )*+
(?> \g<yesS>*+ \[ (?<yesS> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noS>[^\[\]''"/]) | (?<str> ''(\\''|[^''])*+'' | "(\\"|[^"])*+" | /(\\/|[^/])*+/) | (?<squar> \[ \g<yesS>*+ \] ) )*+
| \g<yesR>*+ \( (?<yesR> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noR>[^\(\)''"/]) | \g<str> | (?<round> \( \g<yesR>*+ \) ) )*+
| \g<yesC>*+ \{ (?<yesC> (?!.) |//.*+|/\*((?!\*/).)++(\*/|$)|(^)((?!/\*).)*(\*/)| (?<noC>[^\{\}''"/]) | \g<str> | (?<curly> \{ \g<yesC>*+ \} ) )*+
)$
#!/bin/sh
#
# This hook does two things:
#
# 1. update the "info" files that allow the list of references to be
# queries over dumb transports such as http
#
# 2. if this repository looks like it is a non-bare repository, and
# the checked-out branch is pushed to, then update the working copy.
# This makes "push" function somewhat similarly to darcs and bzr.