Skip to content

Instantly share code, notes, and snippets.

@Djexus
Djexus / spinningcircle.py
Created April 4, 2012 19:08
A script which make a spinning circle
import math
import pygame
from pygame.locals import *
class SpinningCircle(pygame.surface.Surface):
'''
Class which make a spinning circle
@Djexus
Djexus / ircregex.py
Created March 20, 2012 21:09
Regex to parse server's messages
nickname = r'[\w\x5b-\x60\x7b-\x7d]+'
username = r'[-+~=^]?[^@\s]+'
hostname = r'(?:\w|\d)+(?:[-.=](?:\w|\d)+)*'
mask = r'([\w\x5b-\x60\x7b-\x7d]+)(?:(?:!([-+~=^]?[^@\s]+))?@((?:\w|\d)+(?:[-.=](?:\w|\d)+)*))?'
servername = r'(?:\w|\d)+(?:[-.](?:\w|\d)+)*'
prefix = r'[\w\x5b-\x60\x7b-\x7d]+(?:(?:![-+~=^]?[^@\s]+)?@(?:\w|\d)+(?:[-.=](?:\w|\d)+)*)?|(?:\w|\d)+(?:[-.](?:\w|\d)+)*'
command = r'[A-Z]+|[0-9]{3}'
parametres = r'[^:]+'
trailing = r':(.+)'
message = r'^(?::([\w\x5b-\x60\x7b-\x7d]+(?:(?:![-+~=^]?[^@\s]+)?@(?:\w|\d)+(?:[-.=](?:\w|\d)+)*)|(?:\w|\d)+(?:[-.](?:\w|\d)+)*)\s)?([A-Z]+|[0-9]{3})(?: ([^:]+))?(?: :(.+))?$'
@Djexus
Djexus / textwriter.py
Created January 21, 2012 23:16
A script which simulate a person who writes a text
import re
import pygame
import itertools
from pygame.locals import *
NULLCHAR = '\0'
BACKSPACE = '\b'
LEFT = '\1'
@Djexus
Djexus / showstatus.py
Created January 5, 2012 01:26
Decorator which adds statusline to functions
import sys
BUSYMSG = '\033[1;34m[\033[1;m\033[1;36mBUSY\033[1;m\033[1;34m]\033[1;m'
DONEMSG = '\033[1;34m[\033[1;m\033[1;35mDONE\033[1;m\033[1;34m]\033[1;m'
FAILMSG = '\033[1;34m[\033[1;m\033[1;31mFAIL\033[1;m\033[1;34m]\033[1;m'
def showstatus(message=None, length=50):
@Djexus
Djexus / range-obj.py
Created December 9, 2011 13:10
Python's range... in Python
from math import ceil
class Range(object):
'''
Range(start, stop, step) returns the arithmetic progression
of numbers, whose lenght is ceil((stop - start) / step) and
whose form [start, start + (step * 1), ..., start + (step *
(len(obj) - 1)].
@Djexus
Djexus / range-obj.ss
Created December 6, 2011 22:59
Python's range object in Scheme
#lang racket
(define range
(case-lambda
((stop) (range 0 stop 1))
((start stop) (range start stop 1))
((start stop step) (list 'range start stop step))))
(define range?
(lambda (obj)
@Djexus
Djexus / getstring.py
Created September 23, 2011 14:25
A simple script which lets you write in the shell between two strings
# In memoria della programmazione funzionale, che qui giace
import sys
import tty
import termios
def write(string):
'''
@Djexus
Djexus / sexps.ss
Created September 20, 2011 20:22
A simple program in Scheme to solve expressions step by step
#lang racket
(define expr-operator
(lambda (expr)
(car (cdr expr))))
(define expr-operand1
(lambda (expr)
@Djexus
Djexus / machine.py
Created September 10, 2011 12:10
Turing machine in Python
from collections import defaultdict
class TuringMachine(object):
'''
    This class  implements Turing Machine developed by Alan
    Turing  in 1936. It has  to receive  two  arguments: an
    iterable  object for  the initial configuration  of the
    infinite tape  and a list  of 5-elements  tuple for the
@Djexus
Djexus / currying.ss
Created September 4, 2011 22:05
Currying syntax in Scheme
(define-syntax lambda-curried
(syntax-rules ()
((_ (a ...) b ...)
(letrec
((curry (lambda (func . passed-args)
(if (>= (length passed-args) (length '(a ...)))
(apply func passed-args)
(lambda new-args
(apply curry (cons func (append passed-args new-args))))))))
(curry (lambda (a ...) b ...))))))