Skip to content

Instantly share code, notes, and snippets.

View debonx's full-sized avatar
🍕
Food processing

Emanuele De Boni debonx

🍕
Food processing
  • adidas ///
  • Amsterdam
View GitHub Profile
@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 / wp_users_contact_methods.php
Last active October 21, 2018 16:52
Add contact methods to Wordpress User dashboard, like social media or external urls. Add this code to your theme's functions.php.
add_filter( 'user_contactmethods','huraji_contactmethods', 20, 1 );
function huraji_contactmethods( $contact_methods ) {
$contact_methods['linkedin'] = __( 'LinkedIn URL', 'text_domain' );
$contact_methods['github'] = __( 'Github URL', 'text_domain' );
$contact_methods['youtube'] = __( 'YouTube URL', 'text_domain' );
return $contact_methods;
}
@debonx
debonx / get_url_param.js
Last active November 21, 2018 15:31
JQuery / Javascript small function to get url parameters, for example https://your-link?param=value.
function get_url_param(name){
var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);
if (results==null){
return null;
} else {
if(results[1].indexOf("#")){
results = results[1].split("#");
results = results[0];
} else {
results = results[1] || 0;
@debonx
debonx / matplotlib_example.py
Last active August 21, 2019 10:21
Example of using Matplotlib library to display data on graphs. More at https://matplotlib.org/.
from matplotlib import pyplot as plt
#Set data to display > [lists]
x = [1,7,5,2]
y1 = [5,6,3,9]
y2 = [7,8,4,0]
#Create plots with line colors and marker style
plt.plot(x, y1, color="pink", marker="o")
plt.plot(x, y2, color="gray", marker="o")
@debonx
debonx / numpy_example.py
Created November 1, 2018 11:53
Using Numpy example. Records of weekly weather temperatures. More at www.numpy.org.
import numpy as np
#Get data from CSV
#Temperatures recorded 4 times a day, at 0:00, 6:00, 12:00, and 18:00. Last weeks data (Monday through Friday)
temperatures = np.genfromtxt('temperature_data.csv', delimiter=',')
#Adjust temperatures
temperatures_fixed = temperatures + 3.0
#Select Monday's Temperatures
@debonx
debonx / pandas_example.py
Created November 1, 2018 15:38
Using Pandas library example. More at https://pandas.pydata.org/
import pandas as pd
#Read CSV file
orders = pd.read_csv('shoefly.csv')
#Inspect first 5 lines
print(orders.head(5))
#Get a specific serie of data / column
emails = orders['email']
@debonx
debonx / wp_update_transient.php
Created November 2, 2018 17:49
How to update and check transients on Wordpress. More at https://xilab.co.
/*
* @param $tag = tag to use for this transient
* @param $element = value to associate the transient
* @param $duration / $expiration = time in seconds > 3600*24 for 1 day
* @return true > if needed to update | false > if still not expired
*/
function update_transient($tag, $element, $duration, $expiration){
$elements_in_tag = get_transient($tag);
@debonx
debonx / wp_debugging.php
Last active November 11, 2018 08:29
Fast debugging method with Wordpress.
/*
* Put this function in your plugin or functions.php and pass the parameter $log to be debugged.
* Example: wpui_write_log( $log ) where $log is the data to be debugged.
* It writes into /debug.log of your wp-content/
* Could be used as class method as well
*/
function wpui_write_log( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
@debonx
debonx / scikit_learn_example.py
Created November 12, 2018 10:00
Basic Example to work with Scikit-Learn for calculating Linear Regressions. More at https://scikit-learn.org/
#Import LinearRegression methods from Scikit-Learn
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
import numpy as np
#Data of Soup sales with their temperature
temperature = np.array(range(60, 100, 2))
temperature = temperature.reshape(-1, 1)
sales = [65, 58, 46, 45, 44, 42, 40, 40, 36, 38, 38, 28, 30, 22, 27, 25, 25, 20, 15, 5]
@debonx
debonx / scikit_predictive_power.py
Created November 12, 2018 11:00
Analyse the predictive power of your algorithm with Scikit-Learn. More at https://scikit-learn.org/
from sklearn.metrics import accuracy_score, recall_score, precision_score, f1_score
#True labels and predicted classifications
labels = [1, 0, 0, 1, 1, 1, 0, 1, 1, 1]
guesses = [0, 1, 1, 1, 1, 0, 1, 0, 1, 0]
#Calculate accuracy, recall, precision and f1 score
print(accuracy_score(labels, guesses))
print(recall_score(labels, guesses))
print(precision_score(labels, guesses))