Skip to content

Instantly share code, notes, and snippets.

View risacher's full-sized avatar

Daniel Risacher risacher

View GitHub Profile
@risacher
risacher / OANDA-v20-nodejs-example.js
Created February 15, 2017 19:30
example of how to invoke OANDA V20 API from node.js
"use strict";
const oandaV20 = require('@oanda/v20/context');
const fs = require('fs');
var ctx = new oandaV20.Context('api-fxpractice.oanda.com', 443, true, "demo");
var key = fs.readFileSync('api.key', {encoding: 'utf8'});
//remove any bad chars (e.g. the trailing newline)
key = key.replace(/[^0-9a-fA-F-]/g, "");
console.log(key);
@risacher
risacher / main.js
Created July 1, 2014 02:23
glue to make blessed (low-level API) work in browserify with term.js
var blessed = require("blessed");
window.onload = function () {
var term = new Terminal({
cols: 80,
rows: 24,
useStyle: true,
screenKeys: true
});
@risacher
risacher / iTunes-NodObjC-scriptingbridge.js
Last active November 13, 2018 16:50
NodObjC, iTunes, Scripting Bridge example
var util = require('util');
require('NodObjC/global');
framework('ScriptingBridge');
var iTunes = SBApplication('applicationWithBundleIdentifier',
NSString('stringWithUTF8String', 'com.apple.iTunes'));
if (!iTunes('isRunning')) {
console.log('iTunes is not running');
iTunes('run')
@risacher
risacher / caronte-proxy.js
Last active October 4, 2017 12:38
An example of a reverse proxy server written using the caronte branch of node-http-proxy. I dumped node-http-proxy for nginx when it stopped supporting websockets under node 0.10.x.This version seems adequate to replace nginx again.
"use strict";
var fs = require('fs'),
http = require('http'),
https = require('https'),
util = require('util'),
httpProxy = require('http-proxy'),
proxyTable = require('./proxy-table.js'); // proxy-table from the pre-caronte node-http-proxy
var routes_path = "routes.json";
@risacher
risacher / user.js
Last active December 7, 2016 17:47
tty.js/static/user.js to enable context-menu pasting in Firefox/gecko with tty.js web terminal.
var on = window.Terminal.on;
var isGecko = navigator.userAgent.indexOf('WebKit')==-1 && navigator.product == 'Gecko';
var isChromium = window.chrome;
// replace bindPaste with a variant that:
// 1. doesn't set contentEditable back to 'inherit'
// 2. replaces newlines with carriage returns in the clip
// 3. moves the caret (i.e. the contentEditable cursor) out of sight.
window.Terminal.bindPaste = function(document) {
@risacher
risacher / nodejs unicode normalizaition.js
Last active December 30, 2015 05:19
nodejs code demonstrating how Unicode strings from the same source can get changed so they are not the same, and how to renormalize then for comparison.
var unorm = require('unorm');
// These strings appear to be the same, but are NOT!
// String 1 is from a [track][location][path] extracted with Scripting Bridge from iTunes on Mac running an HFS+ filesystem
// String 2 is a path from an HFS+ filesystem mounted on Linux, then stored in an SQLite3 TEXT field.
// The file String 1 was derived from was copied from the file String 2 was derived from using rsync.
// Both strings then printed in Terminal.app and pasted into Emacs.
// Demonstration that two strings that appear the same might not be, even when they came from the same place originally.
@risacher
risacher / tty.js-static-user.js
Created December 2, 2013 18:08
Example of how to use the user.js file in tty.js, to do something somewhat useful. This appends the io.socket transport type into the help text. I use this to know whether I've got websockets actually working on any given day.
if (window.tty) {
tty.on('open', function() {
var tty = window.tty;
window.tty.socket.on('connect', function() {
console.log('connect ',window.tty.socket.socket.transport.name);
document.getElementById('help').innerHTML += "<p>" + window.tty.socket.socket.transport.name;
});
});
}