Skip to content

Instantly share code, notes, and snippets.

View Uplink03's full-sized avatar

Uplink03

  • London, United Kingdom
View GitHub Profile
@Uplink03
Uplink03 / eat_ext4_space.go
Created January 10, 2025 17:45
Eat ext4 space slowly with metadata
// Ext4 leaves metadata allocated for directories when files are deleted.
// That isn't usually a problem, as that allocation is reused when new files are created.
// But if you leave lots of abandonded empty directories around, they can slowly eat up disk space.
// Note on "slowly": "very slowly". On my system (8 cores, nvme drive), it takes aproximately 10s per iteration.
// 100 iteration take 15-20 minutes.
// This program creates 200K small files, and then deletes them, after which it repeats the process in a new directory.
// By default, it loops 100 times using the `output_files` directory.
// If you run `du -h` on a directory that has undergone this process, you'll see that it takes a few megabyets of space.
@Uplink03
Uplink03 / abstract.js
Last active February 14, 2024 04:51
Abstract class pattern in Javascript
// this is an "abstract class" pattern for Javascript
/*
extend `AbstractClass` (meta-class?) to declare your class abstract
define an `abstractMethods()` method in your abstract class to declare which methods child classes must implement
extend your abstract class as normal
*/
// the `AbstractClass` meta-class
class AbstractClass {
@Uplink03
Uplink03 / relativepath.zsh
Last active February 14, 2024 04:54
Function to get relative path give two absolute paths: a base and a target
#!/bin/zsh
## This function exists because on a Mac the `realpath` program doesn't have a `--relative-to` option like GNU does.
## This file can both be used as a standalone command and as a sourced file to use in other scripts.
relativepath()
{
local RelativeTo=$1 Path=$2
if [[ $RelativeTo != /* || $Path != /* ]]; then
@Uplink03
Uplink03 / RefreshTheDamnedDatabase.php
Created November 21, 2023 15:48
Refresh the damned database
<?php
// File path in Laravel project: `tests/RefreshTheDamnedDatabase.php`
declare(strict_types=1);
namespace Tests;
/**
* Quick and dirty database refresh for tests
@Uplink03
Uplink03 / Motorola_G10_Speedup.md
Last active August 3, 2023 00:08
Make Motorola G10 faster

The Motorola Moto G10 is very sluggish on Android 11 (the latest Android available for it) due to its low-end CPU, low RAM (4GB), and what feels like slow flash storage.

The most annoying point is that I can't answer phone calls in a timely manner. It takes about 10 seconds for it to load all the code that can handle the "Answer" button.

I otherwise quite like its battery life, and don't miss the features of a flagship.

But I did manage to make it more usable using the Developer Options:

@Uplink03
Uplink03 / simple-proxy.go
Created May 21, 2023 20:12
Simple HTTP proxy in Go
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
@Uplink03
Uplink03 / UTF8-shenanigans.php
Last active September 28, 2023 11:30
UTF-8 shenanigans
<?php
/*
References:
* https://security.stackexchange.com/questions/9908/multibyte-character-exploits-php-mysql
* https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string
* https://stackoverflow.com/questions/17992893/how-can-i-get-the-single-bytes-from-a-multibyte-php-string-variable-in-a-binary
* https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
* Related reading, but not using UTF-8: https://shiflett.org/blog/2006/addslashes-versus-mysql-real-escape-string
*/
@Uplink03
Uplink03 / SqlExtensions.php
Last active April 4, 2023 16:06
I really want to _like_ SQL's `LIKE` operator...
<?php
declare(strict_types=1);
namespace App\Shared;
use Illuminate\Support\Facades\DB;
/*
I couldn't find a clean way to extend Laravel's Query Builder, so this will have to do.
Reason for this file's existence: I'm tired of writing `addcslashes` everywhere I use the `LIKE` operator.
@Uplink03
Uplink03 / BaldursGate-4K-EnableScaling.md
Last active March 4, 2023 14:10
Baldur's Gate: Enhanced Edition - enable scaling

The problem

  • I got "Baldur's Gate: Enhanced Edition" from Amazon Games.
  • I have a 4K screen on my laptop
  • Baldur's Gate: Enhanced Edition is tiny in the middle of the screen

The game doesn't have an Options screen that I can use.

The solution

@Uplink03
Uplink03 / bash-programming-showcase.bash
Created September 15, 2022 23:55
Bash programming(!) language
#!/bin/bash
# This file is supposed to give you a quick idea about what Bash can do beyond its regular job as a shell or scripting language.
# Bash is more than a scripting language. It's a half-decent programming language. It's snail slow, but half-decent otherwise.
# While it's very archane for such usage, it can be a good substitute for Perl and Python in a pinch.
# These things won't work on cut down shells (e.g. sh, ash, dash), and may explode on ZSH, which has its own,
# somewhat friendlier(!), more modern(!) ways of doing these things.
# Remember kids: always quote your variables in Bash! You're almost certainly expecting them to expand