Skip to content

Instantly share code, notes, and snippets.

{
"ignition": {
"version": "2.2.0"
},
"networkd": {
"units": [
{
"name": "00-enp.network",
"contents": "[Match]\nName=enp*\n\n[Network]\nDHCP=yes"
}
@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 <edoardo849@gmail.com>
# Edits done by: Marco Bosch <marcogithub@hotmail.com>
import os
from time import sleep
import signal
import sys
import RPi.GPIO as GPIO
@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.

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 / 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);
}
@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({
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 / infinite.js
Created January 26, 2017 00:31 — forked from threepointone/infinite.js
infinite scrolling pattern with react fiber (featuring intersection observers)
// inifinite scrolling of content without extra wrappers
const { render, findDOMNode } = ReactDOMFiber
class App extends React.Component {
render() {
// wrap the root element with an Intersection Observer, exposing .observe for children
return <Intersection>
<div style={{ height: 200, overflow: 'auto' }}>
<Page offset={0} count={10} />
</div>
@benfletcher
benfletcher / temp.md
Created December 18, 2016 20:27 — forked from mpj/temp.md
bah

5 tips to quickly understand a new code base

When you work as a programmer, it’s only a small percentage of your time that is spent on writing code. The vast majority of your time is spent trying to understand code that is already written. Either code of others, or code that you yourself wrote a last year.

It’s especially tricky to get into a completely new codebase. You might when you start a new job or perhaps your team takes ownership of a new system.

I have done this a couple of times now, and I have a process for it now, and I figure that it might be interesting to some people to hear about it, and that is what we are going to explore today.

In case you’re new - this is FunFunFunction, a weekly show where we try to become more confident and excited about programming by exploring old wisdom, wild ideas and having fun. At the end of this episode, I’m going to ask to subscribe.

The future is here: Classless object-oriented programming in JavaScript.

Douglas Crockford, author of JavaScript: The Good parts, recently gave a talk called The Better Parts, where he demonstrates how he creates objects in JavaScript nowadays. He doesn't call his approach anything, but I will refer to it as Crockford Classless.

Crockford Classless is completely free of class, new, this, prototype and even Crockfords own invention Object.create.

I think it's really, really sleek, and this is what it looks like:

function dog(spec) {