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 / 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 / main.py
Created November 11, 2023 15:50
Restore objects from S3 Glacier Deep Archive
import argparse
import boto3
def main():
# Parse command line arguments
parser = argparse.ArgumentParser(
description="Restore objects from S3 Glacier Deep Archive"
)
@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 / inde.xhtml
Created July 23, 2023 18:54
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 / Manjaro_HyperV_Setup.md
Created September 13, 2022 08:04 — forked from Zackptg5/Manjaro_HyperV_Setup.md
Manjaro HyperV Install Guide

Deprecated - Microsoft quit updating vm tools in favor of WSL2, it's only a matter of time before this breaks untirely (if it isn't already).

Credits, the original guide which has strangely vanished but can still be found via wayback machine here

This is largely the same as the original but with some updates

  • Setup a new machine in HyperV Manager. Make sure you choose 'Generation 2' and assign default switch for networking (or whatever other adapter you use). Then go to the new VM's settings, disable secure boot, and attach the manjaro iso to it (at the time of writing this, gnome doesn't work).
  • Boot up the vm, you'll be meeting with a black screen or the cli will show it stopped around display starting or whatever. Drop into terminal with CTL + ALT+ F2.
  • Login and type: pacman -Sy && pacman -S xf86-video-fbdev
  • Then restart the display manager: `systemctl r
@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)
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# https://gist.github.com/vadviktor/3c975be22f3e653709252600737631e7
default_language_version:
ruby: 2.6.6
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace