Skip to content

Instantly share code, notes, and snippets.

View zoxon's full-sized avatar

Zoxon zoxon

View GitHub Profile
@zoxon
zoxon / colors.ts
Last active February 3, 2025 03:47
/**
* @see https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
*/
export const COLOURS = {
$: (c: number) => (str: string) => `\x1b[${c}m` + str + '\x1b[0m',
gray: (str: string) => COLOURS.$(90)(str),
cyan: (str: string) => COLOURS.$(36)(str),
yellow: (str: string) => COLOURS.$(33)(str),
green: (str: string) => COLOURS.$(32)(str),
@zoxon
zoxon / web-images.sh
Created December 18, 2024 09:41
Optimize png and jpg and convert it to webp and avif, using node sharp
#!/bin/bash
# Check if sharp-cli is installed
if ! command -v sharp &> /dev/null; then
echo "Error: sharp-cli is not installed. Please install it using 'npm install -g sharp-cli'."
exit 1
fi
# Directories
INPUT_DIR="."
{
"000000": "Black",
"000044": "Endless Galaxy",
"000066": "Alone in the Dark",
"000088": "Midnight in Tokyo",
"0000aa": "Bohemian Blue",
"0000ee": "Hyperlink Blue",
"0000ff": "Blue",
"00022e": "Illicit Darkness",
"000435": "Oblivion",
@zoxon
zoxon / wget.sh
Created March 30, 2023 10:03
Download html page with all assets wget
wget -E -H -k -p https://www.example.com/
@zoxon
zoxon / walk-dir-filter.ts
Created March 20, 2023 03:36
Nodejs walk dir example
import { readdir } from "node:fs/promises";
import { extname, resolve } from "node:path";
async function* walkDir(dir: string): AsyncGenerator<string> {
const entries = await readdir(dir, { withFileTypes: true });
for (const entry of entries) {
const name = resolve(dir, entry.name);
if (entry.isDirectory()) {
yield* walkDir(name);
} else if (filterFile(entry.name)) {
@zoxon
zoxon / easing.css
Created January 18, 2023 04:57
CSS Easing
:root {
--easeInSine: cubic-bezier(0.12, 0, 0.39, 0);
--easeOutSine: cubic-bezier(0.61, 1, 0.88, 1);
--easeInOutSine: cubic-bezier(0.37, 0, 0.63, 1);
--easeInQuad: cubic-bezier(0.11, 0, 0.5, 0);
--easeOutQuad: cubic-bezier(0.5, 1, 0.89, 1);
--easeInOutQuad: cubic-bezier(0.45, 0, 0.55, 1);
--easeInCubic: cubic-bezier(0.32, 0, 0.67, 0);
--easeOutCubic: cubic-bezier(0.33, 1, 0.68, 1);
--easeInOutCubic: cubic-bezier(0.65, 0, 0.35, 1);
/**
* Calculate password strength
* @param value password
* @returns password strength in range between 0 an 1
*/
export const getPasswordStrength = (value: string): number => {
// Minimum 8 characters
const REGEX_CHARACTER = /^.{8,}$/
// Minimum 2 uppercase,
@zoxon
zoxon / arrayToKeyedObject.spec.ts
Last active March 3, 2022 10:09
Converts array of objects to object with key
describe('arrayToKeyedObject', () => {
it('should return empty object if array are empty', () => {
type GenericItems = { code: string }
const items: GenericItems[] = []
const result = arrayToKeyedObject(items, (item) => item.code)
expect(result).toEqual({})
})
it('should return keyed object', () => {
function fakeRequest(data) {
// eslint-disable-next-line unicorn/consistent-function-scoping
const random = (min, max) => Math.floor(Math.random() * (max - min) + min)
return new Promise((resolve) => {
setTimeout(() => {
return resolve({ isOk: true, data })
}, random(500, 2000))
})
}
@zoxon
zoxon / vscode_shortcuts.md
Created April 6, 2021 03:39 — forked from bradtraversy/vscode_shortcuts.md
Helpful shortcuts for VSCode

VSCode Shortcuts

List of helpful shortcuts for faster coding

If you have any other helpful shortcuts, feel free to add in the comments of this gist :)

Official List of all commands