Skip to content

Instantly share code, notes, and snippets.

View debonx's full-sized avatar
🍕
Food processing

Emanuele De Boni debonx

🍕
Food processing
View GitHub Profile
@debonx
debonx / accuracy_recall_precision_f1.py
Created December 11, 2018 10:23
Accuracy, Recall, Precision and F1 score with sklearn.
# To be reminded
# 1) Classifying a single point can result in a true positive (truth = 1, guess = 1), a true negative (truth = 0, guess = 0), a false positive (truth = 0, guess = 1), or a false negative (truth = 1, guess = 0).
# 2) Accuracy measures how many classifications your algorithm got correct out of every classification it made.
# 3) Recall measures the percentage of the relevant items your classifier was able to successfully find.
# 4) Precision measures the percentage of items your classifier found that were actually relevant.
# 5) Precision and recall are tied to each other. As one goes up, the other will go down.
# 6) F1 score is a combination of precision and recall.
# 7) F1 score will be low if either precision or recall is low.
from sklearn.metrics import accuracy_score, recall_score, precision_score, f1_score
@debonx
debonx / missing-integers.js
Last active September 30, 2022 09:36
JavaScript: Simple function to find positive missing integers in Array of numbers.
/* Write a function solution(A); that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];
each element of array A is an integer within the range [−1,000,000..1,000,000]. */
const A = [-1, -4];
@debonx
debonx / php.ini
Last active December 13, 2021 23:04
Optimal php.ini configuration for Wordpress, see also https://xilab.co/what-are-the-best-wordpress-php-ini-settings/
# Wordpress php.ini configuration
upload_max_filesize = 32M
post_max_size = 32M
memory_limit = 128M
max_execution_time = 60
max_input_vars = 10000
max_input_time = 30
@debonx
debonx / wc_product_image_thumbs.php
Last active September 5, 2021 12:05
WooCommerce snippet to customise Single Product image thumbs.
<?php /**
* Single Product Thumbnails
*
* @param array $args
* @param int $attachment_id
* @param string $image_size
* @param bool $main_image
* @return array
*/
function bones_gallery_image_html_attachment_image_params ( $args, $attachment_id, $image_size, $main_image )
@debonx
debonx / naive_bayes_classifier.py
Last active November 28, 2020 11:05
Naive Bayes classifier in Python
#Import datasets and libraries
from sklearn.datasets import fetch_20newsgroups
from sklearn.naive_bayes import MultinomialNB
from sklearn.feature_extraction.text import CountVectorizer
#Category selection to compare different datasets of emails and evaluate how hard is to distinguish those.
the_categories = ['comp.sys.ibm.pc.hardware', 'rec.sport.hockey']
train_emails = fetch_20newsgroups(categories = the_categories, subset = 'train', shuffle = True, random_state = 108)
test_emails = fetch_20newsgroups(categories = the_categories, subset = 'test', shuffle = True, random_state = 108)
@debonx
debonx / luhns-algorithm.c
Last active November 28, 2020 11:02
Luhn's algorithm implementation for credit card sequence validation.
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_card_length(long card)
{
int length = 0;
while (card > 0)
{
@debonx
debonx / media-queries.scss
Created April 25, 2020 15:27 — forked from chrisjlee/media-queries.scss
All Media Queries breakpoints
@media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ }
@media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ }
@media (min-width:600px) { /* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */ }
@media (min-width:801px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
@debonx
debonx / database.sql
Created January 31, 2020 15:44
SQL: Create, insert, Alter, Update, Delete and Select.
CREATE TABLE friends (
id INTEGER,
name TEXT,
birthday DATE
);
INSERT INTO friends (id, name, birthday)
VALUES
(1, 'Jane Doe', '1990-05-30'),
(2, 'Richard Stallman', '1953-03-16'),
@debonx
debonx / rooster.js
Last active January 26, 2020 10:05
Node, Mocha: Simple test suite for Rooster object with Mocha and Node asserts methods. (https://mochajs.org, https://nodejs.org/api/assert.html).
// Define a rooster
Rooster = {};
// Return a morning rooster call
Rooster.announceDawn = () => {
return 'moo!';
}
// Return hour as string
// Throws Error if hour is not between 0 and 23 inclusive
@debonx
debonx / factorial.js
Created January 26, 2020 10:04
Node, Mocha: Simple factorial test suite with Mocha and Node assertion methods.
const Calculate = {
factorial(number) {
if(number === 0) {
return 1;
}
for(let i = number - 1; i >= 1; i--) {
number *= i;
}
return number;
}