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
#!/usr/bin/env python3 | |
""" | |
Very simple HTTP server in python for logging requests | |
Usage:: | |
./server.py [<port>] | |
""" | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
import logging | |
import json |
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
#!/bin/bash | |
# Smcn | |
# ============= | |
if [ $# -eq 0 ]; then | |
echo "Enter date and module, ex 20-05-2021-modul-6" | |
exit | |
fi |
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
package foo | |
fun <T> permutations(list: List<T>): List<List<T>> = when { | |
list.size > 10 -> throw Exception("You probably dont have enough memory to keep all those permutations") | |
list.size <= 1 -> listOf(list) | |
else -> | |
permute(list.drop(1)).map { perm -> | |
(list.indices).map { i -> | |
perm.subList(0, i) + list.first() + perm.drop(i) | |
} |
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
package algorithms.shortestpath | |
interface Node | |
data class Edge(val node1: Node, val node2: Node, val distance: Int) | |
/** | |
* See https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm | |
*/ | |
fun findShortestPath(edges: List<Edge>, source: Node, target: Node): ShortestPathResult { |
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 * as tf from '@tensorflow/tfjs' | |
/* | |
* Experiment with | |
* - multiplication, combined (ie x1+3*x2). May have to train 500 epochs to get satisfactory results. | |
*/ | |
const randomInt = (max: number) => | |
Math.floor(Math.random() * Math.floor(max)) |
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
type Data = number[] | |
type Observation = number | |
type Prediction = Observation | |
function learn(xs: Data[], ys: Observation[]) { | |
return (x: Data): Prediction => { | |
// use xs and ys to predict outcome of x | |
return 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
// Objects with only numeric properties that can be treated as a n-dimensional vector | |
export type Vector<T> = { | |
[P in keyof T]: number | |
}; | |
const vextend = <T>(obj: Vector<T>, key: string, val: number): Vector<T> => Object.assign(obj, { [key]: val }); | |
export const vreduce = <T, R>(obj: Vector<T>, reducer: (agg: R, [key, val]: [string, number]) => R, init: R): R => |
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 {debounce} from 'lodash'; // or whatever | |
const debouncePromise = <T>(fn: (...args) => Promise<T>, wait: number, options = {}): ((...args) => Promise<T>) => { | |
return (...args) => | |
new Promise((resolve, reject) => { | |
const promisedFn = (...args) => | |
fn(...args) | |
.then(resolve) | |
.catch(reject); | |
const debouncedPromisedFn = debounce(promisedFn, wait, options); |
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
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; | |
type Minus<T, U> = {[P in Diff<keyof T, keyof U>]: T[P]}; | |
interface Eo {type: string} | |
interface Meo extends Eo{ meoStuff: any} | |
const isMeo = (eo: Eo): eo is Meo => eo.type === 'MEO type' | |
const aMethod = (eo: Eo) => { | |
if (isMeo(eo)) { | |
eo.meoStuff | |
} |
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
# Cut and paste from: | |
# http://dlib.net/face_recognition.py.html | |
# https://github.com/ageitgey/face_recognition/blob/master/face_recognition/api.py | |
# https://medium.com/towards-data-science/facial-recognition-using-deep-learning-a74e9059a150 | |
# | |
# Install dlib: See https://www.pyimagesearch.com/2017/03/27/how-to-install-dlib/ | |
# Download dlib models: http://dlib.net/files/ | |
import os | |
import dlib |
NewerOlder