Skip to content

Instantly share code, notes, and snippets.

View dejurin's full-sized avatar
💭
;-)

YURII D. dejurin

💭
;-)
View GitHub Profile
@dejurin
dejurin / server-snapshot.sh
Created September 25, 2025 18:47
Small, dependency-light Linux server snapshot tool for quick health checks. Prints host info, time, load, CPU/memory/disk, basic I/O & network stats, TCP summary, top processes, and (optionally) Docker usage. Safe to run as non-root; gracefully degrades when tools are missing.
#!/usr/bin/env bash
# server-snapshot.sh
# Purpose: Print a concise, human-readable snapshot of a Linux server state.
# Safe defaults: exits on errors/undefined vars; degrades when optional tools are missing.
# Intended usage: run manually or via cron; pipe to file for later inspection.
set -euo pipefail
# Ensure predictable output regardless of system locale
export LC_ALL=C
@dejurin
dejurin / update_cloudflare_ips.py
Created September 11, 2025 08:07
Python Script for Updating Cloudflare IPs in Nginx Configuration
import requests
import os
def fetch_cloudflare_ips():
url = "https://www.cloudflare.com/ips-v4/"
response = requests.get(url)
if response.status_code == 200:
return response.text.strip().split("\n")
else:
raise Exception(f"Failed to fetch Cloudflare IPs: {response.status_code}")
@dejurin
dejurin / abbr.ts
Created September 3, 2025 18:08
abbr.ts
// Variant type for clarity
type TZVariant = {
name: string; // Human-readable timezone name
iana: string[]; // One or more IANA zones (first is canonical)
note?: string; // Optional note (DST/legacy/unofficial/etc.)
};
// Map: Abbreviation -> possible variants
export const TZ_MAP_PART_A: Record<string, TZVariant[]> = {
// Military letter zone. Note the inverted sign in Etc/GMT*: Etc/GMT-1 === UTC+1
@dejurin
dejurin / docker.md
Created May 5, 2025 20:17
Docker Log

Show logs for webapp container

docker logs container

Show last 100 lines

docker logs --tail 100 container

Follow logs in real time

docker logs -f container

@dejurin
dejurin / earlyhints.go
Created May 5, 2025 11:14
Early Hints
// Early Hints
app.Use(func(c *fiber.Ctx) error {
if c.Method() != fiber.MethodGet ||
!strings.Contains(c.Get("Accept", ""), "text/html") {
return c.Next()
}
for _, entry := range Manifest {
switch ext := strings.ToLower(filepath.Ext(entry.File)); ext {
case ".js":
c.Append("Link", fmt.Sprintf("</%s>; rel=preload; as=script", entry.File))
@dejurin
dejurin / pretty-number.ts
Created April 24, 2025 17:42
A lightweight, DRY wrapper for Intl.NumberFormat with built-in formatter caching and flexible options.
/**
* Formatting options for prettyNumber.
* Extends all standard Intl.NumberFormatOptions and adds an optional locale override.
*/
export interface PrettyNumberOptions extends Intl.NumberFormatOptions {
/** BCP 47 language tag, e.g. 'en-US', 'ru-RU'. Defaults to 'en-US'. */
locale?: string;
}
/** Cache key → Intl.NumberFormat instance */
@dejurin
dejurin / uni.py
Created April 21, 2025 17:22
Get all Unicode with names, including emoji.
#!/usr/bin/env python3
import re
import csv
import unicodedata2
import urllib.request
EMOJI_TEST_URL = 'https://unicode.org/Public/emoji/latest/emoji-test.txt'
MIN_CHAR = 0x20
MAX_CHAR = 0x100000
OUTPUT_CSV = 'unicode.csv'
@dejurin
dejurin / tailwind-scrollbar-hide.css
Created April 20, 2025 17:12
Scrollbar Hide: TailwindCSS 4
@utility scrollbar-hide {
-ms-overflow-style: none;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
@dejurin
dejurin / jsdelivr.ts
Created April 17, 2025 11:34
Convert various source URLs (GitHub, npm, unpkg, WordPress) to jsDelivr CDN URLs.
/**
* Convert various source URLs (GitHub, npm, unpkg, WordPress) to jsDelivr CDN URLs.
* @param sourceUrl — the original file URL
* @returns jsDelivr URL or null if the format is not recognized
*/
export function toJsDelivr(sourceUrl: string): string | null {
const url = new URL(sourceUrl);
const { hostname, pathname, searchParams } = url;
// GitHub: handle both github.com/blob/... and raw.githubusercontent.com
@dejurin
dejurin / use-on-click-outside.ts
Created April 14, 2025 19:18
Custom hook that calls handler when a click is detected outside of the given ref element
import { useEffect } from "preact/hooks";
// Custom hook that calls handler when a click is detected outside of the given ref element
const useOnClickOutside = (
ref: { current: HTMLElement | null },
handler: (event: MouseEvent | TouchEvent) => void
) => {
useEffect(() => {
// Listener that calls handler if click is outside of ref element
const listener = (event: MouseEvent | TouchEvent) => {