View gist:404593
// Adds a 'fitTextToWidth' function. Which essentially accepts a String and | |
// an Number (int) parameters. The String is a long string of text (i.e. | |
// dialoge in a RPG) and adds '\n' characters throughout the String. | |
// | |
// The placement of '\n' characters is determined by the second param, which | |
// should be the maximum width of a single line of text. | |
// | |
// Depends on Prototype's Language extensions ($w, Enumberable, etc.). Meant | |
// to be used with my Simple Game Framework. |
View anotherScript.js
// If no exception is passed into 'getScriptName', it will only | |
// retrieve the URL of the script where 'getScriptName' is defined. | |
// In order to get the URL of a different script file, you must | |
// pass an exception generated in this script file to 'getScriptName'. | |
try { | |
(0)(); | |
} catch(ex) { | |
getScriptName(ex, onScriptNameKnown); | |
} |
View webfont-manual.js
webfont.DomHelper.prototype.setCssStyle = function(styleNode, body) { | |
if (styleNode.styleSheet) { | |
styleNode.styleSheet.cssText = body; | |
} else { | |
styleNode.appendChild(this.document_.createTextNode(body)); | |
} | |
return styleNode; | |
} | |
/** |
View redir.js
var http = require('http'); | |
var r = http.createClient(80, 'pri.kts-af.net'); | |
var request = r.request('GET', '/redir/index.pls?esid=cb07887ce881c6164c3ae52a58c55361&url_no=1&client_id=7&uid=68efed4d03ec7e45fd3978262c107180&clicksrc=xml', { | |
'Host': 'pri.kts-af.net' | |
}); | |
request.on('response', function (response) { | |
console.log('STATUS: ' + response.statusCode); | |
}); |
View upnp.js
/* node UPNP port forwarding PoC | |
This is a simple way to forward ports on NAT routers with UPNP. | |
This is a not-for-production hack that I found useful when testing apps | |
on my home network behind ny NAT router. | |
-satori | |
usage: |
View getip.js
var child_process = require("child_process"); | |
function getIPs (cb) { | |
child_process.exec("ifconfig -a", function (er, o) { | |
if (er) return cb(er); | |
cb(null, o.match(/inet (?:addr:)?([0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3})/g).map(function (i) { | |
return i.replace(/^inet (?:addr:)?/, ''); | |
})); | |
}) | |
} |
View netStreamDump.js
var port = 8080; | |
require('net').createServer(function(stream) { | |
var id = Date.now(); | |
var filename = stream.remoteAddress + '.' + id + '.dump'; | |
var dumpStream = require('fs').createWriteStream(filename); | |
dumpStream.on('close', function() { | |
console.error('File "' + filename + '" closed'); | |
}); | |
stream.on('timeout', function() { | |
console.error('Closing connection id ' + id + ', due to inactivity (timeout after 5 seconds)'); |
View spawn-response.js
var spawn = require('child_process').spawn; | |
var http = require('http'); | |
http.createServer(function (request, response) { | |
response.writeHead(200, { | |
'Content-Type': 'text/plain', | |
'Connection':'close', | |
'Transfer-Encoding':'identity' // 'chunked' can't be used unfortunately | |
// since the child_process won't know how |
View iphone4.2-node-configure
#! /bin/bash | |
# | |
# Program : iphone4.2-node-configure | |
# Authors : Nathan Rajlich (nathan@tootallnate.net) | |
# Michael Aaron Safyan (michaelsafyan@gmail.com) | |
# Synopsis : This program runs the "configure" script for Node.js. | |
# An install prefix of "/opt/iphone-4.2/" is used. | |
unset CPATH |
OlderNewer