Skip to content

Instantly share code, notes, and snippets.

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

YURII D. dejurin

💭
;-)
View GitHub Profile
@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) => {
@dejurin
dejurin / path.ts
Created April 13, 2025 09:12
Monkey patch: Added non-passive event listener to a scroll-blocking 'wheel' event.
// This code patches addEventListener globally to force passive wheel events
if (typeof window !== 'undefined') {
const originalAddEventListener = window.EventTarget.prototype.addEventListener;
window.EventTarget.prototype.addEventListener = function(type, listener, options) {
if (type === 'wheel') {
// Transform options to object and force passive: true
if (options === undefined) {
options = { passive: true };
} else if (typeof options === 'boolean') {
@dejurin
dejurin / preact.ts
Last active April 13, 2025 08:48
Headless UI shadow DOM support for Preact
const containerRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
if (!containerRef.current) return;
const observer = new MutationObserver((records) => {
const record = records.filter((record) => {
const el = record.target as HTMLDivElement;
return el.id === 'headlessui-portal-root';
}).pop();
@dejurin
dejurin / gen-unicode-csv.py
Created April 10, 2025 20:15
List of all (non-control) Unicode characters with codepoint and Unicode descriptor (as given by python module "unicodedata").
#!/usr/bin/python
import unicodedata
import math
import csv
MIN_CHAR = 0x20
MAX_CHAR = 0x100000
PROGRESS = 0x8000