Skip to content

Instantly share code, notes, and snippets.

View Rembane's full-sized avatar
🔥

Andreas Ekeroot Rembane

🔥
View GitHub Profile
#!/usr/bin/env python3
import os
import os.path
import re
import subprocess
currdir = os.path.dirname(os.path.realpath(__file__))
picpattern = re.compile(r'(jpg|cr2)$', flags=re.IGNORECASE)
datepattern = re.compile(r'(\d{4}):(\d{2}):(\d{2})')
@Rembane
Rembane / FizzBuzz4.hs
Created May 21, 2015 10:12
Another FizzBuzz. This time with lots of recursion.
module Main where
continue :: ([a] -> [b]) -> [a] -> [b]
continue _ [] = []
continue f (x:xs) = f (x:xs)
f1, f2, f3, b1, b2, b3, b4, b5 :: [Int] -> [(Bool, String)]
f1 (x:xs) = (False, show x):continue f2 xs
f2 (x:xs) = (False, show x):continue f3 xs
@Rembane
Rembane / msgorder.erl
Created May 13, 2015 14:37
How to get messages in correct order, with interference.
-module(msgorder).
-compile(export_all).
% How to get messages in correct order, even though things outside of our
% control try to put them in a semi-random order.
f(T, X) ->
Parent = self(),
Ref = make_ref(),
spawn_link(fun() -> timer:send_after(T, Parent, {Ref, {T, X}}) end),
import sys
from time import sleep
from threading import Thread
def communicator():
print('This does not print')
sys.stdout.flush()
while(True):
#frame.evaluateJavaScript('document.getElementById("footer").appendChild(document.createTextNode("Hejjibejj"));')
#fr.evaluateJavaScript('alert("Yo");')
@Rembane
Rembane / FizzBuzz3.hs
Created August 18, 2014 23:00
More Fizzbuzz!
import Data.Maybe
mrd n x | mod n x == 0 = Just n
| otherwise = Nothing
lp = map (\n -> head . catMaybes $ zipWith (\f v -> v >> return f) ["FizzBuzz", "Fizz", "Buzz", show n] (map (mrd n) [15, 3, 5, 1])) [1..]
main :: IO ()
main = putStr $ unlines $ take 100 lp
@Rembane
Rembane / ssnLab.hs
Created June 26, 2014 23:13
Just fooling around with personnummer-validation.
import Data.Char
import Data.List
type Personnummer = [Int]
mod10 x = mod x 10
cleanAndConvert :: String -> Maybe Personnummer
cleanAndConvert cs = return $ map digitToInt $ filter isDigit cs
@Rembane
Rembane / restore_firewall.sh
Created June 6, 2014 14:34
This is my firewall restoration script.
#!/bin/bash
iptables -F # Flush all!
iptables -X # Delete all custom chains!
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
@Rembane
Rembane / PrintCompile.hs
Created April 24, 2014 20:44
Det kan vara så att jag blev lite ivrig efter dagens Perlande...
import Control.Monad
import Data.Char
import Data.List
color s c = "\x1b[38;5;" ++ show c ++ "m" ++ s ++ "\x1b[0m"
txt = map chr $ foldr (\a (b:bs) -> (a+b):(b:bs)) [32] [(-12),2,(-3),7,(-3),7,69]
main = sequence_ $ cycle $ map (\c -> putStr $ color txt c) [0..256]
#include<stdio.h>
int main() {
printf("1 == %i\n", 1);
printf("~1 == %i\n", ~1);
printf("~~1 == %i\n", ~~1);
return 0;
}
,>, Input two bytes
[-<+>] While the second byte is greater than zero add it to the first byte
<. Print the first byte