Skip to content

Instantly share code, notes, and snippets.

View erikyo's full-sized avatar

Erik Golinelli erikyo

View GitHub Profile
@erikyo
erikyo / simple_toast_notification.js
Created October 13, 2023 13:21
This code defines a JavaScript function named makeToast designed for displaying customizable toast notifications on a web page. Toast notifications are often used to provide brief, non-intrusive feedback or information to the user.
function makeToast( message = 'OK!', timeout = 3000 ) {
// Create the toast notification element
const toast = document.createElement('div');
toast.textContent = message;
toast.style = 'display:block;max-width:calc(100% - 20px);position:fixed;bottom:20px;left:50%;transform:translateX(-50%);background-color:#333;color:#fff;padding:10px 20px;border-radius:5px;';
// display the toast notification
document.body.appendChild(toast);
// Hide and remove the toast after a while
@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 July 6, 2025 20:38
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;