Skip to content

Instantly share code, notes, and snippets.

View Rembane's full-sized avatar
🔥

Andreas Ekeroot Rembane

🔥
View GitHub Profile
runRandom :: State StdGen a -> IO a
runRandom x = do
g <- newStdGen
return $ evalState x g
@Rembane
Rembane / prime.hs
Last active January 2, 2016 18:29
A prime number generator, for fun!
import qualified Data.Vector as V
steppingPrimeGenerator :: (V.Vector Int, Int) -> (V.Vector Int, Int)
steppingPrimeGenerator (ps, x) | V.null $ V.filter ((==0) . (mod x)) ps = (V.snoc ps x, succ x)
| otherwise = (ps, succ x)
@Rembane
Rembane / exceptional_looping.py
Created January 7, 2014 12:28
The ugliness! :D
li = [...]
try:
while True:
c = li.next()
if condition(c):
break
except StopIteration:
# Not found...
@Rembane
Rembane / Magic.hs
Last active December 31, 2015 06:19
So, what happens when we wrap something in a monad? :D And what can we do with these endless possibilities?
{-# LANGUAGE NoMonomorphismRestriction #-}
-- If we aren't careful, the monomorphism restriction will bite our backs.
module Magic where
magic :: (Monad m) => Int -> Int -> m Int
magic a b = return $ a + b
main = magic 7 3
O
-|-
|||
|||
-
|||
| |
- -
http://www.youtube.com/watch?v=vTnSf8OjYQ0
@Rembane
Rembane / this_is_usable_code.py
Last active December 26, 2015 06:39
This is a tree which contains prefixes of names.
# Lets build a dictionary of people, like this:
names = [u'{} {}'.format(f.lower(),e.lower()) for (f,e) in Participant.objects.values_list('fname', 'ename').order_by('fname', 'ename')]
autocompletion_tree = defaultdict(list)
for (i,n) in enumerate(names):
s = ''
for c in n:
s += c
autocompletion_tree[s].append(i)
# Purge it!
@Rembane
Rembane / index.html
Created October 19, 2013 22:57
A Haste example!
<!DOCTYPE html>
<html>
<body>
<h1>My web page</h1>
This document has a heading and some text. <em>This sentence is emphasized.</em>
<script src="main.js" type="text/javascript"></script>
</body>
</html>
( 33/185) upgrading firefox [#######################################################] 100%
New optional dependencies for firefox
gstreamer0.10-bad-plugins: aac, vp8 and opus decoding [installed]
gstreamer0.10-base-plugins: vorbis decoding, ogg demuxing [installed]
gstreamer0.10-good-plugins: webm and mp4 demuxing [installed]
gstreamer0.10-ugly-plugins: h.264 decoding
@Rembane
Rembane / fizzbuzz.hs
Last active December 21, 2015 16:49
The typed solution for FizzBuzz.
module Main where
data FzBz = Fizz | Buzz | FizzBuzz | N Int
instance Show FzBz where
show Fizz = "Fizz"
show Buzz = "Buzz"
show FizzBuzz = "FizzBuzz"
show (N x) = show x
@Rembane
Rembane / .vimrc
Last active December 21, 2015 10:29
My Vim config
" Inget pip goddamit!
set visualbell
syntax on
set autoindent
set nosmartindent
set tabstop=4
set expandtab
set shiftwidth=4
set hlsearch " Higliht searched words