Skip to content

Instantly share code, notes, and snippets.

View TooTallNate's full-sized avatar

Nathan Rajlich TooTallNate

View GitHub Profile
@TooTallNate
TooTallNate / tsc-single-file.js
Created July 16, 2014 21:29
TypeScript single-file compiler
/**
* TypeScript single-file compiler:
*
* $ node tsc-single-file.js < input.ts > output.js
*
* Avoids TypeScript attempting to compile an entire "project",
* so that a proper `make` target can be written.
*/
@TooTallNate
TooTallNate / sweet_assert.js
Created July 16, 2014 05:26
C-style assert() function for sweet.js, which include the assertion code in the Error object (as opposed to the calculated result). Similar to: https://github.com/visionmedia/better-assert
macro assert {
rule {($test ...)} => {
if (!($test ...)) {
throw new Error('AssertionError: ' + #{ $test ... });
}
}
}
var foo = 100;
var utility = ffi.Library('utility', {
'tesJson': ['void', ['string']]
});
var obj = {'1': 'one', '2': 'two'};
utility.tesJson(JSON.stringify(obj));
@TooTallNate
TooTallNate / test.c
Last active August 29, 2015 14:02
dlfcn load printf from the current process
/* Compile:
* Unix/OSX: gcc -o test test.c -ldl
* Windows via dlfcn-win32: cl.exe /I dlfcn-win32 dlfcn-win32\dlfcn.c test.c /Fetest.exe
*/
#include <dlfcn.h>
#include <stdio.h>
int main () {
void *handle, *symbol;
@TooTallNate
TooTallNate / example.html
Last active August 29, 2015 14:01
wpcom.js example
<script src="wpcom.js"></script>
<script>
// create a client WPCOM instance
var wpcom = WPCOM();
// retrieve a listing of the most recent
// 5 posts on "en.blog.wordpress.com"
wpcom
.site('en.blog.wordpress.com')
.postsList({ number: 5 }, function(err, data) {
var $ = require('NodObjC');
$.import('Cocoa');
var installNSBundleHook = function() {
var cls = $.NSBundle;
if (cls) {
var bundleIdentifier = cls.getInstanceMethod('bundleIdentifier');
bundleIdentifier.setImplementation(function(val) {
@TooTallNate
TooTallNate / starwars.js
Created May 9, 2014 17:38
A little script to play the ASCII Star Wars, but with a hidden cursor, since over `telnet(1)` the cursor remains visible which is annoying
#!/usr/bin/env node
/**
* A little script to play the ASCII Star Wars, but with a hidden cursor,
* since over `telnet(1)` the cursor remains visible which is annoying.
*/
process.title = 'starwars'
var net = require('net')
@TooTallNate
TooTallNate / windows-path.js
Created March 13, 2014 15:38
Get Window's `path` node core module implementation, even on Unix
var vm = require('vm');
var pathCode = process.binding('natives').path;
var sandbox = {
process: {
env: process.env,
cwd: process.cwd,
platform: 'win32'
},
require: require,
@TooTallNate
TooTallNate / sync.js
Last active August 29, 2015 13:56
`npm owner` syncing tool. Invoke like: gnode sync.js tootallnate rauchg coreh
var exec = require('child_process').exec;
var suspend = require('suspend');
var resume = suspend.resume;
suspend.run(function*(){
// first determine the list of npm usernames to sync up to
var npmUsers = process.argv.slice(2);
@TooTallNate
TooTallNate / 0.11.10 output
Last active January 4, 2016 06:49
TLS over TLS HTTP request. Works in node v0.11.9, throws "Error: stream.push() after EOF" on v0.11.10. `git-bisect` says: 1e066e4a4a88f97af865d965f104b5fe8136797f is the first bad commit
HTTP 33749: agent.request { agent:
{ domain: null,
_events: {},
_maxListeners: undefined,
callback: [Function: connect],
secureProxy: true,
secureEndpoint: true,
proxy:
{ protocol: 'https:',
slashes: true,