Skip to content

Instantly share code, notes, and snippets.

View milesrout's full-sized avatar

Miles Rout milesrout

View GitHub Profile
data Natural = Zero | Succ Natural
add :: Natural -> Natural -> Natural
add Zero b = b
add (Succ a) b = add a (Succ b)
mul :: Natural -> Natural -> Natural
mul Zero _ = Zero
mul _ Zero = Zero
mul (Succ a) b = add b (mul a b)
@milesrout
milesrout / 01-let-and-where.hs
Last active November 23, 2017 00:09
The ? language.
-- ? doesn't have statements, it has sentences.
-- sentences end with a full stop, as everyone knows.
-- every expression can be a sentence.
let a = 1.
-- let expressions look like this:
-- `'let' VARIABLE '=' EXPRESSION (',' VARIABLE '=' EXPRESSION)* ('and' VARIABLE '=' EXPRESSION)?`
let b = 2 and c = 3.
let d = 4, e = 5 and f = 6.
let g = 7, h = 8.
syntax on
nnoremap ; :
nnoremap : ;
" Sane auto-completion
set wildmode=list:longest,longest
" Set working directory to the current file automatically
set autochdir
cat pacman.log | grep ' installed' | cut -d ' ' -f 5 | uniq | wc -l
for directory in $(ls -lAFp | grep '/' | sed 's/\///' | cut -f 2 --d ':' | cut -f 2 --delim ' '); do cd $directory; echo -n "$directory "; sudo find | wc -l; cd ..; done
find . -name "*.[ch]" | xargs etags -o ~/.tags/TAGS
pavucontrol
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
# Play a directory
@milesrout
milesrout / struct.py
Last active August 29, 2015 14:04
struct
def __make_init(*argnames):
def __init__(self, *args):
expected = len(argnames)
actual = len(args)
if expected != actual:
s = '' if expected == 1 else 's'
raise TypeError("__init__() takes exactly {expected} argument{s} ({actual} given)".format(**locals()))
for (arg, argname) in zip(args, argnames):
setattr(self, argname, arg)
return __init__
# Determine whether, in any state, the expected chosen prize is greater than the maximum prize
from itertools import combinations
from math import log, exp
cases = {1,10,100,1000}
maxprize = 200
s = set.union(*[set(combinations(cases, i)) for i in range(1, len(cases)+1)])
ss = sorted(s)
DCPU-16 Specification
Copyright 1985
Version 1.7
=== SUMMARY ====================================================================
* 16 bit words
* 0x10000 words of ram
* 8 registers (A, B, C, X, Y, Z, I, J)
* program counter (PC)
#include <iostream>
using namespace std;
template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value, void>::type>
constexpr T pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798;
int main()
{
float radiusf;
#define GL_GLEXT_PROTOTYPES
#include <GLFW/glfw3.h>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <fstream>