Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
subtleGradient / snippet.js
Created September 24, 2009 15:55
Number.prototype.divideToArray
Number.prototype.divideToArray = function(divideBy,forceInt){
var array = [];
var remainder = this % divideBy;
var result = this / divideBy;
if (forceInt)
result = (this - remainder) / divideBy;
for (var i = divideBy; i; i--)
array.push(result);
@subtleGradient
subtleGradient / Function.prototype.remember.js
Created August 25, 2009 16:14
Slow down functions that get called too often. Remember the result and immediately give back that result until the timeout runs out.
/*
JavaScript Function.prototype.remember
Copyright (c) 2009 Thomas Aylott (SubtleGradient.com)
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@subtleGradient
subtleGradient / refresh_ie6.sh
Created August 11, 2009 13:51
Refresh browsers from the shell
### Created by Thomas Aylott - http://subtleGradient.com
# Requires you to have Parallels or VMWare with Coherence or whatever
# Rename your explorer.app (or whatever) to "Internet Explorer 6.app"
osascript -e 'activate application "Internet Explorer 6"' -e 'tell application "System Events" to key code 96 -- F5 key' -e 'delay 1' &>/dev/null
echo "Internet Explorer 6 Refreshing…"
@subtleGradient
subtleGradient / position-fixed.css
Created July 29, 2009 16:17
Make position:fixed work in IE6
/*Make position:fixed work in IE6!*/
.fixed-top /* position fixed Top */{position:fixed;bottom:auto;top:0;}
.fixed-bottom /* position fixed Bottom */{position:fixed;bottom:0;top:auto;}
.fixed-left /* position fixed Left */{position:fixed;right:auto;left:0;}
.fixed-right /* position fixed right */{position:fixed;right:0;left:auto;}
* html,* html body /* IE6 Fixed Position Jitter Fix */{background-image:url(about:blank);background-attachment:fixed;}
* html .fixed-top /* IE6 position fixed Top */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}
* html .fixed-right /* IE6 position fixed right */{position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));}
// SubtleHoverInspect Bookmarklet
// subtlehoverinspect.bookmarklet.js
/*
The MIT License
Copyright (c) 2009 Thomas Aylott (subtlegradient.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@subtleGradient
subtleGradient / Espresso.requests.md
Created June 25, 2009 22:22
MacRabbit Espresso Feature Requests / Sugar requests

document the selectors api

EG: :capture(name), :capture(itemizer-firstused), :has-next(), [text == $name.text] etc…

allow folding to fold only part of an itemizer

HTML tags fold the whole tag including opening and closing tags, should only fold the contents.

var Something = function(){ alert('howdy'); }
I want "Something" to show in the navigator but I want only alert('howdy'); to fold and ideally select function(){ alert('howdy'); } when clicking in the itemizer.

(function(write, wrapper, slice, fragment){
document.write = function(){
var id = 'document_write' + $time().toString(36);
var html = slice.call(arguments).join('');
write.call(document, '<span id="' + id + '"></span>');
window.addEvent('domready', function(){
$A(wrapper.set('html', html).childNodes).filter(document.write.filter).each(function(node){
var btn = new Element('button',{html:'Run'}).addEvent('click', Context('dynamic').handleWith('handleClick'));
Ccontext(1).addHandler('handleClick', function(){alert(1);});
Ccontext(2).addHandler('handleClick', function(){alert(2);});
Context.set(1);
Context('dynamic') === Context(1);
btn.fireEvent('click'); // alert(1)
Context.set(2);
// # -- sequential speccing
var group1 = spec.group('description');
group1.add('some description', fn);
group1.add('some other description', fn);
var group2 = spec.group('description2');
group2.add('some description', fn);
group2.add('some other description', fn);
@subtleGradient
subtleGradient / Process API.md
Created June 22, 2009 05:02
JavaScript Process API proposal

Process API

The ServerJS system api might help: https://wiki.mozilla.org/ServerJS/System

Ideally Titanium would stick as close to existing standards as much as possible.

All processes, like the current process, could have: environment, arguments, stdin, stdout & stderr.

When creating a process I'd like to be able to define a process, along with its environment and arguments. Then hook up the stdin, stdout & stderr to some sort of IO objects. If you don't define the objects yourself, they could instantiate STDIN, STDOUT & STDERR constructors which are subclasses of some kind of IO. EG: