Skip to content

Instantly share code, notes, and snippets.

View LucaRosaldi's full-sized avatar

Luca Rosaldi LucaRosaldi

View GitHub Profile
@LucaRosaldi
LucaRosaldi / stopwords-it_IT.php
Last active April 11, 2017 18:07
PHP: Italian Prepositions
<?php
/**
* A list of italian prepositions.
* Useful for excluding stopwords from slugs and/or search queries.
*/
return [
'il', 'lo', 'la', 'i', 'gli', 'le',
'di', 'del', 'dello', 'della', 'dei', 'degli', 'delle',
'a', 'al', 'allo', 'alla', 'ai', 'agli', 'alle',
'da', 'dal', 'dallo', 'dalla', 'dai', 'dagli', 'dalle',
@LucaRosaldi
LucaRosaldi / index.html
Last active August 5, 2016 09:02
HTML5: Basic page structure
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
@LucaRosaldi
LucaRosaldi / pretty-print.php
Last active February 24, 2022 10:23
PHP: Pretty Print (Debug function)
<?php
/**
* Pretty Print.
*
* @param [mixed] $val The value to print
*/
function pp( $value ) {
switch ( $type = gettype( $value ) ) {
@LucaRosaldi
LucaRosaldi / print.css
Created September 13, 2013 13:57
CSS: Print Styles
@media print {
* {
background: transparent !important;
color: #000 !important;
box-shadow: none !important;
text-shadow: none !important;
}
p, h1, h2, h3, h4, h5, h6 {
orphans: 3;
widows: 3;
@LucaRosaldi
LucaRosaldi / closure.js
Last active August 5, 2016 10:47 — forked from paulirish/gist:315916
javascript: Closure
/**
* Javascript closure.
*/
( function( window, document, undefined ) {
'use strict';
// do something
} )( window, window.document );
@LucaRosaldi
LucaRosaldi / parse-url.js
Created July 12, 2013 11:37
JS: Simplest way to parse an URL
(function(){
// The URL we want to parse
var url = 'http://example.com/path/to/example-folder/?key=value#hashexample';
// The magic: create a new anchor element, and set the URL as its href attribute.
// This triggers the same properties of the "location" object on the DOM element.
var a = document.createElement('a');
a.setAttribute('href',url);
@LucaRosaldi
LucaRosaldi / login-styles.php
Last active February 24, 2022 10:26
WP: Customize Login Page
<?php
function my_login_enqueue_scripts() {
wp_enqueue_style( 'my-login', get_stylesheet_directory_uri() . '/assets/css/style-login.css' );
}
add_action( 'login_enqueue_scripts', 'my_login_enqueue_scripts', 10 );
@LucaRosaldi
LucaRosaldi / get-browser-language-code.php
Last active February 24, 2022 10:13
PHP: Get Browser Language, optionally passing a list of available languages.
<?php
/**
* Get browser language, optionally passing a list of available languages.
*
* @param [array] $available_languages Available languages for the site
* @param [string] $default Default language for the site
* @return [string] Language code
*/
function get_browser_language_code( $available_languages = [], $default = 'en' ) : string
{
@LucaRosaldi
LucaRosaldi / get_data_uri.php
Last active February 24, 2022 10:30
PHP: Get data URI string from an image file.
<?php
/**
* Get data URI string from an image file.
*
* @param string $path_to_file
* @return string
*/
function get_data_uri( string $path_to_file ) : string
{
@LucaRosaldi
LucaRosaldi / distance-sample.php
Last active February 12, 2024 09:05
PHP: Get Distance Between two Geolocated Points (lat/lon)
<?php
/* These are two points in New York City */
$point1 = array('lat' => 40.770623, 'long' => -73.964367);
$point2 = array('lat' => 40.758224, 'long' => -73.917404);
$distance = getDistanceBetweenPoints($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
foreach ($distance as $unit => $value) {
echo $unit.': '.number_format($value,4).'<br />';
}