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
import Criterion.Main | |
prswap [] = [] | |
prswap (a:b:xs) = b:a:prswap xs | |
prswap' [] = [] | |
prswap' list = reverse (take 2 list) ++ prswap (drop 2 list) | |
main = defaultMain [ bgroup "prswap" [ bench "prswap [1..1000]" $ whnf prswap [1..1000] | |
, bench "prswap [1..10000]" $ whnf prswap [1..10000] |
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
module KleisliComp where | |
import Control.Arrow | |
import Data.Foldable | |
import Data.Monoid | |
import Data.Monoid.Endomorphism | |
-- After explicitly writing the KleisliEndo instance, I realized that it could | |
-- be built using existing infrastructure, namely the Kleisli category instance | |
-- and the Monoid instance for category endomorphism composition. |
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
wrapM :: Monad m => (a -> b) -> (a -> m b) | |
wrapM = (return .) | |
-- same as wrapM f = \x -> return (f x) |
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 heapq import heapify, heappop | |
from binascii import a2b_hex | |
from collections import defaultdict | |
from struct import unpack | |
from sys import argv, exit | |
def parse_byte(bstring): | |
return unpack('>B', a2b_hex(bstring))[0] | |
def dijkstra(graph, source): |
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
# Jack Diederich wrote the advance function | |
# original code from http://pyvideo.org/video/880/stop-writing-classes | |
import collections | |
import curses | |
import gettext | |
import random | |
import signal | |
import sys | |
import time |
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
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
| _ _ _ _ | _ _ _ _ _ | | |
| |_|_ |_|_ _| _|_ _ _| | | |
| |_ _|_ | |_| |_ _ _| |_| | |
|_| |_ _ _|_ _ _| |_ _| | |
| | |_ _ | |_|_|_ | _|_ | | |
| _| | |_|_ _| |_ _ | | | |
| | | _| |_| |_ _ _| | | | |
| |_| |_|_ _ | |_ _|_ _|_ | | | |
|_| _| _ _ _| | | | _ _ | |_| |
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
Copyright 2014 Chas Leichner | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, |
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 | |
''' | |
The MIT License (MIT) | |
Copyright (c) 2013 Chas Leichner | |
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 |
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
''' | |
Null module: | |
Responds to all actions and requests for members with a null object. | |
For example, this code will execute the debugging tools in development, but | |
won't do anything in production. | |
if environment == development: | |
import ExpensiveDebugging | |
else: |
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
import Control.Monad | |
import Data.List | |
data BF a = Add a | |
| Move a | |
| StartLoop | |
| EndLoop | |
| Write | |
| Read | |
| Zero |
OlderNewer