Skip to content

Instantly share code, notes, and snippets.

View vadviktor's full-sized avatar
๐Ÿ€
Mining Ruby ๐Ÿ’Ž โ›๏ธ

Viktor (Icon) VAD ๐Ÿ€ vadviktor

๐Ÿ€
Mining Ruby ๐Ÿ’Ž โ›๏ธ
View GitHub Profile
@vadviktor
vadviktor / echo.go
Created January 15, 2025 12:56
Embedding a Blazor Webassembly SPA in Go with Echo
package main
import (
"embed"
"fmt"
"io/fs"
"net/http"
"github.com/labstack/echo/v4"
)
@vadviktor
vadviktor / rename.py
Created September 12, 2024 07:40
Sanitize file names in a directory tree
import argparse
import os
import re
def sanitize_filename(filename):
# Replace characters not allowed in Windows filenames with underscores
sanitized = re.sub(r'[<>:"/\\|?*]', "_", filename)
# Remove non-ASCII characters
sanitized = re.sub(r"[^\x00-\x7F]", "_", sanitized)
@vadviktor
vadviktor / main.py
Last active January 20, 2024 10:41
Traversing folders using Textual
from pathlib import Path
from textual import events, on
from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal
from textual.screen import ModalScreen
from textual.widgets import Button, DataTable, Footer, Header, Label
from rich.text import Text
@vadviktor
vadviktor / defrost.py
Last active February 17, 2025 11:58
Restore objects from S3 Glacier Deep Archive
# example:
# $env:AWS_PROFILE="xxx"
# python .\main.py --days 3 --path "s3://mybucket/mydir"
import argparse
import boto3
def main():
@vadviktor
vadviktor / pexpect-1password-otp
Created September 1, 2023 11:45
Asking the OTP for an SSH connection form 1password Connect, interacting with the prompt and yielding the console back to the user at the end.
import pexpect
def otp():
import requests
vault_id = "xxxxxxxxx"
item_id = "xxxxxxxx"
url = f"http://localhost:18080/v1/vaults/{vault_id}/items/{item_id}"
headers = {
"Authorization": "Bearer xxxx", # noqa: E501
@vadviktor
vadviktor / index.html
Last active April 1, 2025 17:42
Copy to clipboard button with AlpineJs.
<div>
<button class="btn btn-dark" type="button"
x-on:click="copyToClipboard"
id="clipboard-000">
<i class="bi bi-clipboard"></i> Copy to clipboard
</button>
<div class="d-none" id="clipboard-000-text">Text to be copied to the clipboard</div>
</div>
@vadviktor
vadviktor / randompassword.cs
Created December 30, 2022 16:07
Generate random passwords in C#, taken from .Net Framework 4.8.2
// https://github.com/microsoft/referencesource/blob/master/System.Web/CrossSiteScriptingValidation.cs
private static readonly char[] StartingChars = new char[] { '<', '&' };
private static bool IsAtoZ(char c)
{
return c is >= 'a' and <= 'z' or >= 'A' and <= 'Z';
}
private static bool IsDangerousString(string s)
{
@vadviktor
vadviktor / clean.sh
Created July 18, 2022 18:58
Download Ruby and Rails docs with https://gist.github.com/vadviktor/b3cb6e6b8f9a65fa31a7 and serve them locally with Caddy
#!/usr/bin/env bash
# JS script paths are absolute in some Ruby docs, convert them to relative.
fd --type file --extension html --full-path 'ruby_.*' --exec sd --string-mode 'src="/js/' 'src="js/'
@vadviktor
vadviktor / openinbrowser.go
Created June 9, 2022 07:46 — forked from nanmu42/openinbrowser.go
Golang: Open URL in Browser
func openBrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
@vadviktor
vadviktor / random-password.py
Created March 25, 2022 19:55
Python random password generator
# https://stackoverflow.com/questions/3854692/generate-password-in-python
import string
import secrets
length = 42
password = ""
for _ in range(length):
l = secrets.choice(string.ascii_lowercase)
u = secrets.choice(string.ascii_uppercase)