- GitHub Staff
- ed.minni.xyz
- @egregius313
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 python | |
from contextlib import contextmanager | |
import time | |
@contextmanager | |
def timethis(timer=time.perf_counter): | |
""" | |
Small timing function. It is meant to be used as a | |
context manager, and it returns a lambda that when |
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
""" | |
A simple class decorator to define the __repr__ method | |
based on the signature of the __init__ method. | |
""" | |
__author__ = 'egregius313' | |
_repr_template = """ | |
def __repr__(self): | |
'Return repr(self)' |
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
(defn product [a & bs] | |
"The cross product of sets." | |
(reduce | |
(fn [xss ys] | |
(mapcat (fn [xs] (map (partial conj xs) ys)) xss)) | |
(map vector a) | |
bs)) |
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
(ns blob) | |
(defn abnormal? [color] | |
(= color :abnormal)) | |
(defn color [grid x y] | |
(get-in grid [x y])) |
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
# maybe.py | |
""" | |
Basic implementation of Haskell's Data.Maybe module. | |
The changes in the API are as follows: | |
- `maybe` is replaced with the `Maybe` class constructor | |
- `isJust` and `isNothing` are replaced with the builtin `isinstance` | |
- `listToMaybe` is replaced with the class method `Maybe.from_iterable` | |
- `maybeToList` is replaced with an implementation of `__iter__`, | |
so calls to `list()` will work |
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
# stop_writing_classes_game_of_life.py | |
""" | |
Adaptation of the "Conway's Really Simple Game" code | |
from Jack Diederich's talk "Stop Writing Classes". | |
Meant to help make some of the logic more explicit. | |
""" | |
from itertools import chain | |
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
# Allow tuple unpacking on classes defined with | |
# @attr.s decorator. Uses the attribute information | |
# from the definition of the class using attrs | |
# | |
# See also: | |
# http://www.attrs.org | |
# https://github.com/python-attrs/attrs | |
import hashlib | |
import linecache |
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
PKG_MGR=$(which apt-get brew apt | head -n1) | |
sudo $PKG_MGR update | |
sudo $PKG_MGR install -y opam | |
opam update | |
opam install core | |
if [[ $PKG_MGR =~ apt ]] | |
then |
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 | |
which brew || /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
brew install [email protected] | |
echo "alias gcc='gcc-4.9'" >> .bash_profile | |
echo "alias g++='g++-4.9'" >> .bash_profile |
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 python | |
# check_cflags.py | |
""" | |
check_cflags - guarantees that -Wall -Werror --pedantic flags are set in $CFLAGS | |
Exits with 0 if proper CFLAGS is used, otherwise returns with 1 | |
Usage: | |
./check_cflags.py FILE | |
""" |
OlderNewer