Skip to content

Instantly share code, notes, and snippets.

View erikyo's full-sized avatar

Erik Golinelli erikyo

View GitHub Profile
@erikyo
erikyo / Readme.md
Last active May 24, 2023 18:03
CSS file parser for removing duplicates among multiple css files

By using this script, you can easily remove duplicated CSS properties and prettify the resulting CSS files, making your stylesheets more organized and optimized.

Description:

This Node.js script helps parse multiple CSS files, remove duplicated CSS properties, and save the processed files with the "new-" prefix. The script utilizes the css package for parsing and manipulating CSS, as well as the prettier package for prettifying the resulting CSS output.

Key Features:

Accepts an array of CSS file names as input. Parses each CSS file using the css package, building an Abstract Syntax Tree (AST) representation. Removes duplicate CSS properties by comparing rules across all previous files.

@erikyo
erikyo / imagemin.mjs
Created May 10, 2023 19:55
Image Compression and Minification using imagemin in Node.js.
import imagemin from 'imagemin';
import imageminAvif from 'imagemin-avif';
import imageminSvgo from 'imagemin-svgo';
import imageminMozjpeg from 'imagemin-mozjpeg';
import { promises as fsPromises } from 'node:fs';
import { promisify } from 'node:util';
import path from 'node:path';
import fs from 'graceful-fs';
@erikyo
erikyo / pdf_append.sh
Created May 9, 2023 19:11
PDF Appender - Append a page to multiple PDF files in a directory using pdftk
#!/bin/bash
# Check if pdftk is installed
if ! command -v pdftk &> /dev/null; then
echo "pdftk is not installed."
echo "Please install pdftk for your operating system."
echo ""
case "$(uname -s)" in
Linux*)
echo "To install on Ubuntu/Debian, run: sudo apt-get install pdftk"
@erikyo
erikyo / xkcd_colorname_dictionary.json
Created December 31, 2022 11:23
the XKCD color names survey result in json format
[
{
"name": "pig pink",
"color": "#e78ea5"
},
{
"name": "deep lilac",
"color": "#966ebd"
},
{
@erikyo
erikyo / woocommerce_layered_navigation_add_classes.php
Last active October 4, 2022 17:03
Adds some useful classes to the WooCommerce layered navigation widget. This makes it very easy to stylise attribute colours or anything that can be represented with an icon.
<?php
/**
* Adds some useful classes to the WooCommerce layered navigation widget.
* This makes it very easy to stylise attribute colours or anything that can be represented with an icon.
*
* @param string $term_html - the item html
* @param object $term - the item props
*
* @return string - the old html list content wrapped inside a div with as class term id, term name and taxonomy
@erikyo
erikyo / image-formats-comparison.ipynb
Last active July 10, 2024 17:50
image formats comparison.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@erikyo
erikyo / imagemin.mjs
Last active September 27, 2022 11:33
Optimizes the images stored into wordpress plugin/theme (encodes png to webp, jpg to mozjpeg and optimizes), add this alongside wp-scripts
/**
* Minifying images stored into ./assets/source-images saving them into the ./assets/dist
*
* Add to package.json:
* "imagemin": "^8.0.1",
* "imagemin-mozjpeg": "^10.0.0",
* "imagemin-svgo": "^10.0.1",
* "imagemin-webp": "^7.0.0",
* "graceful-fs": "^4.2.10"
*
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
const MINIMUM_CHUNK_HEADER_LENGTH = 18;
const VP8X_ALPHA = 16;
const VP8X_ANIM = 2;
const VP8X_EXIF = 8;
@erikyo
erikyo / wordpress_oembed_utils.php
Created February 16, 2022 10:15
A filter for Wordpress oembed Block. Will set Youtube url to "youtube-nocookie.com" and will disable misc related videos (rel=). Enables Vimeo subtitles automatically using the browser language.
<?php
function oembed_utils( $html ) {
// set the default youtube url to youtube-nocookie.com
$html = str_replace("www.youtube.com/embed","www.youtube-nocookie.com/embed", $html);
// remove youtube random related videos
$html = str_replace( "feature=oembed", "feature=oembed&rel=0", $html );