This file contains hidden or 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
""" | |
A simple mixin that counts the number of comparisons performed. Each | |
class it is mixed into keeps its own counter, which can be retrieved and | |
reset at whim. The code is written generically, and will work with any | |
orderable type. | |
In the COSC122 (first year computer science) course at the University of | |
Canterbury, one of the assignments is to implement a binary search. To | |
verify the algorithm, students have to manually increment a counter | |
every time they compare two values. This is annoying and error-prone, |
This file contains hidden or 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 | |
""" | |
I go around, knocking on people's doors, until I find someone with two | |
children, at least one of which is a boy. | |
What is the probability that they are both boys? | |
(The answer should approximate 1/3.) |
This file contains hidden or 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
-- | A simple parser combinator library. | |
module Text.Comb | |
( Parser(runParser) | |
, parse | |
, next | |
, satisfy | |
, match | |
, matches | |
) where |
This file contains hidden or 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
GET /project | |
200 OK | |
{ | |
"revision": revision, | |
"tasks": [ | |
{ | |
"title": string, | |
"completed": boolean, | |
"children": [ .. ] |
This file contains hidden or 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
# ~/.bashrc: executed by bash(1) for non-login shells. | |
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) | |
# for examples | |
# Include the default .bashrc | |
. /etc/skel/.bashrc | |
# Don't save command history on the VM | |
if [ "$(hostname)" == 'bonbon' ]; then | |
unset HISTFILE |
This file contains hidden or 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
module Names (renderName) where | |
import Data.List (genericIndex) | |
-- | Map a non-negative integer to a valid Python identifier. | |
renderName :: Integer -> String | |
renderName | |
= ('_':) -- Prevent conflict with Python keywords | |
. map (genericIndex chars) | |
. digitify (fromIntegral $ length chars) |
This file contains hidden or 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
#include <stdio.h> | |
#include "log.h" | |
void | |
PLog_printf(const char *type, const char *filename, unsigned int line, const char *fmt, ...) { | |
va_list vl; | |
va_start(vl, fmt); | |
fprintf(stderr, "%s:%u: %s: ", filename, line, type); | |
vfprintf(stderr, fmt, vl); | |
putc('\n', stderr); |
This file contains hidden or 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
-- http://en.wikipedia.org/wiki/Peano_axioms | |
module PeanoAxioms where | |
data ⊥ : Set where -- empty | |
data ℕ : Set where | |
-- [1] 0 is a natural number. | |
zero : ℕ | |
-- [6] For every natural number n, S(n) is a natural number. |
This file contains hidden or 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
__ | |
_a | |
_b | |
_c | |
_d | |
_e | |
_f | |
_g | |
_h | |
_i |
This file contains hidden or 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
"""Great Scott!""" | |
import sys | |
sys.setrecursionlimit(4000) | |
fix = lambda f: lambda x: f(fix(f))(x) | |
zero = lambda z: lambda s: z | |
succ = lambda x: lambda z: lambda s: s(x) | |
# plus, times are faster when the second argument is small |