Skip to content

Instantly share code, notes, and snippets.

View Rembane's full-sized avatar
🔥

Andreas Ekeroot Rembane

🔥
View GitHub Profile
@Rembane
Rembane / inf_eratosthenes.hs
Last active December 12, 2015 07:19
This version of Eratosthenes sieve works on infinite lists! :D
-- A simpler version, should give the same output as the former one.
eratosthenes2 (x:[]) = [x]
eratosthenes2 (x:xs) = x:eratosthenes2 [y | y <- xs, (mod y x) /= 0]
data Alg = Num' Int
| Add Alg Alg
| Sub Alg Alg
| Mul Alg Alg
deriving (Show)
consume :: Alg -> Int
consume (Num' x) = x
consume (Add a b) = (consume a) + (consume b)
consume (Sub a b) = (consume a) - (consume b)
@Rembane
Rembane / Monoid.c
Last active December 11, 2015 21:49
I heard you liked Monoidstructs so I...
typedef struct MonoidInterface {
struct MonoidInterface (*op)(MonoidInterface*);
struct MonoidInterface (*id)();
} MonoidInterface;
@Rembane
Rembane / Shootyear.hs
Created January 27, 2013 20:36
The awesome code of https://gist.github.com/4638535 implemented in Haskell, but sadly without GUI.
module Main where
import Data.Maybe
isShootYear yr = [mod yr 400 == 0, mod yr 4 == 0, mod yr 100 /= 0] == [True, True, False]
isShootYearMsg True = "är ett skottår"
isShootYearMsg False = "är inte ett skottår"
maybeRead :: Read a => String -> Maybe a
maybeRead s = case reads s of
import javax.swing.*;
public class Shootyear {
public static void main(String[] args) {
int år = 0;
String indata = "";
while (indata != null) {
do {
try {
indata = JOptionPane.showInputDialog("Ett år tak");
@Rembane
Rembane / renamefiles.py
Last active December 11, 2015 08:38
Changes the names of all files in a directory to prefix + index + suffix
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
from functools import partial
import os
joincur = partial(os.path.join, os.getcwd())
print "Ange det nya prefixet på filerna: "
prefix = raw_input()
#!/usr/bin/env python
#-*- coding: UTF-8 -*-
# Ett enkelt Python-program ser oftast ut såhär på en *nix:
# Spara den som letest.py
print "Hje!"
# Körs enklast i terminal med följande sträng:
# python letest.py
#!/usr/bin/env python
from os.path import splitext
import sys
name, suff = splitext(sys.argv[1])
fi = 0
fh = open('%s%s.%s' (name, fi, suff), 'w')
for i,row in enumerate(open(sys.argv[1])):
fh.write(row)
@Rembane
Rembane / reset_password_view.py
Created July 16, 2012 12:24
A view to reset a user's password.
def reset_password(request):
form = PasswordForm(request.POST or None)
fluff = { 'page_title' : u'Återställ lösenord',
'button_text' : 'Skicka nytt lösenord',
'form' : form
}
if request.method == 'POST':
if form.is_valid():
kwargs = {k : v for k,v in zip(('etag', 'modified'), map(lambda x: getattr(self, x), ('etag', 'last_visited'))) if v}