Skip to content

Instantly share code, notes, and snippets.

View prutya's full-sized avatar
🇺🇦
savelife.in.ua/en/donate-en

Anton Prudkohliad prutya

🇺🇦
savelife.in.ua/en/donate-en
View GitHub Profile
@prutya
prutya / generate_uuid.rb
Created September 30, 2024 10:41
Generate consistent UUIDs based on an array of arguments in Ruby (via SHA256 hash)
require 'digest'
require 'securerandom'
def generate_uuid_from_arguments(args)
# Convert the array to a string and then hash it
hash = Digest::SHA256.hexdigest(args.join)
# Use the first 32 characters of the hash to form a UUID
uuid = [
hash[0..7],
@prutya
prutya / utterances-comments.jsx
Last active August 21, 2024 05:31
A React component that adds Utterances (Comments widget built on top of GitHub Issues) to a page in Next.js
// See https://utteranc.es
"use client";
import { useRef, useEffect } from "react";
const UTTERANCES_SRC = "https://utteranc.es/client.js";
const UTTERANCES_ENABLED = process.env.NEXT_PUBLIC_UTTERANCES_ENABLED === "1";
const UTTERANCES_REPO = process.env.NEXT_PUBLIC_UTTERANCES_REPO;
const UTTERANCES_ISSUE_TERM = process.env.NEXT_PUBLIC_UTTERANCES_ISSUE_TERM;
@prutya
prutya / use-is-js-enabled.js
Created August 18, 2024 10:10
A React Hook to check if JavaScript is enabled on the page. Useful for SSR scenarios (e.g. in Next.js) to progressively add functionality to you website
import { useEffect, useState } from "react";
export default function useIsJsEnabled() {
const [isJsEnabled, setIsJsEnabled] = useState(false);
useEffect(() => {
setIsJsEnabled(true);
}, []);
return isJsEnabled;
@prutya
prutya / hashtag.js
Created August 11, 2024 20:58
Twitter hashtag regexp
export const REGEXP =
/(#|#)([a-z0-9_\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0100-\u024f\u0253-\u0254\u0256-\u0257\u0300-\u036f\u1e00-\u1eff\u0400-\u04ff\u0500-\u0527\u2de0-\u2dff\ua640-\ua69f\u0591-\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05d0-\u05ea\u05f0-\u05f4\ufb12-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4f\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06de-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u0750-\u077f\u08a2-\u08ac\u08e4-\u08fe\ufb50-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\u200c-\u200c\u0e01-\u0e3a\u0e40-\u0e4e\u1100-\u11ff\u3130-\u3185\ua960-\ua97f\uac00-\ud7af\ud7b0-\ud7ff\uffa1-\uffdc\u30a1-\u30fa\u30fc-\u30fe\uff66-\uff9f\uff10-\uff19\uff21-\uff3a\uff41-\uff5a\u3041-\u3096\u3099-\u309e\u3400-\u4dbf\u4e00-\u9fff\u20000-\u2a6df\u2a700-\u2b73f\u2b740-\u2b81f\u2f800-\u2fa1f]*[a-z_\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0100-\u024f\u0253-\u0254\u0256-\u0257\u0300-\u036f\u1e00-\u1eff\u0400-\u04ff\u0500-\u0527\u2de0-\u2dff\ua640-\
@prutya
prutya / 01-update-content-schedule.yml
Last active August 12, 2024 09:01
Scheduled content update in a GitHub repository that triggers a static website build and publishes the result to Cloudflare Pages
name: Update Content on schedule
on:
schedule:
- cron: "13 0,12 * * *"
workflow_dispatch: {}
jobs:
trigger-update-content:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
@prutya
prutya / sst.config.ts
Last active October 21, 2024 09:11
Deploy a Next.js app to a Hetzner VPS using SST and Docker (Part of my SST guide https://www.prudkohliad.com/articles/deploy-next-js-to-vps-using-sst-2024-08-11). See full repo at https://github.com/prutya/next-self-hosted
/// <reference path="./.sst/platform/config.d.ts" />
import { resolve as pathResolve } from "node:path";
import { writeFileSync as fsWriteFileSync } from "node:fs";
import { asset as pulumiAsset, all as pulumiAll } from "@pulumi/pulumi";
// Specify HCLOUD_TOKEN and CLOUDFLARE_API_TOKEN before running
// Permissions for CLOUDFLARE_API_TOKEN:
// - Account Settings:Read
// - Zone Settings:Edit
@prutya
prutya / transliteration.js
Created March 11, 2023 13:38
Transliteration of Ukrainian text into English
const MAP_NORMAL = {
"а": "a",
"б": "b",
"в": "v",
"г": "h",
"ґ": "g",
"д": "d",
"е": "e",
"є": "ie",
"ж": "zh",
@prutya
prutya / _headers
Last active December 28, 2022 14:49
A Webpack plugin to automatically generate Cloudflare Pages compatible _headers file to enable HTTP-2 Server Push
# Generated by ServerPushPlugin
/
Link: <index.js>; rel=preload; as=script
Link: <index.css>; rel=preload; as=stylesheet
@prutya
prutya / automatic_theme_switcher.py
Last active December 22, 2022 19:39
Automatically switch theme on iTerm2
#!/usr/bin/env python3
import asyncio
import iterm2
def log(string):
print(string)
async def update(connection, theme):
# Themes have space-delimited attributes, one of which will be light or dark.