Skip to content

Instantly share code, notes, and snippets.

View tef's full-sized avatar
💭
Please don't try to contact me over GitHub.

tef tef

💭
Please don't try to contact me over GitHub.
View GitHub Profile
@tef
tef / dont_do_this.md
Created April 11, 2014 07:26
Please don't do this

Pleae don't do this

Hello is this tef?

Yes. Who is this?

David

Who?

______
< what >
------
\
\
^__^
_______/(oo)
/\/( /(__)
| W----|| |~|
|| || |~| ~~
# based upon http://www.johndcook.com/standard%5Fdeviation.html
from collections import OrderedDict
class RunningStat(object):
def __init__(self):
self.n = 0
self.m = None
self.s = None
self.min = None
self.max = None
possible assignments:
- add tests to check the behaviour is correct.
don't compare it to python's output, just check that each element is greater than the
next, with the compare function
- add profiling code, and run it with much, much larger lists ~5000 elements
which one is fast, slow?
- quick sort picks a random pivot, is this a good choice? what happens on larger lists
class ShittyHashTable:
def __init__(self, buckets = 8):
self.buckets = []
for x in range(8):
self.buckets.append([])
def add(self, key, value):
n = shittyhash(key, len(self.buckets))
bucket = self.buckets[n]
for i, pair in enumerate(bucket):
@tef
tef / sortstuff.py
Last active December 27, 2015 20:29
#!/usr/bin/env python3
import random
def msort(array, compare):
l = len(array)
if l > 2:
mid = l//2
left = msort(array[:mid], compare)
right = msort(array[mid:], compare)
return merge(left, right, compare)
@tef
tef / jptest.tex
Created October 22, 2013 16:12
Test of CJK in XeLaTeX
% Install these fonts http://ipafont.ipa.go.jp/#en
\documentclass[12pt]{article}
\usepackage{fontspec, xunicode, xeCJK}
\setCJKmainfont{IPAexMincho}
\setCJKsansfont{IPAexGothic}
\setCJKmonofont{IPAexGothic}
\begin{document}
Hello World, or こんにちは 世界!
\end{document}
@tef
tef / gist:7040514
Created October 18, 2013 11:56
quines are easy in php :-)
$ cat > quine.php
Hello, World!
$ php quine.php
Hello, World!
$
@tef
tef / sort.py
Last active December 25, 2015 11:19 — forked from ntlk/sort.py
from sys import stdin, stdout
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-r', action='store_const', const=True, required=False, default=False)
args = parser.parse_args()
stdout.writelines(sorted(stdin.readlines(), reverse = args.r))
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$]{$documentclass$}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[utf8]{inputenc}