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
# Released under Unlicense. | |
from inspect import getattr_static | |
import functools | |
class monkeypatch: | |
""" Decorator for all your evil monkeypatching needs. | |
Functions as a class decorator: | |
@monkeypatch(Foo) |
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
-- standard "loeb" combinator | |
-- https://github.com/quchen/articles/blob/master/loeb-moeb.md | |
loeb :: Functor f => f (f a -> a) -> f a | |
loeb x = go where go = fmap ($ go) x | |
-- "monadic loeb"? | |
loebM :: (Traversable t, Monad m) => t (t a -> m a) -> m (t a) | |
loebM = sequenceA . loeb . fmap (\f xs -> f =<< sequenceA xs) |
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 System.Random | |
import Data.Monoid | |
import Control.Applicative | |
import Control.Monad | |
randomRsIO range = randomRs range <$> newStdGen | |
numPlayables :: Int -> [Int] -> Int | |
numPlayables energy costs = zeros + nonzeros | |
where |
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
{-# LANGUAGE UnboxedTuples #-} | |
{-# LANGUAGE MagicHash #-} | |
module FastFibo where | |
import GHC.Exts | |
type Mat2x2 = (# Int#, Int#, Int#, Int# #) | |
type Vec2 = (# Int#, Int# #) |
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 abc import ABCMeta, abstractmethod | |
def do_nothing(f): | |
"""A decorator that swallows the function and does nothing with it.""" | |
pass | |
def instantiate(callable): | |
"""A decorator that replaces a class definition with an instance of the class. | |
Useful for making opaque singleton objects. |
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
{-# LANGUAGE BlockArguments #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE LambdaCase #-} | |
module Objects.File where | |
import Control.Monad | |
import System.IO | |
import Objects |
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
:set prompt "\ESC[1;34m%s\n\ESC[0;34mλ> \ESC[m" | |
:set prompt-cont "\ESC[0;34mλ| \ESC[m" |
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
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE RoleAnnotations #-} | |
module IxSTRef | |
( IxSTRef, ixSTRefId, ixSTRef | |
, IxCounter, withIxCounter, newIxSTRef | |
) where | |
import Control.Monad.ST | |
import Data.Function | |
import Data.STRef |
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
{-# OPTIONS_GHC -Wno-unticked-promoted-constructors -freduction-depth=0 #-} | |
{-# LANGUAGE AllowAmbiguousTypes #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE ExplicitForAll #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} |
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 note: This is pretty much strictly worse than the functionality | |
-- offered by <hackage.haskell.org/package/async> . Use this library if | |
-- you cannot be bothered to depend on async. | |
module Timeout where | |
import Control.Concurrent | |
import Control.Exception | |
data TimeoutException = TimeoutException Int | |
instance Show TimeoutException where |
NewerOlder