Skip to content

Instantly share code, notes, and snippets.

@sardbaba
sardbaba / s3_delete_obj_tags.py
Last active May 3, 2021
AWS Boto3 delete object tags from all objects in a S3 bucket/prefix
View s3_delete_obj_tags.py
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 Nov 14, 2020
order_list_by_dependencies.py
View 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": []},
View flatten_json_pandas_df_column.py
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 Feb 4, 2020
Converts multiple mp3 to one single mp3
View MultiMP3s-to-1MP3
#!/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 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 {