Skip to content

Instantly share code, notes, and snippets.

Bede Kelly bedekelly

Block or report user

Report or block bedekelly

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bedekelly
bedekelly / nondeterminism.py
Created Sep 19, 2019
List monad (+alternative) for nondeterminism in Python
View nondeterminism.py
toss = {"Fair": ["Heads", "Tails"], "Biased": ["Heads", "Heads"]}
@do
def coins():
coin = yield ["Fair", "Biased"]
result = yield toss[coin]
_ = yield guard(result == "Heads")
return coin
# Probability of a biased coin, given you observed Heads, is 2/3.
@bedekelly
bedekelly / nondeterminism.hs
Created Sep 19, 2019
Haskell Nondeterminism
View nondeterminism.hs
data CoinType = Fair | Biased deriving (Show)
data Coin = Head | Tail deriving (Eq,Show)
toss Fair = [Head, Tail]
toss Biased = [Head, Head]
pick = [Fair, Biased]
experiment = do
coin <- pick -- Pick a coin at random
@bedekelly
bedekelly / do_notation.py
Created Sep 18, 2019
Do Notation using Python's Yield Keyword
View do_notation.py
from functools import wraps
def do(f):
def partial_run(f, args, kwargs, values_so_far=()):
# First, create a NEW instance of the coroutine.
coroutine = f(*args, **kwargs)
# Advance the coroutine to the first yield point.
yielded_monad = next(coroutine)
View fixedPose.js
import React, { useState } from "react";
import posed from "react-pose";
import "./App.css";
const Box = posed.div({
regular: { width: '10vw', height: '10vh', flip: true },
fullscreen: { width: "100vw", height: '100vh', flip: true }
});
View pose.js
import React, { useState } from "react";
import posed from "react-pose";
import "./App.css";
export default function App() {
const [fullscreen, setFullscreen] = useState(false);
const toggle = () => setFullscreen(!fullscreen);
const pose = fullscreen ? 'fullscreen' : 'regular';
@bedekelly
bedekelly / parallaxListeners.js
Created Mar 31, 2019
Parallax Event Listeners
View parallaxListeners.js
document.addEventListener("mousemove", event => {
const height = event.clientY / window.innerHeight;
const width = event.clientX / window.innerWidth;
updatePositions(height, width);
});
window.addEventListener("deviceorientation", event => {
const height = -event.beta / 90;
const width = event.gamma / 180;
@bedekelly
bedekelly / parallax.js
Last active Sep 26, 2019
Quick'n'dirty parallax for a bunch of stacked layers
View parallax.js
MAX_TRANSLATE = 6;
const elements = [
"background", "clouds", "back-mountain", "front-mountain",
"hills-4", "hills-3", "hills-2", "hills-1", "birds"
].map(klass => document.querySelector(`.${klass}`));
function updatePositions(height, width) {
const maxVHTranslation = -height * MAX_TRANSLATE;
@bedekelly
bedekelly / circle.html
Last active Mar 24, 2019
Simple circle to use for line-drawing
View circle.html
<svg width="120" height="120" class="ring two">
<circle class="path" cx="60" cy="60"
r="58" stroke="rgb(176, 168, 142)"
stroke-width="2" fill="none" />
</svg>
@bedekelly
bedekelly / circle-drawing.css
Created Mar 24, 2019
Animate Drawing a Circle
View circle-drawing.css
.ring.two {
stroke-dasharray: calc(2 * 3.1415 * 58);
stroke-dashoffset: calc(2 * 3.1415 * 58);
stroke-dashoffset: -calc(2 * 3.1415 * 58);
transform: rotate(-90deg);
transition: stroke-dashoffset linear 0.5s;
}
.button:hover .ring.two {
stroke-dashoffset: 0;
@bedekelly
bedekelly / maps.py
Created Mar 19, 2018
First stab at an implementation of Record types
View maps.py
"""
A MapKeyValue is a name-value pair retrieved from a map.
The name is a string, and the value can be anything at all.
"""
MapKeyValue = namedtuple("MapKeyValue", "key value")
"""
A MapEntrySpec is a specification for an entry in a Map.
The key is a number, the name is a string exposed to the user,
You can’t perform that action at this time.