Skip to content

Instantly share code, notes, and snippets.

@ForeverZer0
ForeverZer0 / mpd-notify.sh
Created April 9, 2024 04:43
Simple script to display dunst notifications with title, artist, and album art when the current song changes in MPD.
#!/usr/bin/env bash
# Simple script to display display a notification when the current song changes
# in MPD, showing the title, artist, and cover/album art.
#
# Requires: dunst, mpd, and mpc
ALBUMART="/tmp/albumart"
TIMEOUT=3000
@ForeverZer0
ForeverZer0 / cavabar.go
Created February 16, 2024 18:34
Cavabar - easily get formatted CAVA output that is suitable for any taskbar.
// Compile executable with "go build cavabar.go" or just run with "go run cavabar.go"
package main
import (
"encoding/binary"
"flag"
"fmt"
"io"
"math"
@ForeverZer0
ForeverZer0 / rimmod.sh
Last active February 2, 2024 23:37
Simple helper to download RimWorld mods via the terminal from SteamWorkshop.
#!/usr/bin/env bash
# Downloads a RimWorld mod from a SteamWorkshop URL
#
# Usage: rimmod URL [URL2 [URL3]]]
# Example: rimmod https://steamcommunity.com/sharedfiles/filedetails/?id=2009463077
#
# Requires steamcmd to be installed and in $PATH
# Mods will be installed in the Steam folder. (i.e. ~/.steam/SteamApps/workshop/content/294100/)
function rimmod() {
@ForeverZer0
ForeverZer0 / timer.c
Created February 24, 2023 20:51
Portable higher-resolution timer with nanosecond granularity.
/* ----------------------------------------------------------------------- */
/*
Easy embeddable cross-platform high resolution timer function. For each
platform we select the high resolution timer. You can call the 'ns()'
function in your file after embedding this.
https://www.roxlu.com/2014/047/high-resolution-timer-function-in-c-c--
*/
#include <stdint.h>
#if defined(__linux)
@ForeverZer0
ForeverZer0 / VarInt.cs
Last active May 3, 2022 07:10
Static helper classes for reading/writing Minecraft-compatible VarInt and VarLong values to a Stream or arbitrary array of bytes.
using System.Runtime.CompilerServices;
namespace MyNamespace;
/// <summary>
/// Provides static functions for encoding/decoding variable-length integers represented as a <see cref="int"/>.
/// </summary>
public class VarInt
{
private const int SEGMENT_BITS = 0x7F;
@ForeverZer0
ForeverZer0 / Vaccine Exemption Letter
Created November 7, 2021 22:48
Legal Letter from Robert Barnes
Dear Boss,
Compelling any employee to take any current Covid-19 vaccine violates federal
and state law.
First, federal law prohibits any mandate of the Covid-19 vaccines as unlicensed,
emergency-use-authorization-only vaccines. Subsection bbb-3(e)(1)(A)(ii)(III) of section 360 of Title 21 of the United States Code, otherwise known as
the Emergency Use Authorization section of the Federal Food, Drug, and Cosmetic
Act, demands that everyone give employees the “option to accept or refuse administration”
of the Covid-19 vaccine. This right to refuse emergency, experimental vaccines, such as
@ForeverZer0
ForeverZer0 / EndianSwapExtensions.cs
Created August 24, 2021 08:25
Swap endian of numeric types using grouped bit-shifts instead of the much slower Array.Reverse.
using System;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
namespace ChangeThisNamespace
{
/// <summary>
/// Contains extension methods dealing with endianness of numeric types.
/// </summary>
[PublicAPI]
@ForeverZer0
ForeverZer0 / Adler32.cs
Created August 24, 2021 07:03
C# ZLib stream implementation
using System;
using System.Runtime.CompilerServices;
namespace ZLib
{
/// <summary>
/// An Adler-32 checksum implementation for ZLib streams.
/// </summary>
/// <seealso href=""/>
public sealed class Adler32
@ForeverZer0
ForeverZer0 / url_match.c
Created February 8, 2021 19:34
Validate URL in C (POSIX)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
printf("Enter the website URL:\n");
fgets(str, 100, stdin);
if (!strcmp(str, "\n")) {
@ForeverZer0
ForeverZer0 / snake_case.rb
Created November 29, 2020 03:56
Convert from camelCase/PascalCase to snake_case in Ruby
def snake_case
return downcase if match(/\A[A-Z]+\z/)
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z])([A-Z])/, '\1_\2').
downcase
end
"FooBar".snake_case #=> "foo_bar"
"HeadlineCNNNews".snake_case #=> "headline_cnn_fake_news"
"CNN".snake_case #=> "cnn"