Skip to content

Instantly share code, notes, and snippets.

View Fordi's full-sized avatar

Bryan Elliott Fordi

View GitHub Profile
@Fordi
Fordi / ShaperDomino.jsx
Last active September 24, 2023 00:24 — forked from anonymous/shaper-dots.svg
Print an 11"x8.5" page of fiducial markers for the Shaper Origin. Download this SVG and open it in your browser to use it. PageUp/PageDown to change pages. Demo: http://fordi.org/shaper-dots.svg
import React from 'react';
/**
* Convert a number into a 12-digit binary number string
*/
const dots = num => {
const n = num.toString(2).padStart(12, 0).split('').slice(0, 12);
return `1${n.substr(0, 6)}11${n.substr(6)}1`;
};
/**
* See generateShaperNumbers.js to see how this is generated.
@Fordi
Fordi / button.ino
Last active March 10, 2018 21:56
Instructions for building a simple light-up toggle button in a small space
// the number of the pushbutton pin
const int buttonPin = PB0;
// the number of the LED pin
const int ledPin = PB1;
int ledState = 0;
int buttonState = 0;
void setup() {
@Fordi
Fordi / mean_presidents_day.js
Last active February 20, 2018 05:41 — forked from anonymous/dates.js
Calculating the average of our Presidents' birthdays.
const CURRENT_YEAR = new Date(new Date().getFullYear(), 0, 0, 0, 0, 0, 0);
const DAY = 1000 * 60 * 60 * 24;
const dates = ['Feb 22', 'Oct 30', 'Apr 13', 'Mar 16', 'Apr 28', 'July 11', 'Mar 15', 'Dec 5', 'Feb 9', 'Mar 29', 'Nov 2', 'Nov 24', 'Jan 7', 'Nov 23', 'Apr 23', 'Feb 12', 'Dec 29', 'Apr 27', 'Oct 4', 'Nov 19', 'Oct 5', 'Mar 18', 'Aug 20', 'Jan 29', 'Oct 27', 'Sep 15', 'Dec 28', 'Nov 2', 'July 4', 'Aug 10', 'Jan 30', 'May 8', 'Oct 14', 'May 29', 'Aug 27', 'Jan 9', 'July 14', 'Oct 1', 'Feb 6', 'June 12', 'Aug 19', 'July 6', 'Aug 4', 'June 14'];
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const TAU = Math.PI * 2;
const getDayNum = d => {
let diff = +new Date(d) - CURRENT_YEAR;
return Math.floor(diff / DAY);
};
#!/bin/bash
# Will maximize the current window to a new desktop, or, if the window is not
# Use your window manager's keybindings to attach this script to the key combination of your choice
# Requires the following packages in Ubuntu:
# xdotool x11-utils wmctrl
function goFull() {
echo $1
DESKTOP=`wmctrl -d | cut -d \ -f 1 | tail -1`
@Fordi
Fordi / utf8-btoatob.js
Created May 31, 2017 18:42
DOM btoa / atob UTF-8 suppport
((win, btoa, atob) => Object.assign(win, {
btoa: (str) => btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => String.fromCharCode(parseInt(p1, 16)))),
atob: (str) => decodeURIComponent(atob(str).split('').map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join(''))
}))(this, btoa, atob);
@Fordi
Fordi / MP3PlayFile.ino
Last active January 19, 2018 13:54
Sample code to play a random MP3 file to the on-board DAC off the root of the on-board SD card on Teensy 3.5/3.6; For use with https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib
#include <Audio.h>
#include <SerialFlash.h>
#include <play_sd_mp3.h>
#define USE_TEENSY3_OPTIMIZED_CODE
// SD-hosted MP3 file source
AudioPlaySdMp3 playMp31;
// Stereo DAC (Teensy 3.5/3.6)
@Fordi
Fordi / .XCompose
Last active August 5, 2017 17:23
My XCompose configuration. For those that want to type 𝔣𝔞𝔫𝔠𝔦𝔢𝔯.
# Spaces
<Multi_key> <space> <space> : " " nobreakspace # NO-BREAK SPACE
<Multi_key> <4> <n> <space> : " " U2000 # en quad
<Multi_key> <4> <m> <space> : " " U2001 # mutton quad
<Multi_key> <n> <space> : " " U2002 # en space
<Multi_key> <m> <space> : " " U2003 # em space
<Multi_key> <1> <3> <m> <space> : " " U2004 # 1/3 em space
<Multi_key> <1> <4> <m> <space> : " " U2005 # 1/4 em space
<Multi_key> <1> <6> <m> <space> : " " U2006 # 1/6 em space
<Multi_key> <f> <space> : " " U2007 # Figure space
@Fordi
Fordi / console.lineGraph.js
Last active December 29, 2022 23:51
Draw a line graph in Chrome/Chromium's dev console
/**
* Draw a line graph in Chrome/Chromium's dev console
* Examples:
* console.lineGraph([[5, 3], [10, 8], [-10, 1], [7, -3], [3, 0]], 320, 240);
* console.lineGraph(Math.sin, 420, 240, -Math.PI, Math.PI, 0.001);
* console.lineGraph(function (x) {
return [
Math.sqrt(1 - x*x) + Math.abs(x) - 0.75,
(Math.abs(x)-Math.sqrt(1 - x*x)) / 2 - 0.25
];
@Fordi
Fordi / uggconv.js
Created November 17, 2016 00:30
Game Genie code conversion library (ported from uggconv.c)
var ConsoleCode = (function () {
var fmt = function (n, b, p) {
if (n === null || n === undefined) { return ''; }
if (isNaN(n)) { return ''; }
n = n.toString(b).toUpperCase();
while (p > n.length) {
n = '0' + n;
}
return n;
};
@Fordi
Fordi / politifact-integrated-score.js
Created November 7, 2016 16:10
Integrate PolitiFact's truth score for sorting
function truthScore(True, mostlyTrue, halfTrue, mostlyFalse, False, pantsOnFire) {
var ttl = True + mostlyTrue + halfTrue + mostlyFalse + False + pantsOnFire;
return 100 * (
1.00 * True +
0.75 * mostlyTrue +
0.5 * halfTrue +
0.25 * mostlyFalse +
0.00 * False +
-0.50 * pantsOnFire
) / ttl;