Skip to content

Instantly share code, notes, and snippets.

/*!
* @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;
@oberhamsi
oberhamsi / isolated.js
Created August 24, 2012 07:28
isolated workers and singletons
/**
* When you see a `postMessage()` it's clear your passing data into
* a different module space. This fact can be obfuscated if you
* use a Singleton.
*
*/
var {Worker} = require("ringo/worker");
var Foo = function() { return this;}
@oberhamsi
oberhamsi / instanceoftest.js
Created August 23, 2012 14:07
ringojs instanceof
var {Worker} = require("ringo/worker");
var Foo = function() { return this;}
function main() {
var w = new Worker(module.id);
w.postMessage(new Foo());
}
function onmessage(e) {
@oberhamsi
oberhamsi / mixin.js
Created June 22, 2012 19:40
nicer mixin
// I never remember which one is the mixin and which one is the class.
// And I find `mixin({mixin:..})` too verbose
mixin(fooMixin, fooBar)
// what I rather want:
mix(fooMixin).into(fooBar);
// so...
var mix = function(mixin) {
return {
@oberhamsi
oberhamsi / mtrtest.js
Created May 14, 2012 13:11
run mtr every 5 seconds and report hosts losing packets
/**
* Continuesly mrts a host and logs errors if packet loss to host
* or on route.
*/
var {command} = require('ringo/subprocess');
var {setInterval} = require('ringo/scheduler');
var log = require('ringo/logging').getLogger('mtr');
var $d = require('ringo/utils/dates');
//var MTR_PATH = '/root/mtr-0.82/mtr';
@oberhamsi
oberhamsi / gist:2510595
Created April 27, 2012 16:28
/tmp/jquery$ git grep " IE "
build/lib/process.js: // IE croaks with "syntax error" on code like this:
speed/jquery-basis.js: // Handle the case where IE and Opera return items
speed/jquery-basis.js: // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
speed/jquery-basis.js: // If IE event model is used
speed/jquery-basis.js: // If IE and not a frame
speed/jquery-basis.js: // aren't supported. They return false on IE (#2968).
speed/jquery-basis.js: // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
speed/jquery-basis.js: // If IE is used, use the trick by Diego Perini
speed/jquery-basis.js: // IE strips leading whitespace when .innerHTML is used
speed/jquery-basis.js: // IE will insert them into empty tables
@oberhamsi
oberhamsi / start
Created April 5, 2012 12:41
openshift start/stop scripts
#!/bin/bash
# The application will work only if it binds to
# $OPENSHIFT_INTERNAL_IP:8080
RUN_CMD="${OPENSHIFT_REPO_DIR}ringojs/bin/ringo"
RUN_ARGS="${OPENSHIFT_REPO_DIR}nocms/main.js serve ${OPENSHIFT_REPO_DIR}foo/"
RINGO_PID="${OPENSHIFT_DATA_DIR}ringo.pid"
RINGO_LOG="${OPENSHIFT_LOG_DIR}ringo.log"
(function() {
"use strict";
function fooBar(arg) {
console.log("first arg is ", arg);
}
function main() {
fooBar(this);
};