Skip to content

Instantly share code, notes, and snippets.

View sudarshann's full-sized avatar
💭
Modernizing

Sudarshan Anbazhagan sudarshann

💭
Modernizing
View GitHub Profile
@sudarshann
sudarshann / export-html-table-xls.js
Created September 28, 2020 20:54
Export any standard html tag to xls file with javascript.
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(tableID, name) {
table = document.getElementById(tableID);
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML};
var link = document.createElement("a");
link.download
@sudarshann
sudarshann / encoding-video.md
Created September 7, 2020 13:07 — forked from Vestride/encoding-video.md
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@sudarshann
sudarshann / woocommerce-out-of-stock.php
Created August 7, 2020 12:10
Custom woocommerce out of stock message
add_filter( 'woocommerce_product_add_to_cart_text', 'superbotics_add_to_cart_text', 20, 2);
add_filter( 'woocommerce_product_single_add_to_cart_text', 'superbotics_add_to_cart_text', 20, 2);
function superbotics_add_to_cart_text( $text, $_product ) {
if ( ! $_product->is_in_stock() ) {
$text = __('<Custom Text>', 'superbotics-customizations');
}
return $text;
}
@sudarshann
sudarshann / pagespeed_optimize_images.sh
Created July 24, 2020 21:25 — forked from julianxhokaxhiu/pagespeed_optimize_images.sh
Recursively optimize all PNG and JPG files wherever they are from the script position and inner ( based on OPTING, PNGCRUSH, ADVANCECOMP and JPEGOPTIM )
#!/bin/bash
# Improved as per feedback from @pascal - https://gist.github.com/julianxhokaxhiu/c0a8e813eabf9d6d9873#gistcomment-3086462
find . -type f -iname "*.png" -exec optipng -nb -nc {} \;
find . -type f -iname "*.png" -exec advpng -z4 {} \;
find . -type f -iname "*.png" -exec pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time -ow {} \;
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --strip-all {} \;
@sudarshann
sudarshann / functions.php
Created May 17, 2020 13:07 — forked from maddisondesigns/functions.php
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
@sudarshann
sudarshann / validate-acf-field-repeater.php
Last active May 2, 2023 06:52
Custom validation for ACF Repeater Field values
add_filter('acf/validate_value/name=voucher', 'acf_validate_vocher_code_unique', 10, 4);
function acf_validate_vocher_code_unique($valid, $value, $field, $input_name) {
// Bail early if value is already invalid.
if ($valid !== true) {
return $valid;
}
$result = validate_voucher_unqiue($value);
public static function acf_validate_vocher_code_unique($valid, $value, $field, $input_name) {
// Bail early if value is already invalid.
if ($valid !== true) {
return $valid;
}
$result = self::validate_voucher_unqiue($value);
if( !empty($result) ){
return $result;
@sudarshann
sudarshann / ACF Country List
Created April 14, 2020 09:49 — forked from yaronguez/ACF Country List
Country list formatted for Advanced Custom Fields select dropdown
afghanistan : Afghanistan
albania : Albania
algeria : Algeria
american_samoa : American Samoa
andorra : Andorra
angola : Angola
anguilla : Anguilla
antigua_and_barbuda : Antigua and Barbuda
argentina : Argentina
armenia : Armenia
<div hidden id="tagManager-tag-manager-promo-desktop">
<div id="corona-open-modal" class="modal-window">
<div>
<a href="#" title="Close" class="modal-close">Fermer</a>
<h1>INFORMATION</h1>
<p>Notre activité (prise de commandes, suivi de commandes, renseignements techniques, expéditions) continue pendant cette période</p>
<p>Les délais de livraison pourraient parfois être rallongés.<br>N’hésitez pas à contacter notre équipe technique pour toute information ou pour tout renseignement.</p>
<div class="rectangle-1"><p>Livraison offerte à domicile pour toute commande</p></div>
<div hidden id="tagManager-tag-manager-promo-desktop">
<div id="tag-manager-promo-desktop-block" class="tag-manager-promo- hide-on-mobile">
<!-- For Desktop Collapsed view -->
<img
class="img-responsive tag-manager-promo-desktop-block close"
id="desktop-open-code"
src=""
alt="tag-manager-promo-">
<!-- For Desktop Expanded view -->
<img