Skip to content

Instantly share code, notes, and snippets.

View Rembane's full-sized avatar
🔥

Andreas Ekeroot Rembane

🔥
View GitHub Profile
import time
# http://docs.python.org/2/library/time.html#time.sleep
while True:
bla()
time.sleep(0.005)
module Main where
-- This one works, but is terribly slow.
-- Make it faster!!!
step (my, mx) (y, x) = if my == y && mx == x
then 1
else stepY + stepX
where
stepY | y < my = step (my, mx) (y+1, x)
void count_freq(int *number, int number_length) {
int *freqs[MAX], *p1;
// Nollställ först
for(p1=freqs; p1 < freqs + MAX; p1++) {
*p1 = 0;
}
for(p1=number; p1 < number + number_length; p1++) {
freqs[*p1-1]++;
# encoding: utf-8
from bs4 import BeautifulSoup
from Cookie import SimpleCookie
import requests
url_template = u'http://wiki.sverok.se/w/index.php?title={}&action=edit'
with open('cookie.txt') as fh:
cookies = {k : v.value for k,v in SimpleCookie(fh.read()).items()}
@Rembane
Rembane / f.md
Last active June 17, 2016 17:14
  • ffffff-ffff, fff f fffffff
  • ffff FFFF ffff FFFF ffff FFFF
  • FFFFFFFFFF
  • F
  • fF
  • fffff, fffff, fffff, F
  • #ffffff
  • #FFFFFF
  • #fff
  • #FFF
@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!