This file contains hidden or 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 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] |
This file contains hidden or 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
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) |
This file contains hidden or 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
typedef struct MonoidInterface { | |
struct MonoidInterface (*op)(MonoidInterface*); | |
struct MonoidInterface (*id)(); | |
} MonoidInterface; |
This file contains hidden or 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
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 |
This file contains hidden or 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 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"); |
This file contains hidden or 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
#!/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() |
This file contains hidden or 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
#!/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 |
This file contains hidden or 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
#!/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) |
This file contains hidden or 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
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(): |
This file contains hidden or 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
kwargs = {k : v for k,v in zip(('etag', 'modified'), map(lambda x: getattr(self, x), ('etag', 'last_visited'))) if v} |