Skip to content

Instantly share code, notes, and snippets.

View lysender's full-sized avatar

Leonel lysender

View GitHub Profile
@lysender
lysender / nodejs-minify-bundle-css-files-using-lightningcss.md
Created August 19, 2023 11:59
NodeJS - minify and bundle css files using lightningcss

Been doing some HTMX lately using ExpressJS backend.

Unfortunately, my CSS files are not automatically minified and bundled for the browser.

Using lightningcss, a blazingly fast tool written in rust, we can achieve some minifications and combining using some NodeJS scripts.

Install lightningcss in your project

npm i -D lightningcss lightningcss-cli
@lysender
lysender / nodejs-minify-bundle-js-files-using-swc.md
Last active August 19, 2023 11:50
NodeJS - minify and bundle js files for browser using swc

Been doing some HTMX lately using ExpressJS backend.

Unfortunately, my JS files are not automatically minified and bundled for the browser.

Using swc - Speedy Web Compiler, a blazingly fast tool written in rust, we can achieve some minifications and combining using some NodeJS scripts.

Install swc in your project

npm i -D @swc/cli @swc/core
@lysender
lysender / hyperscript-toggle-burger-menu.md
Created August 17, 2023 16:41
hyperscript - Toggle Hamburger Menu for mobile browsers

How to toggle hamburger menu on/off in hyperscript?

I used this JavaScript solution earlier - https://gist.github.com/lysender/bc9800e6350e1ccfab3c6ce6934b1cd2

However, I realized it is way more simple to just use hyperscript.

What it does is toggle the is-active class on two divs related to the navigation menu.

No need to write the complicated JavaScript code but we do need to include the hyperscript JavaScript file in our page.

@lysender
lysender / htmx-load-content-with-loading-indicator.md
Created August 17, 2023 05:53
HTMX - Load content with loading indicator

Problem: I want blazingly fast page load but my content may take some time to load.

The page may actually be fast but the content may include calling a service that may take some time to respond or worst, fail.

Solution: Load the full page (HTML, CSS, JS) without the slow content first. Load the slow content later on page load.

<div
  class="albums-container"
 hx-get="/album-listing"
@lysender
lysender / no-htmx-toggle-burger-menu.md
Last active August 17, 2023 05:57
HTMX - Toggle Hamburger Menu for mobile browsers

How to toggle hamburger menu on/off in HTMX?

Why bother using HTMX, just use JavaScript!

Here is my navigation template, written in EJS using Bulma CSS framework. It shows a hamburger menu when viewed in a mobile browser. Without JavaScript, it won't expand or collapse the menu.

<nav class="navbar is-dark" role="navigation" aria-label="main navigation">
@lysender
lysender / bulk-rename-files.md
Created August 14, 2023 08:37
Bulk rename files in linux

Rename all files in current directory and sub-directories in certain pattern

I have several photos compiled in directories. However, these photos were processed by some old application and don't have file name extensions.

I would just assume that they are all JPG files so I want to rename all files to have the .jpg extension.

Will use the find and exec combination.

First, let's test it with a safer echo command. The command simply echos for original filename and the desired filename.

@lysender
lysender / linux-find-and-exec.md
Last active August 14, 2023 08:25
Linux find and exec

Change permissions of all files in a directory including files inside sub-directories

I wanted to ensure that all files has the 644 permissions but I don't want the directories to have the same permissions.

First, I'll run it with ls -l command to avoid accidental command execution.

find ./ -type f -name "*" -exec ls -l "{}" \;
@lysender
lysender / delete-pods-with-shutdown-status.sh
Created October 7, 2021 01:27
Delete pods with Shutdown status
# Replace get with delete at the end
kubectl get pods -n jx-staging | grep -i shutdown | awk '{print $1}' | xargs -n1 kubectl get pod -n jx-staging
@lysender
lysender / ordering-list.md
Last active August 16, 2021 04:26
Ordering a list in a database

Sauces:

Solution: make index a string (because strings, in essence, have infinite "arbitrary precision"). Or if you use an int, increment index by 100 instead of 1.

The performance problem is this: there is no "in between" values between two sorted items.

@lysender
lysender / jx-get-application-activity.sh
Created March 17, 2021 06:47
View jx application activity real time logs
jx get activity -f <application-name> -w