This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
100 prisoners are each given a number. | |
A room is arranged with 100 boxes, each containing a unique prisoner's number. | |
Each prisoner must enter the room, open at most 50 boxes, and leave without | |
communicating anything. Their aim is to find their own number. | |
If *every* prisoner finds their own number, they succeed. | |
If a *single* prisoner fails to find their own number, they fail. | |
The naive approach of each prisoner opening a random 50 boxes results in an | |
incredibly low chance of success, (1/2)^100. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for file in projects shared style | |
do | |
# Move the file to a name matching its hash. | |
echo mv css/$file*.css css/$file-`minihash css/$file*.css`.css | |
mv css/$file*.css css/$file-`minihash css/$file*.css`.css | |
# Grab the new filename and replace all occurrences in HTML files. | |
filePath=`ls css/$file-*.css` | |
newFile="$(basename $filePath)" | |
echo $filePath $newFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { MutableRef, useCallback, useRef, useState } from "preact/hooks"; | |
type RefState<T> = [MutableRef<T>, T, (newVal: T) => void]; | |
export default function useRefState<T>(initialValue: T): RefState<T> { | |
const ref = useRef<T>(initialValue); | |
const [value, setValue] = useState(initialValue); | |
const setValueAndUpdateRef = useCallback((value: T) => { | |
ref.current = value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function useStateWithCallback<T>( | |
defaultState: T | (() => T) | |
): readonly [T, Dispatch<SetStateAction<T>>, () => Promise<T>] { | |
const [state, setState] = useState<T>(defaultState); | |
const getState = useCallback(() => { | |
return new Promise<T>((resolve) => { | |
setState((oldValue) => { | |
resolve(oldValue); | |
return oldValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- App.svelte --> | |
<script> | |
import Knob from './Knob.svelte'; | |
let value = 0; | |
const reset = () => { value = 50 }; | |
</script> | |
<Knob bind:value={value} max={100} min={0} pixelRange={200}/> | |
<p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useSequence({ values, onComplete }) { | |
const [index, setIndex] = useState(0); | |
function next() { | |
setIndex((oldIndex) => { | |
if (oldIndex + 1 >= values.length) { | |
setImmediate(onComplete); | |
return oldIndex; | |
} else { | |
return oldIndex + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from "react"; | |
/** | |
* Focus the given element when a key is pressed; | |
* and unfocus it when Escape is pressed. | |
* | |
* e.g. | |
* const ref = useFocusOnKey('/'); | |
* return <input ref={ref} /> | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import ast | |
import sys | |
import csv | |
import boto3 | |
AWS_ACCESS_KEY = "<YOUR ACCESS KEY HERE>" | |
AWS_SECRET_KEY = "<YOUR SECRET KEY HERE>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import warnings | |
import zlib | |
sys.path.append(os.getcwd() + '/' + "pylzma.egg") | |
import pylzma | |
import struct | |
import random | |
import shutil | |
from zipfile import ZipFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
from minitest import case, tests | |
from functools import wraps, partial | |
def makepartial(fn): | |
""" | |
This function is a decorator which allows functions with a fixed | |
number of arguments gracefully to be transformed into partial functions | |
given too few arguments to execute. |
NewerOlder