Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / child-test.js
Created August 22, 2012 16:19
Node.js: I can't seem to capture a child process's stdout and stderr in Windows.
var parent = function() {
var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [process.argv[1], 123]);
var stdout = '';
var stderr = '';
child.stdout.on('data', function(buf) {
console.log('[STR] stdout "%s"', String(buf));
stdout += buf;
});
child.stderr.on('data', function(buf) {
@cowboy
cowboy / when.js
Created August 20, 2012 01:37
jQuery .when example (I don't think I need it)
// Using the $.when() method, we can create an object that behaves similarly
// to Deferred objects, but for COMBINATIONS of Deferred objects.
//
// The $.when() method creates a Deferred object that is resolved or rejected
// when all the Deferred objects passed into it are resolved or rejected.
var getPromise = function(name) {
var dfd = $.Deferred();
var num = Math.floor(Math.random() * 1000);
setTimeout(function() { dfd.resolve(name + ": " + num); }, num);
return dfd.promise();
@cowboy
cowboy / test.js
Created August 19, 2012 15:30
For my jQuery class.
$("#target").html("<h2 class=well>OMG AWESOME CROSS-DOMAIN TEST JQUERYIES</h2>");
@cowboy
cowboy / ajax-transport.js
Created August 17, 2012 12:25
jQuery: How can I create a catch-all Ajax transport?
// When I set up a json-specific transport...
$.ajaxTransport("json", function(options) {
console.log("json", options);
});
// The json options are logged.
$.getJSON("/foo");
// When I try to set up a catch-all transport...
@cowboy
cowboy / getLiveScriptOperator.js
Created August 12, 2012 15:55
LiveScript: language design?
// Re. the LiveScript <-! operator (et al)
// http://gkz.github.com/LiveScript/
function getLiveScriptOperator() {
var op = '';
for (var i = 0; i < 3; i++) {
op += String.fromCharCode(33 + Math.floor(15 * Math.random()));
}
return op;
}
@cowboy
cowboy / filter_subdir.sh
Created August 7, 2012 17:41
Make a new repo from a subdirectory of an original repo
# Please don't just RUN this. Do it step-by-step.
user=bocoup
orig_repo=training
new_repo=training-jquery
subdir=jquery-conference
# Pull down the original repo.
git clone [email protected]:$user/$orig_repo.git $new_repo
# Repo, I'm in you.
@cowboy
cowboy / commit-authors.txt
Created August 3, 2012 00:13
grunt commit authors
$ git log --format='%aN' | sort | uniq -c | sort -r
890 Ben Alman
16 Kyle Robinson Young
8 Scott González
7 Mickael Daniel
4 Jörn Zaefferer
3 tbranyen
3 Rick Waldron [email protected]
3 Jörn Zaefferer
3 Dan Heberden
@cowboy
cowboy / log.txt
Created July 31, 2012 11:31
#Node.js wtf
[07:19] drug_motor ([email protected]) joined the channel.
[07:19] <drug_motor> ops plz
[07:19] ryan_opper sets mode +o drug_motor
[07:20] drug_motor kicked aguai from the channel. (aguai)
[07:20] drug_motor kicked Aikar from the channel. (Aikar)
[07:20] drug_motor kicked aka from the channel. (aka)
[07:20] drug_motor kicked AlbireoX from the channel. (AlbireoX)
[07:20] _root_ kicked drug_motor from the channel. (mass kick, go sit in a corner)
[07:20] Aikar (~Raxkar@wikia/Aikar) joined the channel.
[07:20] mattgifford ([email protected]) left IRC. (Remote host closed the connection)
@cowboy
cowboy / child_exit_close_test.js
Created July 30, 2012 20:01
Node.js 0.8: trying to see a difference between child_process "exit" and "close" events
function parent() {
var n = 0;
var spawn = require('child_process').spawn;
var child = spawn(process.execPath, [module.filename, true]);
child.stdout.on('data', function(buf) {
n += String(buf).length;
});
@cowboy
cowboy / debounce-wrapper.js
Created July 30, 2012 18:29
for john k paul
var debounced = $.debounce(1000, orig);
var wrapper = function() {
// you have my permission to write whatever logic is useful to you here
if (arguments[0] === 'foo') {
orig.apply(null, arguments);
} else {
debounced.apply(null, arguments);
}
};