Skip to content

Instantly share code, notes, and snippets.

@requinix
requinix / batman-netplan.md
Last active August 11, 2023 03:34
batman-adv with Netplan on Ubuntu

Setting up B.A.T.M.A.N. on Ubuntu using Netplan instead of ifupdown

...is a lie

If you're here then I'm going to assume you already know about B.A.T.M.A.N and Netplan, and probably also about ifupdown (or at least /etc/network/interfaces).

Bad news: Netplan cannot currently (2023) set up batman-adv interfaces. Simply no support for it. This suggests that, in order to have batman-adv interfaces, you have to uninstall Netplan and switch back to ifupdown.

Good news: Netplan uses systemd-networkd under the hood, and it does have support. You'll bypass the Netplan configurations and write your own, but it's not too hard. So you can keep Netplan installed and managing your non-batman interfaces.

@requinix
requinix / highlight_string_ex.php
Created February 24, 2021 05:53
Quick PHP code highlighter
<?php
function highlight_string_ex($string) {
static $COLORS = [
"comment" => "\e[32m%s\e[0m", // green
"constant" => "\e[93m%s\e[0m", // yellow
"function" => "\e[97m%s\e[0m", // white
"keyword" => "\e[94m%s\e[0m", // blue
"magic" => "\e[93m%s\e[0m", // yellow
"string" => "\e[95m%s\e[0m", // magenta
@requinix
requinix / installing-windows-on-a-usb.txt
Created April 4, 2020 01:08
Installing Windows on a USB
Requirements
============
* USB device (actually, any storage device works) with an appropriate size for the OS
* A target computer capable of booting from the device
Before you start
================
* Don't run commands blindly
@requinix
requinix / Show file checksums.pas
Created December 29, 2017 10:54
TES5Edit: Show file checksums
{
Show file checksums.
---
Hotkey: Ctrl+Alt+C
}
unit ShowFileChecksums;
function Initialize: integer;
var
f, h: string;
@requinix
requinix / anonymous-class-abuse.php
Created September 28, 2017 19:55
Global functions with (nearly) totally private shared data
<?php
/*
Can I write global functions in PHP that share data between them, without also making that data
accessible to everyone else?
Global functions have a particular utility that is handy, even in an OOP codebase: it doesn't
require a fully-qualified class name/use statement and when in the root namespace the function will
be automatically resolved from any other namespace automatically (though prepending that slash is
@requinix
requinix / webdav-in-php.md
Created August 7, 2017 01:42
WebDAV in PHP

It's actually pretty easy.

Background

DAV ("Distributed Authoring and Versioning") is basically a way to share content between people in a central source. WebDAV is that applied over the internet. It's an older protocol but quite powerful - full CRUD support, plus fancier features like locking.

Windows, and probably Linux too, has built-in support for mounting WebDAV endpoints as "network locations" or virtual drives (eg, Z:). With full DAV support, you can edit files over the internet. There are three different levels/classes of support:

  1. Original WebDAV (RFC 2518)
  2. Locking
@requinix
requinix / papyrus-skyrim.tmLanguage.json
Created July 19, 2017 20:16
VS Code syntax highlighting for Papyrus (Skyrim version)
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Papyrus (Skyrim)",
"scopeName": "source.papyrus-skyrim",
"foldingStartMarker": "(?i)\\b(event|function|property|state)\\b",
"foldingStopMarker": "(?i)\\b(endevent|endfunction|endproperty|endstate)\\b",
"patterns": [
{ "include": "#comments" },
{ "include": "#events" },
{ "include": "#flags" },
@requinix
requinix / oninit-ongamereload.txt
Created April 13, 2017 07:34
Skyrim: OnInit and OnGameReload sequence
Installation (first time running):
0. Quest variables and papyrus state set; SEQs are started and running
1. OnInit #1 - all quests whether they are SEQ or not
2. OnInit #2 - SEQs that are not run-once
Load Game (not first time running):
0. Quest variables, papyrus state, and running state restored
1. OnGameReload - quests that were running at time of save
@requinix
requinix / php-bug-74142.txt
Created February 21, 2017 18:35
3v4l.org/U61Ii
LimitIterator_::rewind rewind at the beginning of the foreach...
> TestFilterIterator_::rewind ...and the inner iterator
> > ArrayIterator_::rewind ...and again. now testfilteriterator must look for the first accept()able value
> > ArrayIterator_::valid iterate on arrayiterator...
> > ArrayIterator_::current ...
> > ArrayIterator_::key ...
> > TestFilterIterator_::accept ...and test the first value it found
accept (call #1 on [0]=>'0')
> > ArrayIterator_::next value ('0') was not accepted
> > ArrayIterator_::valid continue iterating...

https://bugs.php.net/bug.php?id=74077

Good news is that it isn't so difficult to explain this. What's happening is array_map really has two modes of operation: one array and multiple arrays.

Using one array, (a) with $callback: keep array keys, transform value using $callback(value) (b) without $callback: return a copy of the array

array_map(function($value) { return $value; }, $array)