Skip to content

Instantly share code, notes, and snippets.

View TooTallNate's full-sized avatar

Nathan Rajlich TooTallNate

View GitHub Profile
@TooTallNate
TooTallNate / request-query.js
Created August 15, 2011 22:55
Example script of how `request` (and node) drops any `query` param passed to http.request()
var http = require('http')
, assert = require('assert')
, request = require('./')
, url = require('url')
, path = 'http://localhost/test'
http.createServer(function (req, res) {
assert.equal('/test?foo=bar', req.url)
res.end()
}).listen(0, function () {
var ffi = require('node-ffi')
, objc = new ffi.Library('libobjc', {
objc_msgSend: [ 'pointer', [ 'pointer', 'pointer', ] ]
, objc_getClass: [ 'pointer', [ 'string' ] ]
, sel_registerName: [ 'pointer', [ 'string' ] ]
// try/catch
, objc_begin_catch: [ 'pointer', [ 'pointer' ] ]
, objc_end_catch: [ 'void', [] ]
})
, NSObject = objc.objc_getClass('NSObject')
@TooTallNate
TooTallNate / ffi-objc-try-catch.diff
Created August 18, 2011 15:00
An example of adding Objective-C style @try/@catch support to node-ffi. Forkworthy?
diff --git a/src/ffi.h b/src/ffi.h
index fe29e71..770bc73 100644
--- a/src/ffi.h
+++ b/src/ffi.h
@@ -40,49 +40,49 @@ class Pointer : public ObjectWrap {
Pointer(unsigned char *ptr);
~Pointer();
- static void Initialize(Handle<Object> Target);
- static Handle<Object> WrapInstance(Pointer *inst);
@TooTallNate
TooTallNate / server.conf
Created August 18, 2011 19:40
Example of using `upstart` with a NodeJS server.
description "My NodeJS Server"
author "Nathan Rajlich"
# Upstart has nothing in $PATH by default
env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Keep the server running on crash or machine reboot
respawn
start on runlevel [23]
function Parent () {
this.blah = 'test';
}
function Child () {
}
Child.prototype = new Parent()
var instance = new Child()
From 47554e9443ba8882cfdb0008a1bb93a57d491270 Mon Sep 17 00:00:00 2001
From: Nathan Rajlich <nathan@tootallnate.net>
Date: Tue, 23 Aug 2011 10:39:23 -0700
Subject: [PATCH] Use Object.getPrototypeOf() on the object in the REPL tab-completion.
Some people use __proto__ to augment an Object's prototype after it's been created.
This patch helps make the "new" prototype properties visible if necessary.
This is also more consistent with the while logic below.
---
@TooTallNate
TooTallNate / Foundation.bridgesupport
Created August 28, 2011 18:29
Beautified BridgeSupport files, for my sanity...
<?xml version='1.0'?>
<signatures version="1.0">
<depends_on path="/System/Library/Frameworks/CoreFoundation.framework" />
<depends_on path="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework" />
<depends_on path="/System/Library/Frameworks/SystemConfiguration.framework" />
<depends_on path="/System/Library/Frameworks/Security.framework" />
<depends_on path="/System/Library/Frameworks/CoreServices.framework" />
<depends_on path="/System/Library/Frameworks/IOKit.framework" />
<struct name="NSAffineTransformStruct" type64="{_NSAffineTransformStruct=&quot;m11&quot;d&quot;m12&quot;d&quot;m21&quot;d&quot;m22&quot;d&quot;tX&quot;d&quot;tY&quot;d}" type="{_NSAffineTransformStruct=&quot;m11&quot;f&quot;m12&quot;f&quot;m21&quot;f&quot;m22&quot;f&quot;tX&quot;f&quot;tY&quot;f}" />
<struct name="NSDecimal" opaque="true" type="{_NSDecimal=&quot;_exponent&quot;b8&quot;_length&quot;b4&quot;_isNegative&quot;b1&quot;_isCompact&quot;b1&quot;_reserved&quot;b18&quot;_mant
@TooTallNate
TooTallNate / doctor.txt
Created August 31, 2011 16:53
The result of my `brew doctor`
Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libpng14.14.dylib
Unbrewed static libraries were found in /usr/local/lib.
From 5bc0ea9f3f1bff00f1a983ea47877d1bf0b1d1f3 Mon Sep 17 00:00:00 2001
From: Nathan Rajlich <nathan@tootallnate.net>
Date: Thu, 1 Sep 2011 11:18:29 -0700
Subject: [PATCH] Don't use the NODE_MODULE macro.
What's the point of this? Seems to work fine without it! And it seems some
strange setups don't have this macro defined anyways...
---
time.cc | 7 ++-----
1 files changed, 2 insertions(+), 5 deletions(-)
@TooTallNate
TooTallNate / plist.js
Created September 1, 2011 19:32
Creating a Plist file with NodObjC
var $ = require('./')
$.import('Foundation')
var pool = $.NSAutoreleasePool('alloc')('init')
var plist = $.NSMutableDictionary('alloc')('init')
plist('setValue', $._('val'), 'forKey', $._('key'))
// write out to a plist file
plist('writeToFile', $._('filepath.plist'), 'atomically', true)