Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
subtleGradient / global1.js
Created March 5, 2011 06:42
Globalize JS
var Foo = 'bar';
@subtleGradient
subtleGradient / refresh-Safari-CSS
Created June 8, 2011 00:08
Refreshes the CSS in every Safari document using reCSS
#!/usr/bin/env osascript
-- Refreshes the CSS in every Safari document
-- Using the bookmarklet found at http://dojotoolkit.org/~david/recss.html
--
-- Converted to Applescript by Thomas Aylott - http://subtleGradient.com
tell app "Safari"¬
to do JavaScript "!function(){ var links = document.getElementsByTagName('link'); for (var i=0, link; link = links[i++];){ if (link.href && String(link.rel).toLowerCase().indexOf('stylesheet') >= 0){ var href = link.href.replace(/[&?]reCSS=\\d+/, ''); link.href = href + (href.indexOf('?') >= 0 ? '&' : '?') + 'reCSS=' + (+new Date); } } }()"¬
in every document
@subtleGradient
subtleGradient / mixin.js
Created June 14, 2011 18:39
Mixins as Mutators!
function Events(exports){
var events = {}
exports.fireEvent = function(){...}
exports.addEvent = function(){...}
// etc...
return exports
}
@subtleGradient
subtleGradient / Safer Module.example.js
Created June 21, 2011 18:06
Simple JavaScript Module Pattern
function MyClass(){
if (this instanceof MyClass){
this.init.apply(this, arguments);
} else {
MyClass.from(arguments[0])
}
}
MyClass.from = function(object){
// convert object into a MyClass or something
(function Earth(){
var FootBall = new Game('the one you play with your feet with all the running and stuff');
var Canada
(function USA(soccer){
var FootBall = new Game('the one you play with your hands with all the padding and stuff');
Canada = this;
}(FootBall));
require({
paths: {
'CoreTest': '../core/Specs/2.0',
'Core': '../core/Source',
'DOM': '../core/Source/DOM',
'More': '../more/Source',
'ART': '../art/Source',
'Slick': '../Slick/Source'
},
ready: function(){
@subtleGradient
subtleGradient / Object.getPrototypeOf.js
Created June 28, 2011 22:22 — forked from xavierm02/Object.getPrototypeOf.js
Polyfill for Object.getPrototypeOf
if (typeof Object.getPrototypeOf != "function")(function(){
Object.getPrototypeOf =
(typeof "".__proto__ == "object")
? function(object){
return getPrototypeValue(object, '__proto__');
}
: function(object){
return getPrototypeValue(object, 'constructor').prototype;
@subtleGradient
subtleGradient / appify
Created July 19, 2011 17:16 — forked from mathiasbynens/appify
appify — create the simplest possible Mac app from a shell script
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" ]; then cat <<EOF
appify v3.0.0 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
@subtleGradient
subtleGradient / instance config pattern.js
Created July 29, 2011 20:55 — forked from nktpro/gist:1114601
instance config pattern
Ext.define('Ext.SomeThing', {
config: {
foo: {
height: 123,
baz: {
something: 'zzz'
}
},
bar: {
@subtleGradient
subtleGradient / sortByFoo.js
Created August 3, 2011 02:21
Write the body of the sortByFoo function below
/*
* Write the body of the sortByFoo function below.
* Executing the code must display no warnings in your browser's console.
* i.e. all the assertions must pass
*/
function sortByFoo(array){
// TODO: Write code here. Use Array.sort.
return array;
}