Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
subtleGradient / gist:24610
Created November 13, 2008 20:38
Shortcuts and Functionality needed in Espresso
escape - completion of words in the current document
⌘/ - comment selection/line with line comments
⌘⌥/ - comment selection/line with block comment
command option . - close current HTML/XML tag
command-shift-l - select current line
command-option-a - edit all selected rows
command-option-return - insert terminator at end of line
command-shift-t - select file by name / focus project search
command-ctrl-t - select command/snippet by name
var Dictionary = new Native({
name: 'Dictionary',
initialize: function(){
this.keys = [];
this.values = [];
}
});
Element.implement({
matchFromRoot: function(selector){
return document.getElements(selector, true).contains(this);
}
});
myElement.match('div') // true
myElement.match('body div') // false
myElement.matchFromRoot('div') // true
#!/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.
(?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>*+ \} ) )*+
)$
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;
};
/*
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 */
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 += ' }'
// 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){
@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();