Skip to content

Instantly share code, notes, and snippets.

View tjfontaine's full-sized avatar

Timothy J Fontaine tjfontaine

View GitHub Profile
$ kubessh node.info/external.ipaddress 192.168.2.2
If you don't see a command prompt, try pressing enter.
[root@k8s-worker-ad1-0 /]# exit
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
kubessh-tjfontai-15628 1/1 Running 0 7s
#!/usr/bin/env osascript -l JavaScript
function pathjoin() {
var arr = Array.prototype.slice.call(arguments);
var dest = $.NSString.pathWithComponents(ObjC.wrap(arr));
return ObjC.unwrap(dest);
}
var HOMEDIR = ObjC.unwrap($.NSHomeDirectory());
@tjfontaine
tjfontaine / queue.js
Created February 9, 2015 19:33 — forked from Jks15063/queue
var queue = async.queue(function(task, callback) {
var ObjectId = mongoose.Types.ObjectId
var query = task.query
var update = task.update
var defer = task.defer
query._id['$in'] = _.map(query._id['$in'], ObjectId)
var queryStream = scenarios.find(query).stream()
queryStream.pipe(streamWorker).on('end', function(foo) {
var async = require('async'),
dgram = require('dgram');
var client = dgram.createSocket('udp4');
var totalTimeTaken = 0;
var iterations = +process.argv[2];
var completed = 0;
console.log('doing', iterations, 'iterations');
@tjfontaine
tjfontaine / deferrals-in-nodejs.md
Last active February 16, 2016 06:49
Description of Deferrals in Node.js

There are four kinds of deferral mechanisms in Node.js:

  • setTimeout
  • setInterval
  • setImmediate
  • process.nextTick

setTimeout and setInterval are quite familiar to those used to JavaScript in the browser and their semantics are fairly well understood. They return opaque values that can be passed to their clear counterparts, and have been around forever. setImmediate is a newer construct and its adoption in the browser is not very wide, and nextTick is a creation solely unto Node.js. The latter two are mechanisms to queue a callback in the short future, such that currently executing JavaScript may continue. If you're used to trying to do this pattern in the browser you may be used to using something like setTimeout(fn, 0).

If Node.js actually exposed the idea of a turn of the event loop, you would be expecting the scheduled callback to run at the end of the current loop, or the start of the next -- though from the perspective of your application there isn't really a difference. In

#!/bin/bash
# This will add symbol tables back into binaries (but not debug information)
# For this to work you must first complete the following steps:
# https://wiki.ubuntu.com/DebuggingProgramCrash#Non-built-in_debug_symbol_packages_.28.2A-dbgsym.29
# Then pass the directory of objects you want to recombine
set -e
if [ -z $1 ] || [ ! -d $1 ];
var d = require('domain').create();
d.run(function() {
process.nextTick({
throw new Error("hello");
});
});
d.on('error', function(e) {
assert.strictEqual(e.message, 'hello');
@tjfontaine
tjfontaine / buffer.md
Last active August 29, 2015 14:08
mdb node buffer pointer

For a given address, determine it is a Buffer (or use ::findjsobjects -c Buffer | ::findjsobjects to find a given buffer)

> 89f46b41::jsprint
{
    length: 11,
    parent: {
        length: 8192,
        used: 24,
    },
diff --git a/test/common.js b/test/common.js
index cf90634..92a4183 100644
--- a/test/common.js
+++ b/test/common.js
@@ -210,3 +210,11 @@ exports.mustCall = function(fn, expected) {
return fn.apply(this, arguments);
};
};
+
+exports.hasMultiLocalhost = function hasMultiLocalhost() {
* thread #1: tid = 0x0000, 0x000000010051b5ec node`uv_fs_readdir_next(req=0x0000000100f2a908, ent=0x00007fff5fbf71e8) + 34 at uv-common.c:459, stop reason = signal SIGSTOP
* frame #0: 0x000000010051b5ec node`uv_fs_readdir_next(req=0x0000000100f2a908, ent=0x00007fff5fbf71e8) + 34 at uv-common.c:459
frame #1: 0x00000001004d22e8 node`node::After(req=0x0000000100f2a908) + 470 at node_file.cc:216
frame #2: 0x000000010051a0fa node`uv__work_done(handle=<unavailable>) + 175 at threadpool.c:236
frame #3: 0x000000010051b87f node`uv__async_event(loop=<unavailable>, w=<unavailable>, nevents=<unavailable>) + 62 at async.c:89
frame #4: 0x000000010051b9f2 node`uv__async_io(loop=0x00000001008e20c0, w=0x00000001008e2330, events=<unavailable>) + 136 at async.c:165
frame #5: 0x0000000100529445 node`uv__io_poll(loop=0x00000001008e20c0, timeout=<unavailable>) + 1491 at kqueue.c:232
frame #6: 0x000000010051be62 node`uv_run(loop=0x00000001008e20c0, mode=UV_RUN_ONCE) + 267 at core.c:325
frame #7: 0x0000