Skip to content

Instantly share code, notes, and snippets.

View 3rd-Eden's full-sized avatar
💭
I have approximate knowledge of many things

Arnout Kazemier 3rd-Eden

💭
I have approximate knowledge of many things
View GitHub Profile
@3rd-Eden
3rd-Eden / SpryModularSortInstructions.js
Created March 9, 2010 09:47
Making Spry's sort reusable.
Spry.Data.DataSet.sortInstructions = {};
Spry.Data.DataSet.sortInstructions['number'] = function( prop ){
return {
ascending:function(a, b)
{
a = a[prop]; b = b[prop];
if (a == undefined || b == undefined)
return (a == b) ? 0 : (a ? 1 : -1);
return a-b;
},
@3rd-Eden
3rd-Eden / SpryLiveListener.js
Created March 24, 2010 12:00
Event Delegation for Spry using CSS3 selectors
Spry.Utils.liveListener = function( eventType, root, capture ){
var that = this;
Spry.Utils.Notifier.call( that );
that.root = root || document.documentElement;
that.eventType = eventType || "click";
Spry.Utils.addEventListener( that.root, eventType, function( evt ){
var target = evt.target || evt.srcElement,
@3rd-Eden
3rd-Eden / SpryInputPlaceHolder.js
Created March 25, 2010 10:56
Detect if the placeholder attribute is support, if not find all elements and provide support for it through event listeners.
(function(){
if( function(){ var input = document.createElement( "input" ); return ( "placeholder" in input )}() )
return;
Spry.$$( "input[placeholder]", document.body ).forEach( function( e ){
var current = e.attributes.getNamedItem( "placeholder" ).value;
if( !e.value ){
e.value = current;
// add special place holder class for styling...
@3rd-Eden
3rd-Eden / script_to_region.js
Created March 25, 2010 16:01
Export Spry regions out of <script type="text/spry"></script>
(function( doc, rxp ){
var scripts = doc.getElementsByTagName("script"), i = scripts.length, tmp;
while( i-- ){
if( scripts[i].type == "text/spry" && scripts[i].id.match( rxp ) ){
tmp = doc.getElementById( scripts[i].id.replace( rxp, "" ) )
tmp.innerHTML = scripts[i].innerHTML;
Spry.Data.initRegions( tmp );
}
}
}( document, /replace_/))
@3rd-Eden
3rd-Eden / csvparser.js
Created May 3, 2010 19:05
Node.js gives a fatal error when looping big arrays
var fs = require('fs'),
sys = require('sys');
fs.readFile( './test/user_agent_data.csv', function( err, result ){
( result.split( "\n" ) ).forEach( function(){
sys.puts( arguments[2] );
});
});
@3rd-Eden
3rd-Eden / SpryElementSelectorReplace.js
Created May 12, 2010 10:32
How to replace the Spry Element selector engine
Spry.$$ = function( selectorSequence, rootNode )
{
var matches = [];
Spry.$$.addExtensions( matches );
// If the first argument to $$() is an object, it
// is assumed that all args are either a DOM element
// or an array of DOM elements, in which case we
// simply append all DOM elements to our special
@3rd-Eden
3rd-Eden / SpryEvaluateXPath.js
Created June 1, 2010 10:24
SpryEvaluateXPath
Spry.Data.XMLDataSet.evaluateXPath = function( contextNode, xpath ){
var results = [],
parser, i, length, tmp;
// Quit processing if we don't even have sufficient data to process
if( !( contextNode && xpath ) ) return results;
// Check if the Google Xpath library is available. If it's included it's
// usually an indication that user wants to use it as default.
if( window.ExprContext && window.xpathParse ){
@3rd-Eden
3rd-Eden / yuicssmin-testrunner.py
Created July 4, 2010 17:46
The testrunner I used for the YUI compressor port
#!/usr/bin/python2.4
import os, re
import logging
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from cssmin import compressor
class test(webapp.RequestHandler):
def get(self):
self.response.headers['content-type'] = 'text/html'
@3rd-Eden
3rd-Eden / nodejs_zip.js
Created July 15, 2010 13:10
Zipping files in Node.js
var zip = require('./zip'),
sys = require('sys'),
fs = require('fs');
fs.readFile( '/etc/hosts', function( err, res ){
var data = res.toString(),
unzip = data.length,
start = +new Date,
deflate = zip.deflate( data ),
zipper = deflate.length,
@3rd-Eden
3rd-Eden / gist:478345
Created July 16, 2010 13:12
TCP framing
var net = require('net'),
sys = require('sys');
var stream = new net.Stream();
stream.addListener( 'connect', function(){
this.setTimeout( 0 );
this.setNoDelay( true );
});