Skip to content

Instantly share code, notes, and snippets.

@FedericoPonzi
FedericoPonzi / hsvThreshold.py
Last active January 20, 2021 17:52
Find thresholds for hsv for opencv (inRange opencv function) using your webcam. From: https://raw.githubusercontent.com/saurabheights/IPExperimentTools/master/AnalyzeHSV/hsvThresholder.py
# Preview: https://raw.githubusercontent.com/FedericoPonzi/LegoLab/master/media/hsv-colour.png
import cv2
import sys
import numpy as np
def nothing(x):
pass
useCamera=False
@FedericoPonzi
FedericoPonzi / tictactoe.py
Created August 7, 2018 15:17
A tic tac toe in python3
class IllegalMoveError(ValueError):
pass
class TicTacToe:
def __init__(self):
self.grid = [0 for i in range(9)]
self.turn = "x"
def run(self):
while not self.isOver():
@FedericoPonzi
FedericoPonzi / client.py
Created August 24, 2018 10:51
Hackerrank sorted set solution
import struct
import socket
import os
import sys
class NetworkHandler():
def __init__(self, sock):
self.sock = sock
def myreceive(self):
@FedericoPonzi
FedericoPonzi / Dockerfile
Created September 19, 2018 14:01
Dockerfile for spring boot + gradle.
FROM gradle:jdk8-alpine
VOLUME gradle-cache:/home/gradle/.gradle
VOLUME /tmp
USER root
ADD . /home/gradle/project
WORKDIR /home/gradle/project
RUN chown gradle:gradle -R /home/gradle
USER gradle
RUN gradle bootJar
#Start from a java:8
@FedericoPonzi
FedericoPonzi / Main.java
Last active January 21, 2021 06:47
Google's compression and decompression challange
package me.fponzi;
class Main {
static class Pair{
// Result string
String ret;
// Position of the consumed portion of the string.
int val;
public Pair( String ret, int val) {
@FedericoPonzi
FedericoPonzi / first.sh
Last active August 20, 2019 08:02
Setup typescript project
#from: https://basarat.gitbooks.io/typescript/docs/quick/nodejs.html
npm init -y
npm install typescript --save-dev
npm install @types/node --save-dev
npx tsc --init --rootDir src --outDir lib --esModuleInterop --resolveJsonModule --lib es6,dom --module commonjs
# Done! use `code .` to fireup visual studio.
@FedericoPonzi
FedericoPonzi / main.rs
Created August 27, 2019 08:28 — forked from codesections/main.rs
Warp_proof_of_concept
use futures::{Async, Future, Poll};
use tokio::io::{AsyncRead, AsyncWrite, Error, ReadHalf, WriteHalf};
use tokio::net::TcpStream;
use warp::{path, Filter, Stream};
struct Receiver {
rx: ReadHalf<TcpStream>,
}
impl Stream for Receiver {
type Item = String;
@FedericoPonzi
FedericoPonzi / top_sort.rs
Created January 20, 2020 21:50
Topological sort in rust
use crate::error::Result;
use crate::formats::Service;
use std::collections::BTreeMap;
/// Get a starting executon order
/// Result is a vector of vectors(batches) of Service.
/// Each batch has no dependence between each other so they can be started in parallel.
/// TODO: this might deadlock if `services` is not a DAG.
/// TODO: this topological sorting works, every process in set index i + 1 has only
/// dependencies in `0...i`. But, this might lead to a non optimal solution, because if a process j + 1 has a dependency
@FedericoPonzi
FedericoPonzi / CI.yml
Last active May 4, 2024 07:19
Ready to use Github workflow for cross-compiling a rust binary to many Linux architectures.
# Instruction + template repo: https://github.com/FedericoPonzi/rust-ci
# Search and replace <YOUR_BINARY_NAME> with your binary name.
name: CI
on:
pull_request:
push:
branches:
- master
tags:
@FedericoPonzi
FedericoPonzi / ffun_interpreter.sml
Created August 23, 2020 12:50
Project for my Programming languages exam, an interpreter for a programming language called ffun.
datatype ffun = const of int (* Possiamo trovare delle costanti intere *)
| plus of (ffun*ffun) (* Addizione *)
| var of string (* Variabili di tipo stringhe *)
| llet of (string*ffun*ffun) (* La funzione let, che prende una variabile stringa, e due oggetti di tipo ffun *)
| fffun of (string*ffun) (* Una funzione *)
| ycombinator of (ffun)
| appl of (ffun*ffun)
| ifelse of (ffun*ffun*ffun)
| minus of ffun
| prod of (ffun*ffun);