Skip to content

Instantly share code, notes, and snippets.

"app".foo(); // Fail. The method `foo` doesn't exist
require('commonjs_mod'); // Modifies the String native
"app".foo(); // no Fail. The method `foo` was added
@subtleGradient
subtleGradient / commonjs_app.js
Created January 4, 2010 14:51
CommonJS: Module instances of global objects share prototypes?
String.prototype.foo = function(){ return "foo'd"; };
var myString1 = require('footools').myString;
var myString2 = "app";
myString1.foo(); // Fail?
myString2.foo(); // no Fail
@subtleGradient
subtleGradient / commonjs_app.js
Created January 4, 2010 14:49
CommonJS: Module instances of global objects share prototypes?
var myString1 = require('commonjs_mod').myString;
var myString2 = "app";
myString1.foo(); // no Fail. This string is an instance of a String whose prototype has a `foo` method
myString2.foo(); // Fail. This string is an instance of the global String native
@subtleGradient
subtleGradient / commonjs_app.js
Created January 4, 2010 14:36
CommonJS: Extending native prototypes from a module
require('footools').setup(Array, Boolean, Function, Number, RegExp, String);
"bar".foo(); // no Fail
@subtleGradient
subtleGradient / Brilliance Black (Inverted).tmTheme
Created January 3, 2010 22:52
Brilliance Black, My Little Pony (Brilliance White), Brilliance Dull TextMate Themes in the `tmTheme` format. By Thomas Aylott (SubtleGradient). These themes were designed so that logically similar things will have similar colors. These are extremely rich
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>author</key>
<string>Thomas Aylott</string>
<key>comment</key>
<string>Thomas Aylott ㊷ subtleGradient.com</string>
<key>name</key>
<string>Brilliance Black (Inverted)</string>
@subtleGradient
subtleGradient / toggle_app
Created January 1, 2010 19:13
toggle_app — Toggle the visibility of any app on Mac OS X — Use with Quicksilver or something to toggle with shortcut keys
#!/usr/bin/env bash
#
# toggle_app
# Toggle the visibility of any app on Mac OS X
# Use with Quicksilver or something to toggle with shortcut keys
#
# by: Thomas Aylott -- SubtleGradient.com
# license: MIT
#
// Using this HTML
/*
<div id=root>
<b id=3 class="foo bar">
<b id=2 class=bar>
<b id=1 class=foo></b>
</b>
</b>
</div>
*/
Object.fromQueryString = function(queryString){
queryString = String(queryString);
if (!queryString) return {};
queryString = queryString.split('?');
if (queryString.length > 1) queryString = queryString.slice(1);
queryString = queryString.join('?');
var object = {};
var vars = queryString.split('&');
if (vars.length) for (var i=0, this_var; this_var = vars[i]; i++){
this_var = this_var.split('=');
@subtleGradient
subtleGradient / Array.prototype.apply.js
Created December 21, 2009 18:07
String.prototype.call && Array.prototype.apply
Array.prototype.apply = function(bind, args){
var array = new Array(this.length);
for (var i=0; i < this.length; i++) {
if ('call' in this[i] && typeof this[i].call == 'function'){
try {
if (typeof this[i] == 'function')
array[i] = this[i].apply(bind, args);
else array[i] = this[i].call.apply(bind, args);
continue;
@subtleGradient
subtleGradient / History.Routing.js
Created December 16, 2009 15:18
Harald Kirschner's (http://digitarald.de/) MooTools History (replaces HistoryManager)
/**
* History.Routing
*
* @version 2.0
*
* @license MIT License
* @author Harald Kirschner <mail [at] digitarald.de>
* @copyright 2008 Author
*/