Skip to content

Instantly share code, notes, and snippets.

Mauro Mascia sardbaba

Block or report user

Report or block sardbaba

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sardbaba
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
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
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
sardbaba / jquery.center.js
Created Dec 11, 2015
jQuery plugin for centering vertically and/or horizontally
View jquery.center.js
(function( $ ) {
$.fn.vcenter = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px");
return this;
}
$.fn.hcenter = function () {
this.css("position","absolute");
this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
return this;
@sardbaba
sardbaba / functions.php
Last active Oct 24, 2015
Wordpress - Bulk change products status
View functions.php
/**
* Aggiungo una notice nella pagina dei prodotti con due bottoni:
* uno per nascondere (mettere in bozza), l'altro per pubblicare tutti i prodotti.
*/
add_action( "admin_notices", function() {
// Verifico che sia la pagina corretta
$screen = get_current_screen();
if ( 'edit-product' != $screen->id ) return;
$_wpnonce = wp_create_nonce('la_mia_stringa_di_sicurezza');
View functions.php
<?php
// Add a date range to a datepicker field, replace #date with the id of the date field.
add_filter( 'wp_footer' , 'woo_add_checkout_field_date_range_limit' );
function woo_add_checkout_field_date_range_limit() {
if ( is_checkout() ) {
$js = 'jQuery( "#date" ).datepicker({ minDate: -5, maxDate: "+1M +10D" });';
// Check if WC 2.1+
if ( defined( 'WC_VERSION' ) && WC_VERSION ) {
wc_enqueue_js( $js );
} else {
@sardbaba
sardbaba / functions.php
Created Jan 30, 2015
Wordpress - List all hooks
View functions.php
//LIST ALL HOOKS
function dump_hook( $tag, $hook ) {
ksort($hook);
echo "<pre>>>>>>\t$tag<br>";
foreach( $hook as $priority => $functions ) {
echo $priority;
@sardbaba
sardbaba / jquery-outer.js
Last active Aug 29, 2015 — forked from tlync/jquery-outer.js
Setter for jQuery outerWidth/outerHeight, in a compact version
View jquery-outer.js
/** Get or set the current outer width/height for the first element in the set of matched elements. */
var origOuterWidth = $.fn.outerWidth;
$.fn.outerWidth = function(){
var value = arguments[0];
if (arguments.length === 0 || typeof value === 'boolean') { return origOuterWidth.apply(this, arguments); }
else if (typeof value !== 'number') { throw new Error('Invalid argument. The new outerWidth value must be an integer.'); }
var css = ['borderLeftWidth','borderRightWidth','paddingLeft','paddingRight'];
if (arguments[1] === true) { css.push('marginLeft'); css.push('marginRight'); }
var $el = $(this), exclude = 0, parse = parseFloat;
for (var i=0; i<css.length; i++) { exclude += parse($el.css(css[i])); }
@sardbaba
sardbaba / WP-Widget_Language_Chooser
Created May 2, 2014
Wordpress - A textual language chooser widget compatible with qTranslate and qTranslate-slug
View WP-Widget_Language_Chooser
/**
* A textual language chooser widget compatible with qTranslate and qTranslate-slug
* Author: Mauro Mascia
* License: WTFPL (www.wtfpl.net)
*/
class Widget_Language_Chooser extends WP_Widget {
function __construct() {
parent::__construct(
'widget_language_chooser',
View gist:11078290
Drupal.settings.isTouchDevice = function() {
return "ontouchstart" in window;
}
if ( Drupal.settings.isTouchDevice() ) {
Drupal.behaviors.jQueryMobileSlideShowTouchAdvance = {
attach: function(context, settings) {
self = Drupal.behaviors.jQueryMobileSlideShowTouchAdvance;
jQuery.each(jQuery(".views_slideshow_cycle_main.viewsSlideshowCycle-processed"), function(idx, value) {
value.addEventListener("touchstart", self.handleTouchStart);
You can’t perform that action at this time.