Skip to content

Instantly share code, notes, and snippets.

@nicokruger
nicokruger / async-better.js
Created February 29, 2012 07:30
async-better
before(function (done) {
server.server(options, function (s, db, providers) {
synchelper.waitForAll(
function () {
s.listen();
done();
},
function (callback) { db.notification.remove({}, callback); },
function (callback) { providers.provider1.insertBulk([item1, item2, item3], callback); },
function (callback) { providers.provider2.insertBulk([item1, item2, item3], callback); },
@nicokruger
nicokruger / synchelper.js
Created February 29, 2012 07:21
synchelper-test.js
ar _ = require("underscore"),
assert = require("assert"),
synchelper = require("../js/synchelper.js");
describe("Sync helper", function () {
it("should preserve the arguments", function (done) {
synchelper.waitForAll(
done,
function (callback) {
callback(1);
@nicokruger
nicokruger / synchelper.js
Created February 29, 2012 07:16
synchelper
var _ = require("underscore");
/**
* First argument is the callback to call when all are done
* all other callbacks are functions of the form
* function (callback, ...) { }
* and must call callback when they are done
* the ... will be any additional parameters from the previous step as
* the first parameter of all functions is partially applied to be the callback
* on creation of sequence.
@nicokruger
nicokruger / async-sync-pattern.js
Created February 29, 2012 07:13
async-sync-pattern
var actions = [
function () {
/* code for step 1 */
callback();
}, function () {
/* code for step 2 */
callback();
}, function () {
/* code for step 3 */
callback();
@nicokruger
nicokruger / async-callback-bad.js
Created February 29, 2012 07:09
async-callback-bad
before(function (done) {
server.server(options, function (s, db, providers) {
//clear db and add a test user - "testuser"
db.user.remove({}, function () {
db.notification.remove({}, function () {
providers.provider1.insertBulk(item1, item2, item3],
function (err, result) {
providers.provider2.insert([item1, item2, item3]
function (err, result) {
providers.provider3.insert([item1, item2, item3]
@nicokruger
nicokruger / jenkins-jobcreate.py
Created February 23, 2012 13:53
jenkins-jobcreate
import tempfile
import os
import libxml2
RECIPIENTS="builds@rorotika.com"
for line in [x.strip() for x in open("projects.list").readlines()]:
GIT_URL = "git://git.rorotika/" + line
GROUP_ID = "A"
ARTIFACT_ID = "A"
@nicokruger
nicokruger / Guardfile
Created February 23, 2012 07:45
Guardfile for auto test running
guard 'shell' do
watch(%r"tests/.*test\..*") {|m|
`node bgtests.js`
}
watch(%r"js/.*js") {|m|
`node bgtests.js`
}
end
@nicokruger
nicokruger / bgtest-runner-mocha-libnotify.js
Created February 23, 2012 07:44
bgtest-runner-mocha-libnotify
var exec = require("child_process").exec,
spawn = require("child_process").spawn,
command = "mocha -R json tests/*-test.js",
_ = require("underscore");
var child = exec(command, function (error, stdout, stderr) {
var output, STATUS, ICON, status;
if (stderr) {
STATUS="BROKEN";
@nicokruger
nicokruger / curl.sh
Created February 22, 2012 05:49
Curls
curl -d "username=c&password=c&email=c" http://localhost:8080/admin/add # post data
@nicokruger
nicokruger / vmware.sh
Created February 1, 2012 05:41
vmware re-install modules
vmware-modconfig --console --install-all