if you want to log the call parameters for function xyz, add this is the first line of xyz:
function xyz(p1, p2) {
debugFunctionCall('xyz', arguments);
...
}
then if you call
var os = require('os'); | |
var getMyIPs = function() { | |
var ips = {}; | |
var ifaces = os.networkInterfaces(); | |
var onDetails = function(details) { | |
if (details.family === 'IPv4') { | |
ips[ dev ] = details.address; | |
} |
var removeCycles = function(o) { | |
var seen = []; | |
var s = JSON.stringify(o, function(k, v) { | |
if (v !== null && typeof v === 'object') { | |
if (seen.indexOf(v) !== -1) { | |
//return; | |
v = '[removed]'; | |
} | |
else { |
var ctx = this; // this can be skipped if you don't care about the context | |
var argsL = arguments.length; | |
var args = new Array(argsL); // optimizable arguments-to-array | |
for(var i = 0; i < argsL; ++i) { | |
args[i] = arguments[i]; | |
} |
var listToArr = function(lst) { | |
var l = lst.length; | |
var arr = new Array(l); // optimizable *list-to-array | |
for (var i = 0; i < l; ++i) { | |
arr[i] = lst[i]; | |
} | |
return arr; | |
}; |
if you want to log the call parameters for function xyz, add this is the first line of xyz:
function xyz(p1, p2) {
debugFunctionCall('xyz', arguments);
...
}
then if you call
Features:
Relay.fetch(graphqlQuery)
returns subscribtion that could change over time by mutation queries.Relay.update(m: UpdateMutation)
optimistically updates resource in all previous queries that contains updated resource.Relay.update(m: DeleteMutation)
optimistically deletes resource from all previous queries that contains deleted resource.Relay.update(m: CreateMutation)
pessimistically creates resource and executes again all previous queries.id
key in graphql response explained as resources.
Arrays, objects without id
and scalars explained as static properties./* For Node.js - resolve a chain of HTTP redirects | |
Uses getResponse() from http://gist.github.com/399276 | |
Example: resolveHttpRedirects('http://ow.ly/1Kn4j', function(url) { sys.puts(url) }); | |
*/ | |
function resolveHttpRedirects(url, callback, maxnum) { | |
maxnum = maxnum || 3; | |
var count = 0; | |
function next(url) { | |
getResponse(url, function(response) { |
/* For Node.js - deal with some of the boilerplate involved in HTTP GET requests */ | |
var http = require('http'), | |
urlmod = require('url'); | |
function getResponse(url, callback) { | |
var parsed = urlmod.parse(url); | |
var port = parseInt(parsed.port || '80', 10); | |
var client = http.createClient(port, parsed.hostname); | |
var path = parsed.pathname; |
http://jsperf.com/another-memoization-comparison | |
// underscore.js memoize | |
function memoize1(func) { | |
"use strict"; | |
var memo = {}; | |
var slice = Array.prototype.slice; | |
return function() { | |
var key = "" + slice.call(arguments); | |
return (key in memo) ? memo[key] : (memo[key] = func.apply(this, arguments)); |
#!/usr/bin/env phantomjs | |
var system = require('system'); | |
var text = encodeURIComponent(system.stdin.read()); | |
var url = "http://translate.google.com/#auto/en/" + text; | |
var page = require('webpage').create(); | |
page.settings.userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0'; | |
page.onConsoleMessage = function (msg) { |