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 | |
# Solution to http://adventofcode.com/2016/day/2 part 1 | |
# using reduce and accumulate for awesome functional programing style points | |
# Mark Jenkins <mark@markjenkins.ca> | |
from sys import stdin | |
from functools import reduce | |
from itertools import chain, accumulate, islice |
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 | |
# solution to https://adventofcode.com/2016/day/1 part 2 | |
# in a functional style with python 3.3+ enhanced accumulate() and dropwhile() | |
# Mark Jenkins <mark@markjenkins.ca> | |
from itertools import accumulate, dropwhile, chain | |
MOVEMENTS = ((0,1), (1,0), (0,-1), (-1,0)) | |
DIRECTION_CHANGES = {"R": 1, "L": -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
#!/usr/bin/env python3 | |
# Functional solution to https://adventofcode.com/2016/day/1 part 1 | |
# with reduce() and lambda vs no lambda | |
# Mark Jenkins <mark@markjenkins.ca> | |
from functools import reduce | |
MOVEMENTS = ((0,1), (1,0), (0,-1), (-1,0)) | |
DIRECTION_CHANGES = {"R": 1, "L": -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
from sys import argv | |
# tab separated input from processing apache logs with awk to just have relevant fields and tab separation | |
ips = set() | |
with file(argv[1]) as f: | |
for line in f: | |
ip, date, url = line.split('\t') | |
if ip not in ips: | |
print "%s\t%s" % (ip, date) |
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 | |
# coding=UTF8 | |
""" | |
Copyright (c) 2014 Rudolf Rocker Chess Club | |
Permission is hereby granted, free of charge, to any person | |
obtaining a copy of this software and associated documentation | |
files (the "Software"), to deal in the Software without | |
restriction, including without limitation the rights to use, |
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
BOARD_SIZE = 8 | |
FIRST_RANK = 1 | |
LAST_RANK = BOARD_SIZE | |
PAWN_START = 2 | |
KING_START_FILE = 5 | |
KNIGHT, KING, BISHOP, ROOK, QUEEN, PAWN = ( | |
'N', 'K', 'B', 'R', 'Q', 'P' |
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
from .base58 import ripple_base58_decode, ripple_base58_encode | |
from .util import binary_encode_variable_data | |
from .crypto import double_sha256_checksum | |
ACCOUNT_NUM_BITS = 160 | |
ACCOUNT_NUM_BYTES = 20 | |
def extract_checksum(account_msg): | |
return account_msg[-4:] |
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
from pyparsing import Word, alphas, oneOf, operatorPrecedence, opAssoc | |
operand = Word(alphas) | |
signop = oneOf('+ -') | |
multop = oneOf('* /') | |
plusop = oneOf('+ -') | |
ARITH_EXPR = operatorPrecedence( operand, | |
[(signop, 1, opAssoc.RIGHT), |
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
# Makefile | |
ZONE_LIST=zone_list_file | |
ZONE_FILE_SUFFIX=".db" | |
all: zone_list.zones internal_zone_list.zones | |
zone_list.zones: $(ZONE_LIST) Makefile | |
./make_zone_list --prefix "/etc/bind/" \ | |
--suffix $(ZONE_FILE_SUFFIX) $^ > $@ |
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/evn python | |
# An iterative, functional definition of the fibonacci sequence using reduce() | |
# This is how I originally wrote this. | |
# map is going to be removed from the builtin namespace. So the newer | |
# version below doesn't use them. | |
# | |
# Advocates for removing lambda would consider this to be a good example | |
# of why it should be removed. |