Skip to content

Instantly share code, notes, and snippets.

View DavideCanton's full-sized avatar

Davide Canton DavideCanton

View GitHub Profile
@DavideCanton
DavideCanton / yt.js
Last active December 19, 2015 11:29
My TamperMonkey script. It enables a new function on Youtube, for opening the current video in another window.
// ==UserScript==
//
// @name YT
// @version 1.0
// @author Davide Canton
//
// @include http://www.youtube.com/watch?v=*
// @match http://www.youtube.com/watch?v=*
// @include https://www.youtube.com/watch?v=*
// @match https://www.youtube.com/watch?v=*
@DavideCanton
DavideCanton / ex_fsm.py
Last active December 19, 2015 10:49
Simple Finite State Machine implementation using the State Pattern with Python 3.x. There is also an example of a FSM that recognizes the a+bc* regex.
__author__ = 'davide'
import fsm
# automa di a+bc*
class Q0(fsm.State):
def next(self, input, fsm):
if input == 'a':
@DavideCanton
DavideCanton / bf.py
Last active December 19, 2015 05:19
Simple Brainfuck interpreter
__author__ = 'davide'
import numpy as np
LEFT, RIGHT, INCR, DECR, INPUT, OUTPUT, WHILE, WEND = range(8)
opcodes = {'<': LEFT,
'>': RIGHT,
'+': INCR,
'-': DECR,
',': INPUT,
expr(n(T1, O, T2)) --> term(T1), addop(O), expr(T2).
expr(T1) --> term(T1).
term(n(F1, O, F2)) --> fact(F1), mulop(O), term(F2).
term(F1) --> fact(F1).
fact(l(I)) --> [I], {integer(I)}.
fact(E) --> ['('], expr(E), [')'].
addop(add) --> [+].
addop(sub) --> [-].
mulop(mul) --> [*].
mulop(div) --> [/].
@DavideCanton
DavideCanton / solitario.py
Last active December 18, 2015 01:18
Solitario
import numpy as np
import numpy.random as nprand
def simula(num):
num = nprand.permutation(num)
for i in range(3):
if len((num[i::3] == i + 1).nonzero()):
return False
return True
@DavideCanton
DavideCanton / ip_mgmt.py
Last active December 16, 2015 11:39
IP Management tool written in Python 3.2
#! /usr/bin/python3.2
from tkinter.tix import Tk
from tkinter.ttk import Label, Entry, Button, Combobox
import sys
from tkinter.messagebox import showerror
from tkinter import StringVar
from tkinter.constants import S, E, N, W, CENTER, FALSE, DISABLED
try:
from wmi import WMI
except ImportError:
@DavideCanton
DavideCanton / NimGame.hs
Last active December 16, 2015 11:29
Nim game implemented in Haskell.
module Nim.NimGame where
import Control.Applicative ((<$>))
import Control.Monad (guard, msum, unless)
import Control.Monad.Trans (liftIO)
import Control.Monad.Trans.Maybe (MaybeT, runMaybeT)
import Control.Monad.Trans.State (StateT, evalStateT, get, put)
import Data.Bits (shiftR, (.|.))
import Data.Char (toLower)
import Data.Maybe (fromJust)