Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / counter.lex
Created June 16, 2018 10:10
Simple lex example to count lines and chars.
%{
#include <stdio.h>
int num_lines = 0, num_chars = 0;
%}
%%
\n ++num_lines; ++num_chars;
. ++num_chars;
%%
main() {
/*
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property and
* proprietary rights in and to this software and related documentation.
* Any use, reproduction, disclosure, or distribution of this software
* and related documentation without an express license agreement from
* NVIDIA Corporation is strictly prohibited.
*
* Please refer to the applicable NVIDIA end user license agreement (EULA)
@FedericoPonzi
FedericoPonzi / SendMail.java
Created May 19, 2018 10:26
An example to send HTML mail with attachment in java. No ssl/tls. Raw
package me.fponzi;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.util.StringTokenizer;
import java.util.TreeMap;
class FrequenzeDiParoleInUnaStringa
{
private String stringa; //La stringa da analizzare
private TreeMap<String, Integer> dictionary = new TreeMap<String, Integer>(); //Inizializzo il TreeMap
FrequenzeDiParoleInUnaStringa(String stringa)
{
@FedericoPonzi
FedericoPonzi / cuda-versions.txt
Created January 15, 2018 09:05
For reference, on linux, the previous CUDA toolkits required the following minimum driver versions
CUDA 9.1: 387.xx
CUDA 9.0: 384.xx
CUDA 8.0 375.xx (GA2)
CUDA 8.0: 367.4x
CUDA 7.5: 352.xx
CUDA 7.0: 346.xx
CUDA 6.5: 340.xx
CUDA 6.0: 331.xx
CUDA 5.5: 319.xx
CUDA 5.0: 304.xx
@FedericoPonzi
FedericoPonzi / menu.php
Created January 4, 2018 09:34
A very simple menu.php for automatically higlight the page based on the name. For semi-static websites.
<?php
class MenuItem{
var $name;
var $url;
var $icon;
function __construct($n, $u, $i)
{
$this->name = $n;
$this->url = $u;
$this->icon = $i;
@FedericoPonzi
FedericoPonzi / wrap_malloc.c
Created November 15, 2017 14:26
Malloc/callloc ecc wrappers from bwa source
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef USE_MALLOC_WRAPPERS
/* Don't wrap ourselves */
# undef USE_MALLOC_WRAPPERS
#endif
#include "malloc_wrap.h"
@FedericoPonzi
FedericoPonzi / 21.cpp
Created November 5, 2017 15:34
This is my first attempt to learn CUDA, and is the solution for the problem 21 on project euler.
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <string>
using namespace std;
void divide(int N, long* m){