Skip to content

Instantly share code, notes, and snippets.

Jeremy Mikkola jmikkola

Block or report user

Report or block jmikkola

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View runtime_types.hs
import System.IO (hFlush, stdout)
main :: IO ()
main = do
putStr "enter a number> "
hFlush stdout
line <- getLine
runNested (read line) True
-- a will be the type Bool wrapped in a List n times by the end
View indent_parser_cheatsheet.hs
import Data.Functor.Identity
import Text.Parsec
import Text.Parsec.Indent
example1 = "asdf(1 2 3):\n foo\n x:\n y\n z:\n q\n a"
-- Data structures
data Tree = Node [Value] [Tree]
View 5_cards_puzzle.hs
import Data.List (sort, permutations, elemIndex)
data Card = Card Suit Int
deriving (Show, Eq, Ord)
data Suit = Spades | Clubs | Hearts | Diamonds
deriving (Show, Eq, Ord)
suits = [Spades, Clubs, Hearts, Diamonds]
View TypingHaskellInHaskell_modernized.hs
-- I have made minor changes to the file below to make it compile
-- with GHC 8.0
-----------------------------------------------------------------------------
-- Thih: Typing Haskell in Haskell, main program
View effects.hs
{-# LANGUAGE DeriveFunctor #-}
-- This needs the 'free' package installed in order to build
import Control.Monad (when)
import Control.Monad.Free (Free (..))
import System.IO (hFlush, stdout)
main :: IO ()
main = runIOOp exampleProgram
View rdarkmod.el
;;; rdarkmod-theme.el --- Theme
;; Copyright (C) 2016 , Jeremy M
;; Author: Jeremy M
;; Version: 0.1
;; Package-Requires: ((emacs "24"))
;; Created with ThemeCreator, https://github.com/mswift42/themecreator.
View collatz_histo.py
mem = {}
def collatz_len(n):
if n < 2:
return 1
if n not in mem:
chain = 1 + collatz_len(n/2 if n%2 == 0 else 3*n + 1)
mem[n] = chain
return mem[n]
View n_balls_k_buckets.py
def f(k, n):
'''
k indistinct bucket,
n (n > k) balls,
each bucket must have at least one ball,
how many ways are there to put n balls in k buckets?
'''
if k == 1:
# Only one way to put things in one bucket
return 1
View ioref.hs
import Control.Monad (liftM)
import Data.IORef (IORef, newIORef, modifyIORef', readIORef)
import Data.Map (Map)
import qualified Data.Map as Map
import Control.Monad.Trans.Except (ExceptT, Except, except, runExcept, mapExcept, throwE)
import Control.Monad.IO.Class (liftIO)
data IVal
= IInt Int
View free_monad_mvp.hs
{-# LANGUAGE DeriveFunctor #-}
import Control.Monad.Free
data MThing next
= MItem String next
| MEnd
deriving (Show, Functor)
doThing :: Free MThing ()
You can’t perform that action at this time.