Skip to content

Instantly share code, notes, and snippets.

View DavideCanton's full-sized avatar

Davide Canton DavideCanton

View GitHub Profile
@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)
@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 / 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
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 / 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,
@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 / 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 / pokemon.py
Created July 16, 2013 19:26
Pokemon move effect
__author__ = 'davide'
import operator
NO_EFFECT, NOT_EFFECTIVE, NORMAL, SUPEREFFECTIVE = range(4)
TYPES = list(zip(['Normale', 'Fuoco', 'Acqua', 'Elettro', 'Erba', 'Ghiaccio',
'Lotta', 'Veleno', 'Terra', 'Volante', 'Psico', 'Coleottero',
'Roccia', 'Spettro', 'Drago', 'Buio', 'Acciaio'], range(17)))
@DavideCanton
DavideCanton / bitset.h
Created September 9, 2013 10:57
bitset C++
class dyn_bitset
{
using byte_t = uint_fast8_t;
private:
int _size, _bits;
byte_t* _buf;
public:
dyn_bitset(int n)
@DavideCanton
DavideCanton / BF_Interpreter.h
Last active December 22, 2015 19:09
Brainf*ck interpreter in C++
#ifndef BFINTEPRETER_H_
#define BFINTEPRETER_H_
#include <iostream>
#include <cstdint>
#include <vector>
using namespace std;
namespace BF