Skip to content

Instantly share code, notes, and snippets.

Avatar

Morgan 'ARR!' Allen morganrallen

  • Allen Industries
  • Oakland
View GitHub Profile
View sphero-bridge.js
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 Dec 28, 2015
Demonstrates possible bug in child_process
View README.md

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 Aug 19, 2013
Create repeating function. Takes arguments from first call and repeat on each call there after.
View gist:6274144
function repeater(fn) {
var args = false;
return function() {
if(args === false) args = arguments;
return fn.apply(this, args);
}
};
function add(a, b) {
View gist:5760979
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 Dec 17, 2015
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
View gist:5623956
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
Open Stava upload new content page when Garmin Edge 305 is plugged in. NodeJS, node-udev
View garmin.js
#!/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 Nov 10, 2012
Nodejitsu deploy errors
View package.json
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
View relative-color.js
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]);
View createElement.bug.js
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);
View test.html
<html>
<head>
<script type="text/javascript" src="zeroth.js"></script>
</head>
<body>
<script>
console.log("First script");
</script>
<script>
var s = document.createElement("script");