Skip to content

Instantly share code, notes, and snippets.

@oberhamsi
oberhamsi / lintit.js
Last active December 16, 2015 07:28
quick jslint with ringo
var fs = require('fs');
JSLINT(fs.read(require('system').args[1]), {
passfail: false,
undef: true,
vars: true,
bitwise: true,
sloppy: true,
white: true,
devel: true,
plusplus: true,
#!/bin/bash
REVISIONS=`svn log -q --stop-on-copy |grep "^r" | cut -d"r" -f2 | cut -d" " -f1`
for rev in $REVISIONS; do
prevRev=$(($rev-1))
difftext=`svn diff --old=$file@$prevRev --new=$file@$rev | tr -s " " | grep -v " -\ \- " | grep -e "$1"`
if [ -n "$difftext" ]; then
echo "$rev: $difftext"
fi
done
$.fn.listHandlers = function(events, outputFunction) {
return this.each(function(i){
var elem = this,
dEvents = $(this).data('events');
if (!dEvents) {return;}
$.each(dEvents, function(name, handler){
if((new RegExp('^(' + (events === '*' ? '.+' : events.replace(',','|').replace(/^on/i,'')) + ')$' ,'i')).test(name)) {
$.each(handler, function(i,handler){
outputFunction(elem, '\n' + i + ': [' + name + '] : ' + handler );
});
@oberhamsi
oberhamsi / ringojs.init
Created November 15, 2012 10:27
ringojs init.d
#!/bin/sh
#
# /etc/init.d/ringojs -- startup script for the Ringo JavaScript runtime
#
# Written by Miquel van Smoorenburg <[email protected]>.
# Modified for Debian GNU/Linux by Ian Murdock <[email protected]>.
# Modified for Tomcat by Stefan Gybas <[email protected]>.
# Modified for Tomcat6 by Thierry Carrez <[email protected]>.
# Modified for RingoJS by Hannes Wallnoefer <[email protected]>.
#
@oberhamsi
oberhamsi / sessiondatatest.js
Created November 7, 2012 15:56
req.session.data problem
var {Application} = require('stick');
var app = exports.app = new Application();
app.configure('route');
app.configure('session');
app.get('/', function(req) {
console.dir(req.session.data);
});
@oberhamsi
oberhamsi / proxytest.js
Created November 7, 2012 13:21
js Proxy in rhino
var myObject = {
"foo": true,
"author": "simon",
"env": 123
}
var myProxy = new JavaAdapter(org.mozilla.javascript.NativeObject, {
// The "start" argument is here for setters and getters living
// on a prototype, so they know what to use as "this"-object.
put: function(name, start, value) {
@oberhamsi
oberhamsi / collision.js
Last active October 12, 2015 09:37
tmx collision map
var gamejs = require('gamejs');
var $v = require('gamejs/utils/vectors');
/*
* · Each tile can hold a "block" property detailing its desired
* blocking behaviour. Possible blocking data values are:
* - "none" -> Tile does not block.
* - "always" -> Tile blocks.
* - "north" -> Tile does not allow to go through its north border.
* - "east" -> Tile does not allow to go through its east border.
/*!
* @version 1.0
* @see ORFON
* A setInterval which is pausable and does not trigger
* when the current document doesn't have focus.
*
* Must explictely be `start()`ed.
*
* Optionally, the callback can return `false` in which case the
* `interval` duration is increased in `intervalStep` up to `maxInterval` until a later callback
var {Variable} = require('reinhardt/variable');
var {Context} = require('reinhardt');
var profiler = require('ringo/profiler');
var {Broadcast} = require("radimeta/model/all");
var {renderResponse, Template} = require('reinhardt');
var {Loader} = require("reinhardt/loaders/filesystem");
var fs = require('fs');
@oberhamsi
oberhamsi / fixunicode.js
Created August 24, 2012 14:09
fix unicode string
/* call with file to be cleaned
write result into file with postfix ".cleaned"
*/
var fs = require('fs');
var system = require('system');
var text = fs.read(system.args[1]);
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;