Skip to content

Instantly share code, notes, and snippets.

View Rembane's full-sized avatar
🔥

Andreas Ekeroot Rembane

🔥
View GitHub Profile
#!/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)
#!/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
@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()
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 / 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
@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;
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 / 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]
@Rembane
Rembane / one_ring_to_rule_them_all.py
Created March 6, 2013 23:05
Ugliest script ever to remove the BOM from all Python files! :D
#!/usr/bin/env python
import os
for (path, dirs, files) in os.walk(os.getcwd()):
for f in [os.path.join(path, f) for f in files if f.endswith('.py')]:
fh_in = open(f)
if '\xEF\xBB\xBF' in fh_in.read(10):
fh_in.seek(0)
s = fh_in.read().replace('\xEF\xBB\xBF', '')
#include <stdio.h>
int main() {
unsigned long longest = 0;
unsigned long longest_collatz = 0;
unsigned long i = 2;
unsigned long collatz, length;
for(; i < 1000000; i++) {
collatz = i;
length = 0;