Skip to content

Instantly share code, notes, and snippets.

View elazar's full-sized avatar

Matthew Turland elazar

View GitHub Profile
@elazar
elazar / refind-to-postmarks.php
Created October 17, 2023 01:33
Convert Refind export to Postmarks SQL
<?php
$date = fn(int $timestamp): string => date('Y-m-d H:i:s', $timestamp);
$doc = XMLReader::open('refind collection links.html', null, LIBXML_NOERROR | LIBXML_NOWARNING);
$links = [];
$currentTag = null;
while ($doc->read()) {
if ($doc->nodeType == XMLReader::ELEMENT) {
if ($doc->localName === 'h3') {
$currentTag = $doc->readString();
if ($currentTag === 'Dungeons and Dragons') {
@elazar
elazar / readme.md
Last active December 10, 2022 02:53
Personal Finance Project RFC

Problem

Existing software-based personal finance systems (hereafter abbreviated as PFS) tend to lack data portability, customizability, support for self-hosting, mobile-friendliness, or some combination thereof, and are often used as an indirect form of advertising or to otherwise promote paid third-party services.

@elazar
elazar / TwitterCrawler.php
Created May 27, 2022 13:15
Twitter Follower Crawler
<?php
// https://developer.twitter.com/en/docs/twitter-api/getting-started/getting-access-to-the-twitter-api
define('TWITTER_BEARER_TOKEN', '...');
date_default_timezone_set('America/Chicago');
function sendRequest($path)
{
$context = stream_context_create([
@elazar
elazar / html-in-php.php
Last active November 13, 2022 01:11
HTML-in-PHP
<?php
if (!function_exists('array_is_list')) {
function array_is_list(array $array): bool
{
return array_keys($array) === range(0, count($array) - 1);
}
}
$data = [
@elazar
elazar / Dockerfile
Created November 1, 2021 13:11
rustwasm + docker
# https://rustwasm.github.io/docs/book/game-of-life/setup.html
FROM rust:alpine3.14
# https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
ENV RUSTFLAGS="-C target-feature=-crt-static"
RUN apk update
RUN apk add build-base openssl-dev perl npm git
RUN cargo install wasm-pack cargo-generate
@elazar
elazar / userscript.js
Last active October 20, 2021 23:44
Userscript to add sort options for video length and channel to YouTube
const getVideoList = () => document.getElementById("contents");
const getVideoCount = () => {
return Number(
document
.getElementById("stats")
.getElementsByClassName("yt-formatted-string")[0]
.textContent
);
}
@elazar
elazar / README.md
Last active September 13, 2021 13:37
Hurricane Ida Aftermath

Updates

2021-09-13

We made another trip to our old rental property in New Orleans this past weekend. It has had power restored. Most of the standing water was gone. We filled our car with what salvageable possessions we could and brought them back to Lafayete. We've secured a new rental property there and will be moving in over the next week or so. We're planning to make another trip there next weekend to box up the remaining possessions that can be salvaged and transport them to Lafayette in a U-Haul. We're exhausted and still have a lot of things left to do, but we're making progress.

Evacuation

On the morning of Saturday August 28, 2021, we evacuated from our rental home of three and a half years in New Orleans due to Hurricane Ida.

@elazar
elazar / error.log
Last active July 13, 2021 20:11
react/stream
PHP Fatal error: Uncaught ValueError: No stream arrays were passed in vendor/react/event-loop/src/StreamSelectLoop.php:290
Stack trace:
#0 vendor/react/event-loop/src/StreamSelectLoop.php(290): stream_select()
#1 vendor/react/event-loop/src/StreamSelectLoop.php(231): React\EventLoop\StreamSelectLoop->streamSelect()
#2 vendor/react/event-loop/src/StreamSelectLoop.php(212): React\EventLoop\StreamSelectLoop->waitForStreamActivity()
#3 vendor/react/event-loop/src/Loop.php(55): React\EventLoop\StreamSelectLoop->run()
#4 [internal function]: React\EventLoop\Loop::React\EventLoop\{closure}()
#5 {main}
thrown in vendor/react/event-loop/src/StreamSelectLoop.php on line 290
@elazar
elazar / lint.php
Created July 11, 2021 01:58
Lint checking PHP code samples in README.md
<?php
$contents = file_get_contents(__DIR__ . '/README.md');
$start = 0;
while (true) {
$start = strpos($contents, '```php', $start);
if ($start === false) {
break;
}
@elazar
elazar / error.php
Created January 29, 2021 19:17
Psalm Error Example
<?php
// This version replaces the redundant code with a recursive call, but emits these errors:
//
// ERROR: InvalidReturnType - src/Filter/FilterTransformer.php:111:16 - The declared return type 'Kiosk\Filter\PriceRange|array<array-key, Kiosk\Filter\PriceRange|float>|float' for Kiosk\Filter\FilterTransformer::getPrice is incorrect, got 'Kiosk\Filter\PriceRange|array<int|string(max)|string(min), Kiosk\Filter\PriceRange|array<array-key, Kiosk\Filter\PriceRange|float>|float>|float' (see https://psalm.dev/011)
// * @return float|float[]|PriceRange|PriceRange[]
//
// ERROR: InvalidReturnStatement - src/Filter/FilterTransformer.php:130:16 - The inferred type 'array<int|string(max)|string(min), Kiosk\Filter\PriceRange|array<array-key, Kiosk\Filter\PriceRange|float>|float>' does not match the declared return type 'Kiosk\Filter\PriceRange|array<array-key, Kiosk\Filter\PriceRange|float>|float' for Kiosk\Filter\FilterTransformer::getPrice (see https://psalm.dev/128)
// return array_map(
// [$t