Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Rajlich TooTallNate

View GitHub Profile
@TooTallNate
TooTallNate / transcode.js
Last active Nov 17, 2020
Transcode an OGG Vorbis audio file to an MP3 using node-ogg, node-vorbis and node-lame
View transcode.js
/**
* Module dependencies.
*/
var fs = require('fs');
var ogg = require('ogg');
var lame = require('lame');
var vorbis = require('vorbis');
@TooTallNate
TooTallNate / objc.js
Created Jul 13, 2011
Experimentations with node-ffi
View objc.js
var ffi = require('node-ffi')
, objc = new ffi.Library(null, {
'objc_getClass': [ 'pointer', [ 'string' ] ]
, 'class_getName': [ 'string', [ 'pointer' ] ]
, 'sel_registerName': [ 'pointer', [ 'string' ] ]
, 'sel_getName': [ 'string', [ 'pointer' ] ]
, 'objc_msgSend': [ 'pointer', [ 'pointer', 'pointer' ] ]
})
// The problem with libffi and C functions that accepts varargs is that we
// have to create new wrappers for each different argument and return value
@TooTallNate
TooTallNate / .gitignore
Created Jul 9, 2011
low-level objc runtime apis
View .gitignore
*
!*.m
!Makefile
@TooTallNate
TooTallNate / repl-client.js
Created Mar 26, 2012
Running a "full-featured" REPL using a net.Server and net.Socket
View repl-client.js
var net = require('net')
var sock = net.connect(1337)
process.stdin.pipe(sock)
sock.pipe(process.stdout)
sock.on('connect', function () {
process.stdin.resume();
process.stdin.setRawMode(true)
@TooTallNate
TooTallNate / http-error.js
Created Aug 3, 2016
HTTPError class for JavaScript HTTP errors
View http-error.js
import { format } from 'url';
import { STATUS_CODES } from 'http';
import uppercamelcase from 'uppercamelcase';
class HTTPError extends Error {
constructor(code, message, extras) {
super(message || STATUS_CODES[code]);
if (arguments.length >= 3 && extras) {
Object.assign(this, extras);
}
@TooTallNate
TooTallNate / bbs.js
Created Mar 16, 2012 — forked from substack/bbs.js
Running a node.js REPL over `curl`
View bbs.js
/**
* Requires node v0.7.7 or greater.
*
* To connect: $ curl -sSNT. localhost:8000
*/
var http = require('http')
, repl = require('repl')
, buf0 = new Buffer([0])
@TooTallNate
TooTallNate / mouse.js
Created Jan 30, 2012
Enable "mouse reporting" with Node.js
View mouse.js
// Based on:
// http://groups.google.com/group/nodejs-dev/browse_thread/thread/a0c23008029e5fa7
process.stdin.resume();
process.stdin.on('data', function (b) {
var s = b.toString('utf8');
if (s === '\u0003') {
console.error('Ctrl+C');
process.stdin.pause();
@TooTallNate
TooTallNate / test.js
Created Oct 1, 2012
This gist has been moved to `ref-wchar` module on npm, see: https://github.com/TooTallNate/ref-wchar
View test.js
var ffi = require('ffi')
var ref = require('ref')
var assert = require('assert')
var wchar_t = require('./wchar_t')
// now we can create our FFI'd "wcslen()" function
var libc = ffi.Library('libc', {
wcslen: [ 'size_t', [ wchar_t ] ],
wcstod: [ 'double', [ wchar_t, ref.refType(wchar_t) ] ]
})
@TooTallNate
TooTallNate / starwars.js
Created Apr 4, 2012
NodeJS script to play ACSII Star Wars (using a hidden cursor)
View starwars.js
/**
* A little script to play the ACSII Star Wars, but with a hidden
* cursor, since over telnet the cursor remains visible
*/
var net = require('net')
var cursor = require('ansi')(process.stdout)
// connect to Star Wars server
@TooTallNate
TooTallNate / endianness.js
Created Feb 10, 2013
Get host machine endianness using JavaScript Typed Arrays (polyfill for `os.endianness()` in node.js)
View endianness.js
function endianness () {
var b = new ArrayBuffer(4);
var a = new Uint32Array(b);
var c = new Uint8Array(b);
a[0] = 0xdeadbeef;
if (c[0] == 0xef) return 'LE';
if (c[0] == 0xde) return 'BE';
throw new Error('unknown endianness');
}
You can’t perform that action at this time.