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 / ff-check.js
Last active March 23, 2017 12:43
Check if Firefox/Firefox OS/Firefox for Android
//With locationbar.visible check if not in a webview (like an open web app)
if (locationbar.visible) {
//mozApps used for the open web app and with the user agent check if have MObile (used in Firefox OS)
if (navigator.userAgent.indexOf('Firefox') > -1 && navigator.userAgent.indexOf("Mobile") > -1) {
//Check Firefox OS
} else if (navigator.userAgent.indexOf('Firefox') > -1 && navigator.userAgent.indexOf("Android") > -1) {
//Check Firefox for Android
} else if (navigator.userAgent.indexOf("Firefox") > -1) {
//Check Firefox Desktop
}
@Mte90
Mte90 / ffos-check
Last active July 13, 2018 20:45
Check Firefox OS version
function getVersion() {
if (navigator.userAgent.match(/(mobile|tablet)/i)) {
var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/));
if (ffVersionArray.length === 2) {
//Check with the gecko version the Firefox OS version
//Table https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
var hashVersion = {
'18.0': '1.0.1',
'18.1': '1.1',
'26.0': '1.2',
@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 {
@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 / 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 / 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 / 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 / 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 / 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 / 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) {