Skip to content

Instantly share code, notes, and snippets.

/*
Nice to study. Original here http://www.20thingsilearned.com/js/twentythings.min.js
*/
var TT = TT || {};
TT.PAGE_WIDTH = 800;
TT.PAGE_HEIGHT = 500;
TT.PAGE_MIN_WIDTH = 1000;
TT.PAGE_MIN_HEIGHT = 680;
TT.PAGE_MARGIN_LEFT = 32;
Pseudocode
Each node has x,y position and dx,dy velocity and mass m. There is usually a spring constant, s, and damping: 0 < damping < 1. The force toward and away from nodes is calculated according to Hooke's Law and Coulomb's law or similar as discussed above.
set up initial node velocities to (0,0)
set up initial node positions randomly // make sure no 2 nodes are in exactly the same position
loop
total_kinetic_energy := 0 // running sum of total kinetic energy over all particles
for each node
net-force := (0, 0) // running sum of total force on this particular node
@abernier
abernier / gist:1067125
Created July 6, 2011 12:37
Cross-browsers events listener implementation
({
addListener: null,
removeListener: null,
init: function () {
if (typeof window.addEventListener === 'function') {
this.addListener = function (el, type, fn) {
el.addEventListener(type, fn, false);
};
this.removeListener = function (el, type, fn) {
@abernier
abernier / goCanvas.js
Created July 7, 2011 12:53
Firebug : go to canvas!
//
// Make firebug going to facebook's canvas
//
// From Firebug console, just execute the following command
// Or make a bookmarklet: <a href="javascript:with(_FirebugCommandLine){cd($$(".canvas_iframe_util")[0].contentWindow);}">cd(canvas)</a>
//
// see: http://stackoverflow.com/questions/2495313/firebug-and-jquery-selectors-in-an-iframe#answer-2512156
//
cd($$(".canvas_iframe_util")[0].contentWindow);
@abernier
abernier / dots.pattern.css
Created July 21, 2011 13:30
CSS3 dots patterns
background-image: -webkit-linear-gradient(-90deg, transparent 0%, transparent 50%, white 50%, white 100%),
-webkit-linear-gradient( 0deg, rgba(0,0,0,.1) 0%, rgba(0,0,0,.1) 50%, white 50%, white 100%);
background-size:.25em .25em;
@abernier
abernier / github.gist.content.xml
Created July 21, 2011 14:02
YQL github.gist.content table
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Antoine BERNIER</author>
<documentationURL></documentationURL>
<sampleQuery>USE 'https://raw.github.com/gist/1097256' AS github.gist.content; select * from github.gist.content where gist_id='1097256'</sampleQuery>
</meta>
<bindings>
<select itemPath="content" produces="JSON">
<urls>
@abernier
abernier / gist:1099590
Created July 22, 2011 14:40
Houndstooth
background-color: white;
background-size: 1em 1em;
background-position:0em 0em,.5em .5em, -.5em .5em,.5em -.5em, 1.5em 1em,1em .5em;
background-image:
-webkit-linear-gradient(-45deg, white 25%, transparent 25%, transparent 75%, transparent 75%, transparent),
-webkit-linear-gradient(-45deg, transparent 25%, transparent 25%, transparent 75%, white 75%, white),
-webkit-linear-gradient(-135deg, #333 0%, #333 14%, transparent 14%, transparent 26%, #333 26%, #333 35%, transparent 35%, transparent 100%),
-webkit-linear-gradient( 45deg, #333 0%, #333 14%, transparent 14%, transparent 26%, #333 26%, #333 35%, transparent 35%, transparent 100%),
@abernier
abernier / gist:1101653
Created July 23, 2011 17:30
Method/Function invocation pattern
var o = {
value: 3
};
* Method invocation
When invoking a function that is a property of an object
o.incr = function () {
this.value += 1; // 'this' will be bound to 'o'
@abernier
abernier / reset.css
Created July 27, 2011 13:02
contextual CSS reset
/**
* Contextual reset
*
* Undo default browser's HTML styles
*
* Author: Antoine BERNIER (antoine.bernier@cafe.com)
*/
.reset {
font-size:inherit; line-height:inherit;
@abernier
abernier / pacman.css
Created July 28, 2011 02:13
pacman css3pattern
background:
-webkit-linear-gradient(90deg, blue 0, blue 0.02925em, transparent 0.02925em, transparent 0.26325em, blue 0.26325em, blue 0.2925em, transparent 0) 0em 0.14625em,
-webkit-radial-gradient(white 0.07605em, transparent 0em),
-webkit-linear-gradient(128deg, black 0.6201em, transparent 0) -0.585em 1.17em,
-webkit-linear-gradient(-128deg, black 0.6201em, transparent 0) -0.585em 1.17em,
-webkit-linear-gradient(115deg, black 0.351em, transparent 0) -0.585em 1.17em,
-webkit-linear-gradient(-115deg, black 0.351em, transparent 0) -0.585em 1.17em,
-webkit-linear-gradient(103deg, black 0.1755em, transparent 0) -0.585em 1.17em,
-webkit-linear-gradient(-103deg, black 0.1755em, transparent 0) -0.585em 1.17em,
-webkit-radial-gradient(yellow 0.585em, transparent 0) black;