Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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);
Function.safeTry = (function(){
var currentHandler;
var dispatchFakeEvent;
var currentHandlerResult;
if (document.addEventListener){
document.addEventListener("fakeEvents", function(){
currentHandler(); // execute the callback
}, false);
@subtleGradient
subtleGradient / MooTools_Logo.svg
Created October 7, 2009 22:20
MooTools Logo in SVG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@subtleGradient
subtleGradient / lateBind.js
Created October 8, 2009 19:45
String.bind lets you bind to a method that doesn't exist yet, and then swap out methods without re-wiring all your codez
// -*- Mode: Javascript; tab-width: 4; -*-
/*
---
privides: [String.bound, String.prototype.bind]
description: Lets you bind to a method that doesn't exist yet, and then swap out methods without re-wiring all your codez
author: Thomas Aylott <subtlegradient.com>
copyright: 2009 Thomas Aylott
license: MIT Style
...
*/
@subtleGradient
subtleGradient / delayunless.js
Created October 30, 2009 13:55
delayUnless — fire an event after a delay unless it's cancelled by another event; DEMO: http://mooshell.net/JvwnU/
// -*- Mode: MooTools Javascript; tab-width: 4; -*-
/*
---
provides: delayUnless
author: Thomas Aylott <subtlegradient.com>
copyright: 2009 Thomas Aylott
license: MIT Style
requires: [MooTools, Element, Events]
...
*/
// Basic closure, assumes window === this
(function(){
// require stuff here
})();
// Custom closure, this === anything you want
(function(){
// require stuff here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Benchmark prototype Method vs Object Property Fn</title>
<script type="text/javascript" src="JSLitmus.js"></script>
<script type="text/javascript">
var MyClass = new Class({
initialize: function(){
this.foo = /*<b compat=1.2>*/'123' && /*</b>*/'345';
/*<b compat=1.2>*/this.foo = '123';/*</b>*/
this.foo = '345';
},
//<b fix=ie6>
method: function(/*<b compat=1.2>*/arg12, /*</b>*/arg20){