Skip to content

Instantly share code, notes, and snippets.

View Mte90's full-sized avatar
🎯
Creating new open source stuff that you will like

Daniele Scasciafratte Mte90

🎯
Creating new open source stuff that you will like
View GitHub Profile
@Mte90
Mte90 / pre-push.sh
Last active October 2, 2020 10:21
pre-push
#!/bin/sh
# If the branch is not master, execute phpmetrics and upoload everything on the VPS
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $current_branch != "master" ]; then
sshpass -p your-password ssh user@domain.tld mkdir -p /var/www/your-path/status/master/
sshpass -p your-password rsync --progress -avzP /home/your-user/.cache/QualityAnalyzer/assets -e ssh user@domain.tld:/var/www/your-metrics/status/$current_branch/ > /dev/null
sshpass -p your-password rsync --progress -avzP /home/your-user/.cache/QualityAnalyzer/index.html -e ssh user@domain.tld:/var/www/your-metrics/status/$current_branch/ > /dev/null
/usr/bin/phpmd /var/www/VVV/www/site/public_html/wp-content/plugins/your-plugin/ xml /CodeatCS/codeat-phpmd.xml --exclude vendor,tests --reportfile /tmp/phpmd-analysis.xml
/home/your-user/.cache/QualityAnalyzer/bin/analyze analyze /var/www/VVV/www/site/public_html/wp-content/plugins/your-plugin/ --exclude=vendor,tests --exclude_analyzers=cpd,pdepend,checkst
@Mte90
Mte90 / freemius.php
Created February 21, 2018 13:28
Freemius integration for OpenSupports
<?php
echo "Parsing Freemius Webhook";
// Get Freemius data
$json = file_get_contents('php://input');
$data = json_decode($json, true);
if( isset($data['objects']['user']) ) {
// Let's call our opensupports instance
$name = $data['objects']['user']['first'] . ' ' . $data['objects']['user']['last'];
@Mte90
Mte90 / snippet.php
Last active February 24, 2021 18:25
Custom WordPress Error Handler. Support Query Monitor and can be used as mu-plugin.
<?php
/*
* Plugin Name: Better errors
* Description: Better errors in log
* Author: Daniele Scasciafratte
* Version: 1.0
* Author URI: http://codeat.co
*/
function handleError($code, $description, $file = null, $line = null, $context = null) {
@Mte90
Mte90 / snippet.php
Last active May 22, 2017 13:57
Order array multidimensional using a reference array
<?php
function sortArrayByArray( $array, $orderArray ) {
$order = array();
foreach ( array_keys( $array ) as $index ) {
foreach ( array_keys( $orderArray ) as $key ) {
$order[ $index ][ $key ] = $array[ $index ][ $key ];
}
}
return $order;
@Mte90
Mte90 / php-error-in-wp.php
Last active April 14, 2020 06:09
PHP error in WordPress backend wrapped as native notice. Refer/screenshot on https://core.trac.wordpress.org/ticket/35155
<?php
/*
Plugin Name: Error For WP backend
Plugin URI: https://github.com/Mte90/
Description: Wrap the PHP errors in the WP admin backend with the native notice
Author: Mte90
Version: 1.0.0
*/
@Mte90
Mte90 / script.php
Last active May 21, 2016 22:42
Table from array in PHP
<?php
function table_from_array( $cols, $tableclass = 'info' ) {
$content = "<table class=\"" . $tableclass . "\">\n";
$i = 1;
foreach ( $cols as $key => $value ) {
if ( !empty( $value ) ) {
$i++;
if ( $i % 2 === 0 ) {
$content .= "<tr>";
}
@Mte90
Mte90 / dashboard-activity-cpt.php
Created September 18, 2015 11:27
Add your cpts to the Widget Activity of the Dashboard in WordPress
<?php
/*
Plugin Name: Dashboard Widget Activity Custom Post Type
Plugin URI:
Description:
Author: Daniele Mte90 Scasciafratte
Version: 1.0.0
Author URI: http://mte90.net
*/
@Mte90
Mte90 / WebSerial API test
Last active November 21, 2022 12:47
Firefox WebSerial API Test
Download from https://bugzilla.mozilla.org/show_bug.cgi?id=926940 the development build with the WebSerial API
Screenshot: https://plus.google.com/u/0/+DanieleScasciafratteMte90Net/posts/EED6sbEt2zv
@Mte90
Mte90 / owa.ino
Last active September 29, 2021 21:36
Web Server with Arduino Yun with CORS enabled
/*
It demonstrates how you can create your own API when using REST style
calls through the browser with CORS enabled.
Possible commands created in this shetch:
* "/arduino/digital/13" -> digitalRead(13)
* "/arduino/digital/13/1" -> digitalWrite(13, HIGH)
* "/arduino/analog/2/123" -> analogWrite(2, 123)
@Mte90
Mte90 / gist:4117ec381a577df04793
Last active August 29, 2015 14:01
Modal in javascript vanilla
//Based on http://jsfiddle.net/i_like_robots/W2DA8/
(function(name, context, definition) {
if (typeof define === 'function' && define.amd) {
define(definition);
}
else if (typeof module !== 'undefined' && module.exports) {
module.exports = definition();
}
else {