Skip to content

Instantly share code, notes, and snippets.

View Rembane's full-sized avatar
🔥

Andreas Ekeroot Rembane

🔥
View GitHub Profile
@Rembane
Rembane / drunkenbot.py
Created June 26, 2012 13:53
A bot built in Python on top of Twisted when I was drunk.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from random import choice, randint
from time import sleep
from twisted.words.protocols import irc
from twisted.internet import protocol, reactor
import sys
memory = []
kwargs = {k : v for k,v in zip(('etag', 'modified'), map(lambda x: getattr(self, x), ('etag', 'last_visited'))) if v}
@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():
#!/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)