Skip to content

Instantly share code, notes, and snippets.


Mauro Mascia sardbaba

View GitHub Profile
sardbaba /
Created Nov 14, 2020
import json
views = {
"a1": {"position":0,"depends": []},
"a2": {"position":0,"depends": ["a1"]},
"a3": {"position":0,"depends": ["a2"]},
"a5": {"position":0,"depends": ["a9"]},
"a9": {"position":0,"depends": ["a7","a8"]},
"a7": {"position":0,"depends": []},
"a8": {"position":0,"depends": []},
def flatten_json(nested_json, name='', exclude=['']):
"""Flatten json object with nested keys into a single level.
nested_json: A nested json object.
name: A name to cancatenate to the sublevels keys
exclude: Keys to exclude from output.
The flattened json object if successful, None otherwise.
out = {}
sardbaba / MultiMP3s-to-1MP3
Last active Feb 4, 2020
Converts multiple mp3 to one single mp3
View MultiMP3s-to-1MP3
for d in */ ; do
OUTDIR=$(basename "${mp3PATH//\'}")
echo $mp3PATH $OUTDIR
if [ -d "$mp3PATH" ]; then
sardbaba / wordpress-function.php
Last active Apr 23, 2018 — forked from GaryJones/gist:1258784
An improved version of the original Jared/Gary version which checks for, in order, the presence of: 1) subcategory template ID 2) subcategory template slug 3) parent category ID 4) parent category slug 5) general category (category.php) You can use it in the function.php file of your theme.
View wordpress-function.php
* Apply a template to all subcategories of a certain parent category.
* Initial work by Jared Atchison.
* Revisited by GaryJones
* An improved version of the original Jared/Gary version which checks for, in order, the presence of the templates:
sardbaba / woocommerce-functions.php
Created Mar 1, 2016
Woocommerce - Aggiunge verifica email ai campi billing
View woocommerce-functions.php
class My_Class {
public function __construct () {
// Aggiunge verifica email ai campi billing
add_filter( 'woocommerce_billing_fields' , array($this, 'woocommerce_billing_fields'), 10, 1 );
add_action( 'woocommerce_checkout_process', array($this, 'woocommerce_checkout_process'), 9 );
function array_insert(&$array, $position, $insert) {
$pos = array_search($position, array_keys($array));
sardbaba / local-storage-size.js
Created Mar 2, 2016
One line calculate browser local storage size.
View local-storage-size.js
var total = 0; for(var x in localStorage) { var amount = (localStorage[x].length*2)/1024/1024; total += amount; } console.log("Total: "+total.toFixed(10)+" MB");
sardbaba / gist:f822604e53aab4769771
Created Jan 26, 2016
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)
View gist:f822604e53aab4769771
/* Produces a dump on the state of WordPress when a not found error occurs */
/* useful when debugging permalink issues, rewrite rule trouble, place inside functions.php */
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<pre>';
add_action( 'parse_request', 'debug_404_rewrite_dump' );
function debug_404_rewrite_dump( &$wp ) {
sardbaba / functions.php
Created Jan 30, 2015
Wordpress - List all hooks
View functions.php
function dump_hook( $tag, $hook ) {
echo "<pre>>>>>>\t$tag<br>";
foreach( $hook as $priority => $functions ) {
echo $priority;
sardbaba / functions.js
Created Jun 13, 2013
Fallback to PNG if SVG is not supported. Note: of course, you must create the PNG version of the SVG image. Reference:
View functions.js
( function( $ ) {
$( window ).load( function() {
function supportsSVG() {
return !! document.createElementNS && !! document.createElementNS('','svg').createSVGRect;
if (!supportsSVG()) {
var imgs = document.getElementsByTagName('img');
var dotSVG = /.*\.svg$/;
sardbaba / wordpress-functions.php
Created May 14, 2013
Add a checkbox for the terms agreement and hooks into wp_authenticate to allow authentication or to display an error message.
View wordpress-functions.php
* Add the terms agreement field
function sardbaba_add_login_field() {
<p class="forgetmenot">
<label for="terms-agreement">
<input name="terms-agreement" type="checkbox" id="terms-agreement" value="agree"> <?php _e( 'I Agree to the terms and conditions' ) ?>
You can’t perform that action at this time.