Skip to content

Instantly share code, notes, and snippets.

View morganrallen's full-sized avatar

Morgan 'ARR!' Allen morganrallen

  • Allen Industries
  • Oakland
View GitHub Profile
@morganrallen
morganrallen / sphero-bridge.js
Created November 21, 2013 03:01
left overs from NKO4
Math.TAU = Math.PI + Math.PI;
const TO_DEGREES = 180 / Math.PI;
const TO_RADIANS = Math.PI / 180;
function headingFromDelta(x, y) {
var a = Math.atan2(y, x);
if(a < 0) a = (a + Math.PI) + Math.PI;
// janky rotation by 90deg
a = Math.round(a * TO_DEGREES);
@morganrallen
morganrallen / README.md
Last active December 28, 2015 17:59
Demonstrates possible bug in child_process

Demonstrates possible bug in child_process

running node main.js will result in process.stdin.setRawMode being undefined and tty.setRawMode barfing 'Error: can't set raw mode on non-tty'

running node child-using-stdin.js will give the function as expected and give deprecation message rather than barf.

@morganrallen
morganrallen / gist:6274144
Created August 19, 2013 21:00
Create repeating function. Takes arguments from first call and repeat on each call there after.
function repeater(fn) {
var args = false;
return function() {
if(args === false) args = arguments;
return fn.apply(this, args);
}
};
function add(a, b) {
Project.Collections.MappedAreas = Backbone.Collection.extend({
model: {
"Model[LatLng, Geopoints[LatLng]]": {
Model: Backbone.Model,
Geopoints: Project.Collections.Geopoints,
LatLng: Project.Models.LatLng
}
}
});
@morganrallen
morganrallen / gist:5623956
Last active December 17, 2015 14:19
Auto compile LESS to CSS on write. Also will allow you to compile a parent script by putting /* lessc-parent: "main" */ on the top line
function LessToCss()
let match = matchstr(getline(1), '...lessc-parent: "\zs.\{-}\ze"')
if strlen(match) > 0
let current_file = match . ".less"
let filename = match
el
let current_file = shellescape(expand('%:p'))
let filename = shellescape(expand('%:r'))
endif
@morganrallen
morganrallen / garmin.js
Created May 15, 2013 20:36
Open Stava upload new content page when Garmin Edge 305 is plugged in. NodeJS, node-udev
#!/usr/bin/env node
var udev = require("udev");
var monitor = udev.monitor();
monitor.on("add", function(device) {
// change vendor and model IDs to match your device if not Garmin Edge 305
if(device.ID_VENDOR_ID === "091e" && device.ID_MODEL_ID === "0003") {
require("child_process").spawn("xdg-open", ["http://app.strava.com/upload/garmin_new"], {
env: process.env
@morganrallen
morganrallen / package.json
Created November 10, 2012 14:14
Nodejitsu deploy errors
info: Welcome to Nodejitsu nko3-derpatron
info: jitsu v0.10.5, node v0.8.2
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Analyzing application dependencies in node server/server.js
warn: Local package version appears to be old
warn: The package.json version will be incremented automatically
warn: About to write /Users/morganallen/devel/NKO3/derpatron/package.json
warn: Using '*' as a version for dependencies may eventually cause issues
warn: Use specific versions for dependencies to avoid future problems
@morganrallen
morganrallen / relative-color.js
Created November 7, 2012 14:37
Relative RGB
function RGB2HEX(s) {
return [ parseInt(s.substr(0,2), 16), parseInt(s.substr(2,2), 16), parseInt(s.substr(4,2), 16) ];
}
function ItoS(i) {
return i === 0 ? "00" : i.toString(16);
}
function HEX2RGB(s) {
return ItoS(s[0]) + ItoS(s[1]) + ItoS(s[2]);
var jsdom = require("jsdom"),
fs = require("fs");
fs.readFile("test.html", function(err, content) {
if(err) throw err;
var doc = jsdom.jsdom(content, jsdom.defaultLevel);
doc.addEventListener("load", function() {
console.log(arguments);
<html>
<head>
<script type="text/javascript" src="zeroth.js"></script>
</head>
<body>
<script>
console.log("First script");
</script>
<script>
var s = document.createElement("script");