Skip to content

Instantly share code, notes, and snippets.

View by-nari's full-sized avatar
🏠
Working from home

Nari by-nari

🏠
Working from home
  • Midgard
View GitHub Profile
@by-nari
by-nari / synology_update_docker_image.md
Created February 18, 2025 10:51
How to update Docker image for a running container on Synology NAS
  1. Action -> Stop

  2. Download new Docker image with the same tag to overwrite the old image

  3. Action -> Reset

  4. Start

@by-nari
by-nari / enum.ts
Created December 29, 2024 11:12
TypeScript enum to Drizzle's pgEnum
export enum Role {
APPLICANT = 'applicant',
TRAINER = 'trainer',
ADMIN = 'admin',
}
export function enumToPgEnum<T extends Record<string, any>>(
myEnum: T,
): [T[keyof T], ...T[keyof T][]] {
return Object.values(myEnum).map((value: any) => `${value}`) as any
@by-nari
by-nari / readme.md
Last active December 25, 2024 12:55
1Password commit signing inside devcontainers

Tailscale Serve with other target rather than localhost

  1. Get the full current config of serve:

    sudo tailscale serve status -json > serve.json
  2. Edit the JSON file to meet your needs.

  3. Set the modified configuration back using the set-raw option:

cat serve.json | sudo tailscale serve set-raw

@by-nari
by-nari / corsproxyservice.js
Last active April 26, 2024 14:26
Use this proxy by appending the URL you want to access to the base URL of this proxy. For example: https://our-corsproxy.site/https://somewhere.hates.cors/some-path?somequery=param
export default {
async fetch(request) {
function usageResponse() {
const usageHtml = `<!DOCTYPE html>
<html>
<head><title>CORS Proxy Service</title></head>
<body>
<h1>CORS Proxy Usage</h1>
<p>Use this proxy by appending the URL you want to access to the base URL of this proxy. For example:</p>
<code>https://our-corsproxy.site/https://somewhere.hates.cors/some-path?somequery=param</code>
@by-nari
by-nari / bot.go
Created April 23, 2024 15:33
A simple example Telegram echo-bot on Google Cloud Functions
package telegrambot
import (
"context"
"fmt"
"os"
"github.com/GoogleCloudPlatform/functions-framework-go/functions"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
@by-nari
by-nari / macos_change_hostname.sh
Created March 30, 2024 06:23
macOS, how to rename computer via scutil
sudo scutil --set HostName <new host name>
@by-nari
by-nari / Delay.tsx
Created March 19, 2024 06:33
Delaying React Lazy Loaded Component Import
const IndexPage = React.lazy(() =>
new Promise<{ default: React.ComponentType }>(resolve =>
setTimeout(() => {
resolve(
import('./pages/IndexPage').then(module => ({ default: module.IndexPage }))
);
}, 3000000)
)
);
@by-nari
by-nari / convert_incompatible_codecs.sh
Created December 8, 2023 13:00
The script will convert files containing the EAC3, DTS, or DTS-HD audio codecs to use the AAC codec through the AudioToolbox encoder specified as aac_at. The converted files will get the suffix -AAC_at.mkv to distinguish them from the original files
#!/bin/bash
# Function to check and convert the file if necessary
check_and_convert() {
local file=$1
[ -d "$file" ] && return # Skip directories
# Use ffprobe to get the codec type for each audio stream
codec_info=$(ffprobe -v error -select_streams a -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "$file")
@by-nari
by-nari / lazy-load-puppeteer.js
Created September 17, 2023 07:04 — forked from schnerd/lazy-load-puppeteer.js
Lazy-loading content in Puppeteer
function wait (ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms));
}
export default async function capture(browser, url) {
// Load the specified page
const page = await browser.newPage();
await page.goto(url, {waitUntil: 'load'});
// Get the height of the rendered page