Skip to content

Instantly share code, notes, and snippets.

View devNoiseConsulting's full-sized avatar

Michael Flynn devNoiseConsulting

View GitHub Profile
@devNoiseConsulting
devNoiseConsulting / dp20180219.js
Created February 20, 2018 02:06
Number Diamond - PhillyDev Slack #daily_programmer - 20180219
const numberDiamond_1 = function() {
const padding = new Array(9).join(' ');
const numbers = new Array(9)
.fill(0)
.map((v, i) => i + 1)
.join('');
let halfDiamond = new Array(9).fill(0).map((v, i) => {
let halfRow = padding.slice(0, 8 - i) + numbers.slice(0, i + 1);
return (
halfRow +
@devNoiseConsulting
devNoiseConsulting / PiNotes.md
Last active February 12, 2018 21:06
My Notes on setting up a Raspberry Pi

Raspberry Pi notes

Write img to SD card (OS X)

diskutil list
sudo dd bs=1m if=2017-11-29-raspbian-stretch-lite.img of=/dev/disk2 conv=sync

Enable SSH

@devNoiseConsulting
devNoiseConsulting / index.js
Created January 12, 2018 21:12
Pay attention to which variable you're using!
// Wrong!!!
self.addEventListener('activate', function(event) {
var cacheWhitelist = ['v2'];
event.waitUntil(
// TODO: remove the old cache
caches.keys().then(function(keyList) {
return Promise.all(
keyList.map(function(key) {
if (cacheWhitelist.indexOf(key) === -1) {
@devNoiseConsulting
devNoiseConsulting / ac20171225.js
Created January 3, 2018 03:32
The Halting Problem - Advent of Code - 20171225
/*
Begin in state A.
Perform a diagnostic checksum after 12629077 steps.
In state A:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state B.
If the current value is 1:
@devNoiseConsulting
devNoiseConsulting / ac20171224.js
Created January 3, 2018 03:31
Electromagnetic Moat - Advent of Code - 20171224
const ports = require('./ports');
let findCompatiblePorts = function(currentPort, portSize, ports, usedPorts) {
ports = ports
.filter(p => p !== currentPort)
.filter(p => usedPorts.indexOf(p) == -1)
.filter(port => {
let [a, b] = port.split('/');
return a == portSize || b == portSize ? true : false;
});
@devNoiseConsulting
devNoiseConsulting / ac20171223.js
Created January 3, 2018 03:30
Coprocessor Conflagration - Advent of Code - 20171223
let coprocessorConflagration = function(instructions, regA = 0) {
let offset = 'a'.charCodeAt();
let registers = new Array(10).fill(0);
registers[0] = regA;
let multiplied = 0;
let index = 0;
let executeInstruction = function(instruction) {
let [operation, a, b] = instruction.split(' ');
@devNoiseConsulting
devNoiseConsulting / ac20171222.js
Created January 3, 2018 03:29
Sporifica Virus - Advent of Code - 20171222
let virusGrid = require('./virusGrid');
let checkGridSize = function(grid, x, y) {
let width = grid[0].length;
if (x < 0) {
grid.unshift(new Array(width).fill(0).map(v => '.'));
x = 0;
}
if (x == grid.length) {
@devNoiseConsulting
devNoiseConsulting / ac20171221.js
Created January 3, 2018 03:29
Fractal Art - Advent of Code - 20171221
let gridRules = require('./gridRules');
let transposeArray = function(array) {
return array[0].map((col, i) => array.map(row => row[i]));
};
let permuations = function(square) {
let perms = [];
perms.push(square.slice());
perms.push(transposeArray(square.slice()));
@devNoiseConsulting
devNoiseConsulting / ac20171220.js
Last active January 3, 2018 03:28
Particle Swarm - Advent of Code - 20171220
let particles = require('./particles');
let stepParticles = function(particles) {
return particles.map(p => {
p.v = p.v.map((c, i) => c + p.a[i]);
p.p = p.p.map((c, i) => c + p.v[i]);
return p;
});
};
@devNoiseConsulting
devNoiseConsulting / ac20171219.js
Created January 3, 2018 03:27
A Series of Tubes - Advent of Code - 20171219
const path = require('./path');
let changeDirection = function(path, x, y, dX, dY) {
let newDirections = [[dY, dX], [-1 * dY, -1 * dX]];
let direction = -1;
newDirections.forEach((d, i) => {
let location = path[x + d[0]][y + d[1]];
if (location !== ' ' && location !== undefined) {
direction = i;