Skip to content

Instantly share code, notes, and snippets.

View DavideCanton's full-sized avatar

Davide Canton DavideCanton

View GitHub Profile
@DavideCanton
DavideCanton / .gitconfig
Last active January 30, 2023 08:49
Git useful aliases
[alias]
cln = !git fetch --prune && git branch --verbose | grep gone | awk '{ print $1 }' | xargs -r git branch -D
fall = !for b in $(git branch -l --format "%(refname:lstrip=2)"); do git fetch origin $b:$b; done
st = status -s
cl = clone
ci = commit
co = checkout
br = branch
r = reset
cp = cherry-pick
@DavideCanton
DavideCanton / unionfind.py
Created February 23, 2014 15:55
Union find in Python
__author__ = 'davide'
import collections
class Element:
def __init__(self, parent, rank=0, size=1):
self.parent = parent
self.rank = rank
self.size = size
@DavideCanton
DavideCanton / quadtree.py
Created May 1, 2014 12:57
Quad Tree Python implementation.
__author__ = 'davide'
from collections import namedtuple, deque
from random import randint
import sys
import itertools as it
class Rect(namedtuple("_Rect", "x, y, w, h")):
def __contains__(self, point):
@DavideCanton
DavideCanton / sudoku.logic
Last active June 16, 2021 21:58
Sudoku solver with Clingo
cell_index(0..8).
cell_value(1..9).
% fill with initial values
initial_pos(0, 3, 4).
initial_pos(0, 6, 1).
initial_pos(0, 7, 5).
initial_pos(1, 1, 8).
initial_pos(1, 2, 1).
initial_pos(1, 3, 9).
@DavideCanton
DavideCanton / graph_diff_eq.py
Last active April 15, 2019 22:20
Graphical Differential equations
import itertools as it
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
mu = 0.3
L = 10
g = 9.8
DELTA = 0.01
T = 1000
@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 / Main.hs
Last active December 30, 2015 00:39
Paolify
module Main where
import Data.Char
import Control.Monad
import System.IO
type Token = (String, Bool)
mySplit :: (Char -> Bool) -> String -> [Token]
mySplit _ "" = []
@DavideCanton
DavideCanton / factor.scm
Created September 20, 2013 23:05
Integer factorization in Chez Scheme
(define factor
(lambda (n)
(let ([next (lambda (i)
(if (zero? (modulo i 2))
(1+ i)
(+ 2 i)))])
(let f ([n n] [i 2])
(let ([d (/ n i)] [s (sqrt n)])
(cond
[(>= i s) (list 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
@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)))