Skip to content

Instantly share code, notes, and snippets.

View evemilano's full-sized avatar

Giovanni Sacheli evemilano

View GitHub Profile
@evemilano
evemilano / HTTP header (esempio)
Created April 27, 2018 08:00
HTTP header (esempio)
HTTP/1.1 200 OK
Date: Fri, 27 Apr 2018 07:59:06 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Set-Cookie: __cfduid=d047683e2225426554c96d71a9e7d21521524815946; expires=Sat, 27-Apr-19 07:59:06 GMT; path=/; domain=.evemilano.com; HttpOnly
Vary: Accept-Encoding
Link: <https://www.evemilano.com/wp-json/>; rel="https://api.w.org/"
X-Cache: HIT
Strict-Transport-Security: max-age=15552000; preload
X-Content-Type-Options: nosniff
@evemilano
evemilano / Personalizzare il Prompt Banner delle notifiche push
Last active March 29, 2018 10:20
Personalizzare il Prompt Banner delle notifiche push
<script>
var OneSignal = window.OneSignal || [];
OneSignal.push(["init", {
appId: "12341234-1234-1234-1234-12341234",
safari_web_id: "web.onesignal.auto.12341234-1234-1234-1234-12341234",
autoRegister: false,
notifyButton: {
enable: false,
showCredit: false
},
@evemilano
evemilano / Come usare due Service Worker
Last active March 29, 2018 22:36
Implementazione di due service worker: PWA e notifiche push
<!-- PWA & Push Service Worker -->
<script>
// If service workers are supported, and one isn't already registered
if ('serviceWorker' in navigator && !navigator.serviceWorker.controller) {
navigator.serviceWorker.register('/OneSignalSDKWorker.js');
console.log("OneSignalSDKWorker.js loaded...");
}
</script>
@evemilano
evemilano / OneSignalSDKUpdaterWorker.js
Created March 29, 2018 09:32
Modifica al file OneSignalSDKUpdaterWorker.js
importScripts('https://www.evemilano.com/sw.js');
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDK.js');
@evemilano
evemilano / Nginx Speed Configuration
Created February 3, 2018 10:06
Nginx Speed Configuration - /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
@evemilano
evemilano / Examples
Created December 7, 2017 13:57
WordPress 301 redirect after permalink change
## From permalink "Day and Name (/%year%/%monthnum%/%day%/%postname%/)" to "postname"
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://www.yourwebsite.com/$4
## From permalink "Month and Name (/%year%/%monthnum%/%postname%/)" to "postname"
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.*)$ http://www.yourwebsite.com/$3
## From permalink "Numeric (/archives/%post_id%)" to "postname"
RedirectMatch 301 ^/archives/(\d+)$ http://www.yourwebsite.com/?p=$1
@evemilano
evemilano / WordPress Plugin Dynamic Prerender Meta Tag
Last active December 22, 2017 09:12
WordPress Plugin Dynamic Prerender Meta Tag
<?php
/*
Plugin Name: EVE Dynamic Prerender Meta Tag
Plugin URI: https://www.evemilano.com/2017/11/wp-prerender-plugin/
Version: 3.5.3
Description: This WordPress plugin creates and inject into HTML head a Dynamic Prerender Meta Tag. The system stores users navigational paths inside the database e retrieve the most common next visited page as prerender meta tag. If the plugin doesn't has data for the next probable page, it will show a prerender to the homepage. The database table WILL BE REMOVED automatically when the plugin is uninstalled but not when disabled. Do not remove the plugin if you want to keep data. The database table can grow up a lot in large websites, keep an eye on it!
Author: Giovanni Sacheli
Author URI: https://www.evemilano.com/
*/
@evemilano
evemilano / Da usare nel file functions.php
Last active December 17, 2018 19:16
Come disabilitare le Rest API di WordPress
/* 410 STATUS CODE */
add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) );
}
return $result;
});
@evemilano
evemilano / Service Worker Registration
Created October 25, 2017 13:03
Service Worker Registration
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(function(registration) {
console.log('Registration successful, scope is:', registration.scope);
})
.catch(function(error) {
console.log('Service worker registration failed, error:', error);
});
}
@evemilano
evemilano / Link Rel Manifest
Created October 25, 2017 12:50
Link Rel Manifest