Skip to content

Instantly share code, notes, and snippets.

const dir = {
North: { x: 0, y: 1, R: "East", L: "West" },
West: { x: -1, y: 0, R: "North", L: "South" },
South: { x: 0, y: -1, R: "West", L: "East" },
East: { x: 1, y: 0, R: "South", L: "North" }
};
const moves = {
R: ([x, y, d]) => ([x, y, dir[d].R]),
L: ([x, y, d]) => ([x, y, dir[d].L]),
@benfletcher
benfletcher / strategy-demo.js
Created February 17, 2017 13:30
Passport Google and Bearer Strategy
var express = require('express');
var passport = require('passport');
var GoogleStrategy = require('passport-google-oauth20').Strategy;
var BearerStrategy = require('passport-http-bearer').Strategy;
var app = express();
app.use('/', express.static('build'));
passport.use(new GoogleStrategy({
@benfletcher
benfletcher / dither.js
Created March 23, 2017 00:57
Temporal dithering
var swatch = document.createElement('div');
swatch.style.width = 500;
swatch.style.height = 500;
document.body.appendChild(swatch);
function turnRed() {
swatch.style.backgroundColor = 'red';
requestAnimationFrame(turnBlue);
}

Compute the number of unique change combinations possible.

You will be given:

  • an amount of money
  • an array of coin denominations
  • you have access to an unlimited number of each coin denomination

For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2:

1+1+1+1

@benfletcher
benfletcher / collatz.md
Last active March 8, 2019 15:47
Collatz Collusion

The Collatz conjecture:wiki

Start with any positive integer n. Then each term is obtained from the previous term as follows:

  • if the previous term is even, the next term is one half the previous term ( n / 2)
  • if the previous term is odd, the next term is 3 times the previous term plus 1 ( 3n + 1 )

The conjecture is that no matter what value of n, the sequence will always reach 1.

Numbers form a tree as they work their way down to 1, as seen in the image below. For example, starting with the number 5 you next get 16 ( 3x5 + 1 ) and then 8 ( 16 / 2 ). Starting with the number 64, you get 32 ( 64 / 2 ) and then 32. So the numbers 5 and 64 converge at 16.

@benfletcher
benfletcher / fancontrol python 3.4 code
Created May 14, 2019 19:28 — forked from highflyersnl/fancontrol python 3.4 code
this is to control a fan on a raspberry pi with python 3.4 on a bc332 transistor
#!/usr/bin/env python3
# first author: Edoardo Paolo Scalafiotti <[email protected]>
# Edits done by: Marco Bosch <[email protected]>
import os
from time import sleep
import signal
import sys
import RPi.GPIO as GPIO
{
"ignition": {
"version": "2.2.0"
},
"networkd": {
"units": [
{
"name": "00-enp.network",
"contents": "[Match]\nName=enp*\n\n[Network]\nDHCP=yes"
}