Skip to content

Instantly share code, notes, and snippets.

@TimboKZ
TimboKZ / type-safe-redux-code.ts
Last active October 16, 2019 11:28
Ultimate type-safe Redux abstraction
// Library code
type ReduxAction<Type extends string = string> = { type: Type; payload?: any };
type ActionTemplate<P> = (payload: P) => ReduxAction;
type ActionTemplateMap = { [action: string]: ActionTemplate<any> };
type ReduxHandler<State, Payload> = undefined extends Payload
? (state: Readonly<State>) => State
: (state: Readonly<State>, payload: Payload) => State;
type ExtractPayloadMap<T extends ActionTemplateMap> = {
[K in keyof T]: T[K] extends ActionTemplate<infer P> ? P : never;
};
#!/usr/bin/env bash
# Get the command from arguments
arg_str="$*"
$arg_str &
pid="$!"
# Wait for the window to open and grab its window ID
winid=''
while : ; do
import numpy as np
import matplotlib.patches as patches
from matplotlib import pyplot as plt
T_count = 5
x_count = 7
state_count = 6
state_rows = 2
state_cols = 3
@TimboKZ
TimboKZ / tim-test.sh
Last active March 4, 2017 22:55
COMP207P Shell Test Runner, works best with `.gitignore` from here: https://gist.github.com/TimboKZ/868cc0a23fdd217da2e581e59531172b
#!/usr/bin/env bash
#######################################################################
#
# tim-test.sh - UCL CS COMP207P Test Runner
# Timur Kuzhagaliyev 2017, https://foxypanda.me/
# Public version 1.1
#
#######################################################################
#
@TimboKZ
TimboKZ / data-binding.html
Created May 14, 2016 19:40
Two-way Data Binding in JS, read this for more information: http://foxypanda.me/two-way-data-binding
<html>
<head>
<title>Two-way Data Binding</title>
</head>
<body>
<input id="input" type="text">
<button id="change">Set value to "Hello"</button>
<span>Value: <strong id="value"></strong></span>
<script>
@TimboKZ
TimboKZ / solutions.hs
Last active May 8, 2016 22:48
Haskell solutions, 2015 to 2013
import Test.QuickCheck
combi:: (Num a, Ord a) => [(a, a)] -> [a]
combi [] = [0, 0]
combi xs = [sum ys] ++ [sum zs]
where ys = [x | (x, y) <- xs, x > y]
zs = [y | (x, y) <- xs, x > y]
zipWith':: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith' f a b = [f (a!!x) (b!!x) | x <- [0 .. len - 1]]