Skip to content

Instantly share code, notes, and snippets.

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

Viktor (Ikon) VAD ๐Ÿ€ vadviktor

๐Ÿ€
Mining Ruby ๐Ÿ’Ž โ›๏ธ
View GitHub Profile
@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)
@vadviktor
vadviktor / delete-google-photos.py
Created January 24, 2021 09:21
Delete all Google Photos with Selenium, Firefox, Python
"""
1. create a separate Firefox profile
2. start that profile and log into the Google Account of choice
3. get the profile's path from `about:profiles`
4. set `profile_url` to the profile's path
5. run script
"""
from time import sleep
from selenium import webdriver
@vadviktor
vadviktor / drop-shadow.sh
Created September 24, 2020 10:20
Create a decent but narrow shadow with Imagemagick
#!/bin/bash
if [[ -f "${1}" ]]; then
tmp="${1%.*}"
convert "${1}" \( +clone -background gray -shadow 80x8+8+8 \) +swap -background white -layers merge +repage "${tmp}_drop-shadow.png"
fi
@vadviktor
vadviktor / main.go
Created June 24, 2019 16:32
Find IP address that matches a subset.
package main
import (
"bytes"
"fmt"
"log"
"net"
)
func main() {
@vadviktor
vadviktor / db.rake
Created March 8, 2019 17:09
Rails: kill all PostgreSQL connections.
namespace :db do
desc "Kick out PostgreSQL users from the database."
task kick: [:environment] do
begin
ActiveRecord::Base.connection.execute <<-SQL
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '#{ActiveRecord::Base.connection.current_database}';
SQL
rescue ActiveRecord::StatementInvalid
@vadviktor
vadviktor / sync.py
Created February 18, 2019 12:56
Sync repos from Github
"""
https://gitpython.readthedocs.io/en/stable/index.html
"""
import shutil
from git import Repo
repos = {
"github": "[email protected]:vadviktor/test.git",
@vadviktor
vadviktor / main.go
Created July 6, 2018 14:04
Go: Nested maps access in a template
package main
import (
"log"
"os"
"text/template"
)
func main() {