Skip to content

Instantly share code, notes, and snippets.

@bitfexl
bitfexl / logs.sh
Created July 21, 2025 14:07
Easily view podman compose logs.
#!/bin/sh
podman compose ps -f '{{.Names}}' | cat -n
echo -n 'Select container (number) or press ENTER for full logs: '
read selection
if [ -n "$selection" ]
then
podman compose logs -tn 2>&1 | grep --color=never $(podman compose ps -f '{{.Names}}' | head -n $selection | tail -n 1) | less +G
else
podman compose logs -tn 2>&1 | less +G
fi
@bitfexl
bitfexl / Main.java
Created May 15, 2025 09:33
Java sqlite performace test (file hashes).
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.sql.*;
public class Main {
public static void main(String[] args) throws Exception {
final MessageDigest md5 = MessageDigest.getInstance("md5");
final int recordCount = 10_000_000;
@bitfexl
bitfexl / WaitForPort.java
Created October 19, 2024 08:35
Wait until a given port becomes available.
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
public class WaitForPort {
@SuppressWarnings("BusyWait")
public static boolean waitForPort(InetAddress target, int port) {
while (true) {
@bitfexl
bitfexl / volumescript.sh
Last active October 5, 2024 18:55
Create a volume for Hetzner Cloud.
#!/bin/bash
set -e
API_TOKEN=$1
VOLUME_NAME=$2
VOLUME_SIZE_GB=$3
package org.example;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import okhttp3.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@bitfexl
bitfexl / Main.java
Created July 11, 2024 10:46
Java custom UUID tester.
package org.example;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Main {
final static String UUID_REGEX = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
public static void main(String[] args) {
@bitfexl
bitfexl / YTVideoPlayer.tsx
Last active January 6, 2024 10:23
Play YouTube videos in React applications (also hides related videos from the player).
import { useState } from "react";
import { useMediaPlayer } from "../hooks/useMediaPlayer";
export interface YTVideoPlayerProps {
videoId: string;
privacyMode: boolean;
}
export function YTVideoPlayer({ videoId, privacyMode }: YTVideoPlayerProps) {
const url = `https://www.youtube${privacyMode ? "-nocookie" : ""}.com/embed/${videoId}?autoplay=1&rel=0`;
import java.io.InputStream;
import java.util.*;
public class CSVParser {
/**
* Delimiter for columns.
* Default: ','
*/
private final char delimiter;
@bitfexl
bitfexl / lichessbot.user.js
Created December 10, 2023 15:01
A lichess game analysis script for tampermonkey (can analyse running games). Click raw to install.
// ==UserScript==
// @name Lichess Analysis
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Analyze running games.
// @author bitfexl
// @match https://lichess.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=lichess.org
// @grant none
// ==/UserScript==
@echo off
set /p email= < last_email.txt >nul
set /p version= < last_version.txt >nul
echo Ignore above errors if any.
echo -----------------------------
echo Press enter to use existing values.
set /p email=Enter account email (or cracked name) [%email%]: