Skip to content

Instantly share code, notes, and snippets.

View heapwolf's full-sized avatar
🕷️
Vault of the Black Spiders

heapwolf heapwolf

🕷️
Vault of the Black Spiders
View GitHub Profile
var gesture = {
delta: {
X: 0,
Y: 0,
T: 0
},
start: {
X: 0,
Y: 0,
T: 0,
Exiting the dark ages of strongly coupled templating.
Remember "Classic ASP" or "Java Beans"? they never really understood the concept of the DOM.
They chose to ignore it and just stub in some placeholders like <%=myVariable%> for server
generated content then just rewrite the file.
These days, not much has changed, there are lots of templating engines. I think choosing a
templating engine with JS these days is like choosing between a fast car and a fast car. IMHO,
the most important thing to look at is the concept, not the performance. Sure you could go to
JSPerf and test how many milliseconds of difference there is between their compile times. But
<html>
<head>
<style>
#products {
display: -webkit-box;
-webkit-box-orient: horizontal;
}
#products p {
display: -moz-inline-box;
-moz-box-orient: vertical;
@heapwolf
heapwolf / es5check.js
Created November 29, 2010 04:30
identify ES5 functions that are not implemented in a browser (returns an object literal of arrays that contain the names of the missing functions)
var issues = (function() {
var o = {
"Array.prototype": "forEach map reduce reduceRight filter every some indexOf lastIndexOf",
"Array": "isArray",
"Object": "keys preventExtensions isExtensible getOwnPropertyDescriptor defineProperty getOwnPropertyNames create seal isSealed freeze isFrozen"
};
for(var l in o) {
o[l] = o[l].split(" ");
for(var f=0; f<o[l].length; f++) {
@heapwolf
heapwolf / indexOf
Created December 19, 2010 14:18
!!very fast array indexOf for outdated browsers
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(s) {
var len = this.length;
while(len--) {
if (this[len] === s) {
return len;
}
}
return -1;
@heapwolf
heapwolf / sugarcap.js
Created January 16, 2011 04:53
routing by capture-group-value with sugarskull
var router = SS.router({
'foo/?([a-zA-Z0-9_\-]+)?': { // if the route 'foo/whatever' is matched...
'1': { // the first capture group
'bar': { // a potential value
on: ["barFunc"], // list of methods to fire on match
once: ["barOnce"], // optional, once only this route
state: { "someNumber": 100 } // optional, some data
}
@heapwolf
heapwolf / arrayDiff.js
Created January 23, 2011 13:42
array diff
Array.diff = function(left, right)
{
var o = left;
var n = right;
var ns = {};
var os = {};
for (var i = 0; i < n.length; i++) {
if (ns[n[i]] == null)
var uA=navigator.userAgent.toLowerCase();
var version=((uA.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1]||"").split(".");
@heapwolf
heapwolf / ujsdomideas.js
Created February 5, 2011 04:36
unobstrusive.jsdom ideas
var d = { foo: [{ /* ... */ }], bla: 123123 };
{
".name[foo]": { "foo": "bla" },
".foo": "/foo.html",
".bazz": {
data: d.foo,
map: function(node, data) {
$(".content").weld(
{
some : "data",
user : "tmpvar"
},
{
map : function(key, value) {
$(this).attr("foo", value); // key is null if it is an array.
},
method : "append" // defines what action the insert method should do.