Skip to content

Instantly share code, notes, and snippets.

Avatar
👾
Invading spaces

Nathan Friedly nfriedly

👾
Invading spaces
View GitHub Profile
@nfriedly
nfriedly / hack.sh
Created Apr 4, 2012 — forked from erikh/hack.sh
OSX For Hackers
View hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@nfriedly
nfriedly / fb_graph_aip_results.js
Created Jan 19, 2012
FB Graph API: ?ids=username,pagename&fields=name,picture looses picture field for page
View fb_graph_aip_results.js
// If you ask for a username before a pagename in the ?ids= Graph API,
// it looses the picture field for all pages.
// A few examples:
// http://graph.facebook.com/?ids=nfriedly&fields=picture,name works correctly:
{
"nfriedly": {
"name": "Nathan Friedly",
"id": "215902661",
@nfriedly
nfriedly / all_fixed.js
Created Jan 10, 2012
FB long graph query fix
View all_fixed.js
FB.ApiServer.flash = function(b, e, c, d, a){
if (!window.FB_OnXdHttpResult) window.FB_OnXdHttpResult = function(g, f) {
FB.ApiServer._callbacks[g](decodeURIComponent(f));
};
FB.Flash.onReady(function() {
if (b === 'graph') d.suppress_http_code = 1;
var h = FB.getDomain(b) + e,
f = FB.QS.encode(d);
if (c === 'get') {
if (h.length + f.length > 2000) {
@nfriedly
nfriedly / http-coap-spark-particle-forwarding-app.js
Last active Sep 17, 2015
Send arbitrary commands to a Particle Photon (new version of Spark Core) via express
View http-coap-spark-particle-forwarding-app.js
var express = require('express');
var app = express(),
var spark = require('spark');
var _ = require('lodash');
require('dotenv').load(); // reads particle username and password from a file named .env that you can .gitignore
var deviceName = "InternetButton"; // set this to the name of your device
// Login and retrive the device
@nfriedly
nfriedly / log-all-fs-writes.js
Last active Aug 29, 2015
Log all fs.write* operations with a stack trace in node.js
View log-all-fs-writes.js
// Stick this in the top of your main app.js/server.js/whatever file.
// Any time one of the below fs.* methods are called anywher in the app or dependencies,
// this code will log the details including the method, arguments, and a stack trace.
// It will then complete the write as normal.
var fs = require('fs');
['write','writeSync','writeFile','writeFileSync', 'appendFile', 'appendFileSync','createWriteStream'].forEach(function(fn){
fs['real'+fn] = fs[fn];
fs[fn] = function() {
var e = new Error();
@nfriedly
nfriedly / html-iconv-stream.js
Created Jul 1, 2015
iconv html stream decoder (reads charset from <meta> tag, uses it to decode document to utf8)
View html-iconv-stream.js
// buffers a stream of html untill it sees a charset meta tag (or opening <?xml tag with an encoding)
// then it creates an iconv-lite decoder for the charset and sends all data (the buffer and any future data) through it, emiting node.js-friendly utf8
// if it cannot find a charset by the time the </head> tag is reached, it gives up and just calls .toString() on each chunk hoping that it's in a format that node.js can read
// based on iconv-lite's decodeStream
// todo: clean this up, add some tests, and stick it on npm
// == Decoder stream =======================================================
function HTMLDecodeStream(options) {
this.buff = new Buffer([]);
this.isBuffering = true;
@nfriedly
nfriedly / index.js
Created May 7, 2015
streaming opus decoder
View index.js
var fs = require('fs');
var watson = require('watson-developer-cloud');
var ogg = require('ogg');
var opus = require('./opus_stream.js');
var wav = require('wav');
var Speaker = require('speaker');
var oggDecoder = new ogg.Decoder();
@nfriedly
nfriedly / log.txt
Created Oct 17, 2014
MiniCMS error
View log.txt
info: Welcome to DocPad v6.69.1 (local installation: c:\Users\IBM_ADMIN\watson-developer-cloud\node_modules\docpad)
notice: If everyone who saw this message donated $1/week, maintaining DocPad would become sustainable: http://docpad.org/donate
info: Contribute: http://docpad.org/docs/contribute
info: Plugins: eco, minicms, mongodb
info: Environment: development
info: Watching setup starting...
info: Watching setup
error: An error occured:
Error: The task [action runner ➞ watch] just completed, but it had already completed earlier, this is unexpected. State information is:
{ error:
You can’t perform that action at this time.