Skip to content

Instantly share code, notes, and snippets.

@sardbaba
sardbaba / s3_delete_obj_tags.py
Last active May 3, 2021 13:08
AWS Boto3 delete object tags from all objects in a S3 bucket/prefix
import boto3
import time
start_time = time.time()
boto3.setup_default_session(profile_name='YOUR_AWS_PROFILE')
s3 = boto3.client('s3')
s3_paginator = s3.get_paginator('list_objects_v2')
BUCKET = 'YOUR-BUCKET-NAME'
@sardbaba
sardbaba / order_list_by_dependencies.py
Created November 14, 2020 08:03
order_list_by_dependencies.py
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.
Args:
nested_json: A nested json object.
name: A name to cancatenate to the sublevels keys
exclude: Keys to exclude from output.
Returns:
The flattened json object if successful, None otherwise.
"""
out = {}
@sardbaba
sardbaba / MultiMP3s-to-1MP3
Last active May 24, 2022 16:51
Converts multiple mp3 to one single mp3
#!/bin/bash
for d in */ ; do
mp3PATH=$PWD/"$d"
OUTDIR=$(basename "${mp3PATH//\'}")
echo $mp3PATH $OUTDIR
if [ -d "$mp3PATH" ]; then
@sardbaba
sardbaba / local-storage-size.js
Created March 2, 2016 16:39
One line calculate browser local storage size.
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 March 1, 2016 19:27
Woocommerce - Aggiunge verifica email ai campi billing
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 January 26, 2016 17:16
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)
/* 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 December 11, 2015 17:46
jQuery plugin for centering vertically and/or horizontally
(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 October 24, 2015 14:21
Wordpress - Bulk change products status
/**
* 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');
@sardbaba
sardbaba / functions.php
Last active December 4, 2015 17:59 — forked from kloon/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 {