Skip to content

Instantly share code, notes, and snippets.

View tanepiper's full-sized avatar

Tane Piper tanepiper

View GitHub Profile
@tanepiper
tanepiper / mm-keyboard.html
Created December 19, 2017 00:15
Example of how to declare a keyboard with Music Markup
<mm-keyboard oscillator-type="sawtooth">
<mm-key class-name="white b" frequency="174.614" time="1"></mm-key>
<mm-key class-name="black as" frequency="184.997" time="1"></mm-key>
<mm-key class-name="white a" frequency="195.998" time="1"></mm-key>
<mm-key class-name="black gs" frequency="200.000" time="1"></mm-key>
<mm-key class-name="white g" frequency="207.652" time="1"></mm-key>
<mm-key class-name="black fs" frequency="233.082" time="1"></mm-key>
<mm-key class-name="white f" frequency="246.942" time="1"></mm-key>
<mm-key class-name="white e" frequency="261.626" time="1"></mm-key> <!-- Middle c -->
<mm-key class-name="black ds" frequency="277.183" time="1"></mm-key>
const e = document.createDocumentFragment('div');
const sleep = (ms, caller, ...args) => new Promise(resolve => setTimeout(caller || resolve, ms, ...args));
const waitForHello = async(timeout, elm) => {
console.log('checking');
if (elm.innerHTML === 'Hello world') {
console.log('Value found');
return;
} else if ((timeout -= 100) <= 0) {
@tanepiper
tanepiper / sleep.js
Created November 13, 2017 14:09
A JS sleep function that can also call a passed function
const sleep = (ms, caller, ...args) => new Promise(resolve => setTimeout(caller || resolve, ms, ...args));
const sleep = ms => {
return new Promise(resolve => setTimeout(resolve, ms));
}
const register = shared => ({
event: 'HeatWarning',
command: async event => {
const lights = await shared.hub.lights.getAll();
lights.map(async (light, index) => {
light.on = true;
light.alert = 'lselect';
light.effect = 'none';
light.brightness = 254;
[
{ "timestamp":"2017-11-06T17:41:47Z", "event":"Loadout", "Ship":"DiamondBackXL"},
{ "timestamp":"2017-11-06T17:43:01Z", "event":"StartJump", "JumpType":"Hyperspace", "StarSystem":"Sol", "StarClass":"G" },
{ "timestamp":"2017-11-06T17:47:57Z", "event":"HeatWarning" }
]
@tanepiper
tanepiper / version.sh
Created November 1, 2017 13:39
Given a version returned of 1.2.3-beta.0 from the package I only want the "1.2.3" part
# Given a version returned of 1.2.3-beta.0 from the package I only want the "1.2.3" part
grep -m1 version package.json | awk -F: '{ print $2 }' | sed 's/[^0-9.].*//g'
# Running the above command I get an empty output. But if I manually run the result:
echo "1.2.3-beta.0", | sed 's/[^0-9.].*//g'
# I get 1.2.3
@tanepiper
tanepiper / ES6 Example.js
Created October 31, 2017 20:27
node-bitly examples
const BitlyClient = require('bitly');
const bitly = BitleyClient('<accessToken>');
const uri = 'https://github.com/tanepiper/node-bitly';
bitly.shorten(uri).then(result => {
console.log(result);
});
@tanepiper
tanepiper / tsconfig.json
Created October 31, 2017 20:25
Config file for node-bitly
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es7"],
"allowJs": true,
"strict": false,
"noImplicitAny": false,
"strictNullChecks": false,
"noUnusedLocals": true,
@tanepiper
tanepiper / new.js
Created October 31, 2017 20:20
Difference between old and new doRequest methods
const doRequest = async ({ accessToken, config, method, data }) => {
const uri = generateUrl(accessToken, method, data, config);
try {
const req = await request({ uri });
return JSON.parse(req);
} catch (e) {
console.log('Request Failed');
throw e;
}
};