Skip to content

Instantly share code, notes, and snippets.

Invading spaces

Nathan Friedly nfriedly

Invading spaces
Block or report user

Report or block nfriedly

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View callback-to-promise.js
function getData(callback) {
setTimeout(() => callback("hi"), 10);
function render(promiseData) {
promiseData.then(data => console.log("data"));
// wrapper around getData() to make it return a promise
function getDataPromise() {
View function-scope.js
a = { note: "I'm global" };
function foo(b) {
// b is scoped to this function, but currently points to the same object as a
b === a; // => true
b = { note: "I'm not global" };
// now b points to a new object
b !== a; // => true
nfriedly / dsgnwrks-instagram-importer-hooks.php
Created Sep 19, 2018
Plugin to format WordPress posts created byt the DsgnWrks Instagram Importer
View dsgnwrks-instagram-importer-hooks.php
Plugin Name: DsgnWrks Instagram Importer Hooks
Plugin URI:
Description: Improvements to the Instagram Importer
Author URI:
Author: nfriedly
Version: 0.0.0
nfriedly / stt-ws-transaction-id.js
Last active Mar 3, 2017
Extract transaction ID from IBM Watson Node.js SDK Speech to Text RecognizeStream (WebSocket)
View stt-ws-transaction-id.js
'use strict';
const SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1');
require('dotenv').config({silent: true}); // optional, loads credentials from a .env file
const fs = require('fs');
const speech_to_text = new SpeechToTextV1({
// defaults to env properties if these are unset
nfriedly / WatsonSTTWebsocketExample.cs
Last active Nov 20, 2018
C# example of streaming Watson Speech to Text results over a WebSocket
View WatsonSTTWebsocketExample.cs
// Note: The official .net SDK is in progress. It doesn't support streaming Speech to Text at the time of writing,
// but it will soon. Please check it out before using this code.
using System;
using System.Net.WebSockets;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Threading;
nfriedly / 1
Last active Jun 25, 2017
How much are verizon "smart rewards" points worth?
View 1

How much are verizon "smart rewards" points worth?

TLDR: Each point is worth about 0.012¢ - 0.109¢ ($0.00012 - $0.00109) depending on what you want and how many you have. The more you have, the more they're worth, but what you get also makes a big difference.

I just noticed that verizon has a rewards program, and so I spent a few minutes trying to work out approximately how much my accrued 74,710 points were worth. There are a few different ways to spend the points, but the gift card auctions seemed like one of the most straightforward ways of getting a real-world value. Helpfully, verizon will show you all past auctions on a single (huge) page, and they even include a copy of jQuery for easy data scraping!

Here's a quick one-liner that you can paste into the console to reduce the page to a single chunk of JSON (

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 / mainIoTF.lua
Last active Oct 28, 2016
Connect ESP8266 to IBM IoT Foundation and publish data via MQTT (NodeMCU Firmware)
View mainIoTF.lua
-- see for more information
orgID = "quickstart" -- IoT Foundation organization ID replace this with your own after creating an IoT service in bluemix
broker = "" -- IP or hostname of Quickstart IoTF service
mqttPort = 1883 -- MQTT port (default 1883)
userID = "" -- optional. Set to "use-token-auth" for token auth
userPWD = "" -- optional. Put token here for token auth
macID= wifi.sta.getmac():gsub('-','') -- set this manually if needed. Just hex digits, no collons/spaces/dashes/etc.
clientID = "d:quickstart:esp8266:"..macID -- Device ID
count = 0 -- Test number of mqtt_do cycles
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 / 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;
You can’t perform that action at this time.