Skip to content

Instantly share code, notes, and snippets.

View amwmedia's full-sized avatar

Andrew Worcester amwmedia

View GitHub Profile
@amwmedia
amwmedia / animation.js
Last active August 12, 2020 17:23
Launch Scripts
window.hudpad = window.hudpad || {};
window.hudpad.scripts = window.hudpad.scripts || [];
window.hudpad.scripts.push({
name: 'animation',
title: 'Demo Animation',
script: function (launch) {
// launch.showText('Hello There!');
// launch.showText('My Name is Andrew!');
// launch.showText('what is your name?');
let x = 8;
@amwmedia
amwmedia / plopfile.js
Last active November 25, 2019 13:51
addMany example
module.exports = function (plop) {
plop.setGenerator("test", {
description: "create a component",
prompts: [
{
type: "input",
name: "name",
message: "name"
}
],
@amwmedia
amwmedia / aworcester.zsh-theme
Last active October 17, 2019 15:37
Zsh Theme (Based on Agnoster)
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
@amwmedia
amwmedia / Challenge-1.js
Created December 11, 2017 15:57
Advent Of Code 2017 - Day 6
// input => [10, 3, 15, ...];
function memoryBanks(input) {
const states = [];
let opCount = 0;
for (; !states.includes(input.join('|')) ;) {
states.push(input.join('|'));
const highestNum = Math.max.apply(null, input);
let idx = input.indexOf(highestNum);
let amt = input[idx];
input[idx] = 0;
@amwmedia
amwmedia / Challenge-1.js
Created December 11, 2017 14:21
Advent Of Code 2017 - Day 5
// Day 5 - Challenge #1
// input is an array of integers
function escapeHops(input) {
let hops = 0;
for (let pos = 0; pos < input.length;) {
const prevPos = pos;
pos += input[pos];
hops += 1;
input[prevPos]++;
}
@amwmedia
amwmedia / Challenge-1.js
Last active December 8, 2017 14:47
Advent Of Code 2017 - Day 4
// input is array of passphrases
input.filter(
phrase => phrase
.split(' ')
.every((word, idx, arr) => arr.indexOf(word) === idx)
).length;
@amwmedia
amwmedia / Challenge-1.js
Created December 8, 2017 14:10
Advent Of Code 2017 - Day 3
function getDist(num) {
let sqrt = Math.ceil(Math.sqrt(num));
let sideLengthOfSq = (sqrt % 2 === 0 ? sqrt + 1 : sqrt);
let highestNumInSq = sideLengthOfSq * sideLengthOfSq;
let targetDistFromCorner = (highestNumInSq - num) % (sideLengthOfSq - 1);
let targetDistFromSideCenter = Math.abs(targetDistFromCorner - Math.floor(sideLengthOfSq/2));
const closestDistFromSq = (sideLengthOfSq - 1) / 2;
return closestDistFromSq + targetDistFromSideCenter;
}
@amwmedia
amwmedia / Day1Solution.js
Last active December 6, 2017 14:55
Advent Of Code 2017
// Day 1 - Challenge #1
input.split('').reduce((acc, d, i, a) => {
const n1 = Number(d);
const n2 = Number(a[i+1] || a[0]);
return (n1 === n2 ? acc + n1 : acc);
}, 0);
// Day 1 - Challenge #2
input.split('').reduce((acc, d, i, a) => {
const n2Pos = (i + (a.length / 2)) % a.length;
@amwmedia
amwmedia / glean.js
Last active August 25, 2017 12:21
Glean... what you want from any data source.
/**
* glean - Access nested paths in an object whos structure we are uncertain of.
* Unholy marriage of Facebook's existential function and lodash get()
* https://facebook.github.io/react-native/blog/2017/03/13/idx-the-existential-function.html
* https://lodash.com/docs#get
*
* @param {Object} source the source object we are operating on
* @param {Function} accessor attepts to access the property desired
* @param {Any} defaultValue = null value to return if the accessor throws
* @return {Any}
@amwmedia
amwmedia / random-data-generator.js
Last active December 28, 2016 20:11
uncontext style random data generator. Used for the random-nodecopter project my team did at jsconf2015.
(function () {
var data = {};
var dataLastSent = '';
var listeners = [];
setInterval(genA, 1500);
setInterval(genB, 2270);
setInterval(genC, 5234);
genA();