Skip to content

Instantly share code, notes, and snippets.

View elazar's full-sized avatar

Matthew Turland elazar

View GitHub Profile
@elazar
elazar / queens.php
Last active October 5, 2018 17:00
Eight Queens Problem
<?php
/**
* Sample output:
*
* $ time php queens.php
* [ ][ ][ ][ ][ ][X][ ][ ]
* [ ][ ][X][ ][ ][ ][ ][ ]
* [ ][ ][ ][ ][ ][ ][X][ ]
* [ ][X][ ][ ][ ][ ][ ][ ]
@elazar
elazar / conway.php
Created May 17, 2020 12:26
Conway's Game of Life
<?php
$height = 20;
$width = 40;
$live_seeds = 20;
$delay = 1000000;
$empty_grid = fn(): array => array_fill(0, $height, array_fill(0, $width, false));
$random_percent = fn(): float => rand(0, 100) / 100;
@elazar
elazar / README.md
Last active June 24, 2020 22:33
Vampire Chronicles
@elazar
elazar / README.md
Last active June 12, 2020 20:29
Leaving Facebook
@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
@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.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 / 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 / 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 / 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