Skip to content

Instantly share code, notes, and snippets.

Daniel Risacher risacher

Block or report user

Report or block risacher

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
@risacher
risacher / OANDA-v20-nodejs-example.js
Created Feb 15, 2017
example of how to invoke OANDA V20 API from node.js
View OANDA-v20-nodejs-example.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 Jul 1, 2014
glue to make blessed (low-level API) work in browserify with term.js
View main.js
var blessed = require("blessed");
window.onload = function () {
var term = new Terminal({
cols: 80,
rows: 24,
useStyle: true,
screenKeys: true
});
@risacher
risacher / caronte-proxy.js
Last active Oct 4, 2017
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.
View caronte-proxy.js
"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 Dec 7, 2016
tty.js/static/user.js to enable context-menu pasting in Firefox/gecko with tty.js web terminal.
View user.js
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 Dec 30, 2015
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.
View nodejs unicode normalizaition.js
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 Dec 2, 2013
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.
View tty.js-static-user.js
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;
});
});
}
@risacher
risacher / iTunes-NodObjC-scriptingbridge.js
Last active Nov 13, 2018
NodObjC, iTunes, Scripting Bridge example
View iTunes-NodObjC-scriptingbridge.js
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')
You can’t perform that action at this time.