Skip to content

Instantly share code, notes, and snippets.

View Widowan's full-sized avatar
🌚

Widowan

🌚
View GitHub Profile

Smartctl Exporter can query smartctl on a disk an returns its status. However, smartctl returns a bitmask and PromQL doesn't have any bitwise operators, making getting a specific bits very tricky. Here's my recipe for this.

Say smartctl returned valued (rv) is 26 and we're only looking for bit 3 ("DISK FAILING"):

rv = 0b0011010 (26)
p  = 2^(3+1) = 16
rv = rv % p  = 0b1010 # Cuts off bits higer than fourth
@Widowan
Widowan / BENCHMARK.md
Last active May 10, 2025 11:44
Benchmark of software overhead of Wireguard, Cloak, Xray, Hysteria and AmneziaWG

I benchmarked a few transport obfuscation protocols to use wireguard with. Here are the results.

Warning

The test is by no means scientific and should not be trusted blindly. You can see the very high loss rate, so it's more of a "software overhead" limit test.

Important

Again! This is not a proper becnhmark! To do proper benchmark, you'd need actual physical servers in same real 10/25 Gbit LAN which I can't afford for testing!

@Widowan
Widowan / 40-nekoray.rules
Created March 23, 2024 11:12
Polkit rules for activating nekoray VPN on linux without password prompt. Not very safe but suffice for personal machine.
// Drop in /etc/polkit-1/rules.d/ and restart `polkit` service.
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.policykit.exec" && subject.isInGroup("MYUSERNAME")) {
if (action.lookup("program") == '/usr/bin/pkill') {
return polkit.Result.YES;
}
if (action.lookup("command_line") == "/usr/bin/bash /home/MYUSERNAME/.config/nekoray/config/vpn-run-root.sh") {
return polkit.Result.YES;
}
@Widowan
Widowan / provision.sh
Last active January 22, 2024 14:45
Stupid simple SSH provisioning in Bash
#!/bin/bash
# Stupid simple SSH provisioning
# The idea is as follows:
#
# ./provision.sh
# ./actions/provision_ssl_certs.sh
# ./actions/provision_postgresql.sh
# ./actions/update_openssh.sh
# ./args/database_servers
#!/bin/bash
SINCE="$1"
UNTIL="$2"
SERVICES=(
pems@master-1
pems@master-2
pems@master-3
pems@worker-1
@Widowan
Widowan / exclude_nets.py
Last active August 27, 2023 07:26
Script to exclude multiple IPs/subnetworks from one starting network. Mainly was made for Wireguard with Cloak transport.
# python3 exclude_nets.py -s 0.0.0.0/0 -e 95.1.63.42/32,10.0.0.0/8,192.168.0.0/24
import ipaddress, getopt, sys, functools
def comparator(i1, i2):
if i1 == i2:
return 0
elif i1.overlaps(i2) and i1.num_addresses > i2.num_addresses:
return -1
else:
return 1
struct Sudoku {
data: Vec<Vec<u32>>,
}
impl Sudoku {
fn is_valid(&self) -> bool {
let size = self.data.len();
if (size as f32).sqrt() % 1.0 != 0.0 { return false }
@Widowan
Widowan / spring-boot-yandex-cloud.md
Last active February 25, 2023 14:31
Заметки по поводу запуска Spring Boot в Yandex Cloud Functions

Документация Yandex Cloud Functions (YCF) по части Java... очень скудная. За сим:

Во первых, в главе по Spring Boot написано, что YCF не поддерживает Spring Boot Loader - classloader, который Spring Boot использует по умолчанию и который предоставляется вместе со spring-boot-maven-plugin (из-за того что в YCF по видимому свой собственный classloader) (очевидно что его нужно убрать, а вместе с ним вы потеряете плюшки вроде mvn spring-boot:run).

Поэтому, нам, логично, необходимо от него избавится. Согласно документации, пропустить его можно используя, например, Maven Shade:

<plugin>
@Widowan
Widowan / spring-openapi-generator-404.md
Last active February 28, 2023 11:11
How to fix controller not working (404 error) with spring openapi-generator-maven-plugin

If you're getting 404 while trying to openapi-generator-maven-plugin, check if you're specifying correct package name (be it apiPackage, modelPackage or packageName).

It should either match with your main package (or any of its subpackages) name, or you have to use additional configuration to find @RestController bean.

i.e. if your main package is dev.wido.MyAmazingProject and you've specified following in plugin's config in pom.xml:

<apiPackage>dev.wido.openapi.api</apiPackage>

You have to add following configuration to your project:

@Widowan
Widowan / !visitor_enum.java
Last active February 20, 2023 14:16
Avoid switching on enum with visitor pattern
// Jdoodle link: https://jdoodle.com/ia/DH0
import java.util.function.BiFunction;
@SuppressWarnings("Convert2MethodRef")
enum Country {
// Can be `CHINA(CountryVisitor::visitChina)`, but that's A LOT less obvious IMO
CHINA((v, data) -> v.visitChina(data)),
INDIA((v, data) -> v.visitIndia(data));
// essentialy BiFunction<CountryVisitor<T, U>, T, U>,