Skip to content

Instantly share code, notes, and snippets.

@chowey
chowey / bench.js
Created April 20, 2012 13:08
Benchmark str concatenation
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite,
a, b;
suite
.add('push', function () {
a = [];
for (var i = 0; i < 100; i++)
a.push('Text\n');
var Benchmark = require('benchmark'),
jade = require('../'),
fs = require('fs');
// Test cases
var cases = fs.readdirSync('cases').filter(function(file){
return ~file.indexOf('.jade');
}),
pretty = {},
@chowey
chowey / transact2.js
Created March 28, 2012 13:46
pg atomic transaction test 2
var pg = require('pg'),
path = require('path'),
Query = require(path.join(path.dirname(require.resolve('pg')), 'query'));
pg.Client.prototype.next = function (config, values, callback) {
//can take in strings or config objects
config = (typeof(config) == 'string') ? { text: config } : config;
if (this.binary && !('binary' in config)) {
config.binary = true;
}
@chowey
chowey / transact.js
Created March 28, 2012 13:17
pg atomic transaction test
var pg = require('pg');
var client = new pg.Client('pg://user:pass@127.0.0.1/postgres');
client.connect(function () {
client.query('CREATE TEMP TABLE foo (bar real)', function () {
for (var i = 0; i < 5; i++)
insertRandomNumber();
});
client.once('drain', function () {
client.query('SELECT bar FROM foo', function (err, results) {
@chowey
chowey / bench.js
Created February 23, 2012 14:37
Benchmark Multiline Stylus
var stylus1 = require('../node_modules/stylus'),
stylus2 = require('../cloned/stylus'),
Benchmark = require('benchmark'),
fs = require('fs');
fs.readFile('C:/node/cloned/stylus/test/cases/regression.127.styl', 'utf8', function (err, str) {
if (err) throw err;
var handler = function (err, css) {
if (err) console.error(err);
@chowey
chowey / syntax.js
Created February 18, 2012 22:32
Jade Syntax Checker
var jade = require('jade'),
runtime = require('jade/lib/runtime'),
spawn = require('child_process').spawn,
fs = require('fs');
function parse(str, filename){
var options = {filename: filename, compileDebug: true};
try {
// Parse
var parser = new jade.Parser(str, filename, options)
@chowey
chowey / Readme.md
Last active September 30, 2015 03:14
Movie Countdown with Greensock

Simple countdown using Greensock. You could add an "onComplete" to the Tweenlite to trigger an event when the countdown ends.

@chowey
chowey / child.js
Created January 18, 2012 03:33
Programmatically get a SyntaxError lineno from Node
var fn = '\n var o={a: "Hello";\n b:"World"};'
var child = require('child_process').spawn(process.execPath, ['-e', fn]);
child.stderr.setEncoding('utf8');
child.stderr.on('data', function (data) {
var errLines = data.split('\n');
var infoLine = errLines[1].split(':');
var descLine = errLines[4];
@chowey
chowey / fs_stub.go
Created May 15, 2015 18:09
In-Memory implementation for http.FileSystem
// http.FileSystem in-memory test stub
type TestOpener interface {
OpenAs(name string) http.File
}
type TestFileSystem TestDir
func (fs TestFileSystem) Open(name string) (http.File, error) {
@chowey
chowey / hash_test.go
Created July 25, 2014 05:39
Benchmark comparison of cryptographic hashes in Go
package main
import (
"crypto/md5"
"crypto/rand"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"testing"
)