Skip to content

Instantly share code, notes, and snippets.

View andrewrk's full-sized avatar

Andrew Kelley andrewrk

View GitHub Profile
function oncePerEventLoopFunc(fn){
var queued, cbs;
queued = false;
cbs = [];
return function(cb){
cbs.push(cb);
if (queued) {
return;
}
queued = true;
aoeu
function moveFile(source, dest, cb){
fs.rename(source, dest, function(err){
var ins, outs, had_error;
if (!err) {
return cb();
}
if (err.code !== 'EXDEV') {
return cb(err);
}
ins = fs.createReadStream(source);
var Plugin, fs, zipstream, path, safePath, express, findit, Download;
Plugin = require('../plugin');
fs = require('fs');
zipstream = require('zipstream');
path = require('path');
safePath = require('../futils').safePath;
express = require('express');
findit = require('findit');
module.exports = Download = (function(superclass){
Download.displayName = 'Download';

Query String

querystring.stringify(obj, [sep], [eq])

Serialize an object to a query string. Optionally override the default separator ('&') and assignment ('=') characters.

Example:

@andrewrk
andrewrk / gist:4119242
Created November 20, 2012 16:58
media man templates
"templates": {
// lydian audio processing
"b5eec8b0-2925-11e2-81c1-0800200c9a66": {
"original": {
"type": "store"
},
"waveform": {
"type": "waveform",
"settings": {
"width": 1800,
# compile with http://satyr.github.com/cup/
PROGRESS_TIME_REGEX = //
^ In:([\d.]+)% # progress
\s+ (\d\d):(\d\d):([\d.]+) # time that has been encoded
\s+ \[(\d\d):(\d\d):([\d.]+)\] # time left to encode
\s+ Out:([\d.\w]+) # file size of output
\s+ \[[\s|\-!=]+\] # clip meter
\s+ (?:Hd:([\d.]+))? # dunno wtf this is
\s+ Clip:(\d+) # clip count
\s* $
# What's easier to read?
add_submission(Submission.from_upload(user, upload)).tap do |submission|
publish('submission.uploaded', submission.to_hash)
end
# or
@andrewrk
andrewrk / .gitignore
Created December 16, 2012 20:54
mediablast server example
/node_modules
@andrewrk
andrewrk / output.txt
Created December 26, 2012 20:35
benchmarking a couple zfill implementations in node
zfill1
it took 149
zfill2
it took 629