Skip to content

Instantly share code, notes, and snippets.

👻
it is a mystery

Andrea hikari-no-yume

👻
it is a mystery
Block or report user

Report or block hikari-no-yume

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hikari-no-yume
hikari-no-yume / glob.php
Created May 25, 2019
makes a directory listing
View glob.php
#!/usr/bin/env php
<?php declare(strict_types=1);
$glob = glob($argv[1] ?? "*");
echo "<!doctype html>";
echo "<meta charset=utf-8>";
echo "<body style=\"font-family: monospace;\">";
echo "<ul>";
foreach ($glob as $blob) {
@hikari-no-yume
hikari-no-yume / taxrates.php
Last active Mar 13, 2019
Calculate UK or Scottish income tax and find the point where one costs more than the other (https://twitter.com/hikari_no_yume/status/1105922831626502147)
View taxrates.php
<?php
const UK_2018 = [
0 => 11850,
20 => 46350,
40 => 150000,
45 => INF,
];
const UK_2019 = [
0 => 12500,
View loader.js
function load(stuffs, ondone) {
var loaded = {};
var loadedCount = 0;
stuffs.forEach(function (src, i) {
var img = document.createElement('img');
img.onload = function () {
loaded[src] = img;
loadedCount++;
if (loadedCount === stuffs.length) {
ondone(loaded);
@hikari-no-yume
hikari-no-yume / optimise.php
Last active Feb 11, 2019
Circular avatar optimiser: blacks out 16×16 blocks outside the circle (see: https://hikari.noyu.me/blog/2017-07-30-optimising-circular-avatars.html)
View optimise.php
<?php declare(strict_types=1);
if ($argc !== 3) {
die("Usage: php optimise.php input.jpeg output.jpeg" . PHP_EOL);
}
$infile = $argv[1];
$outfile = $argv[2];
$img = imageCreateFromJPEG($infile);
@hikari-no-yume
hikari-no-yume / example.php
Created Mar 20, 2017
function chaining for PHP 7
View example.php
<?php declare(strict_types=1);
require_once "✨.🐘";
✨($_)->strlen("foo")->var_dump($_);
@hikari-no-yume
hikari-no-yume / lesson.txt
Last active Feb 20, 2017
Advanced Japanese Lesson: #1
View lesson.txt
我 - I
我が - my
我がの - My
我がのな - Ours
我がのなの - Are you mine?
我がのなのは - Our nation is
我がのなのはん - My nakedness
我がのなのはんて - In my opinion
我がのなのはんてね - Do not be mine
我がのなのはんてねだ - It is my mind
View keygen.php
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,<?=strtoupper(bin2hex(random_bytes(16)));?>
<?=wordwrap(base64_encode(random_bytes(2388)), 64, "\n", true);?>
-----END RSA PRIVATE KEY----
@hikari-no-yume
hikari-no-yume / Makefile
Last active Nov 19, 2016
Minimal Famicom assembly example using cc65 which (in PAL mode only, apparently?) flips the screen colour every 256 frames
View Makefile
game.nes: game.o
ld65 -C nrom128.x game.o -o game.nes
game.o: game.s
ca65 game.s -o game.o
clean:
rm *.o *.nes
@hikari-no-yume
hikari-no-yume / CUAD.hs
Created Oct 26, 2016
CUADs are an alternative to UUIDs I created for a project which didn't get finished
View CUAD.hs
-- UUIDs are terrible, and I couldn't get the `uuid` package to work on Haste
-- So here's something similar that I like more
-- CUAD: Cute, Unique And iDentifying
-- (new backronym thanks to those lovely three Irenes)
-- A quad (see what I did there?) of four 32-bit words
-- Canon text representation is 4 hex words separated by dashes
-- e.g. 01234567-89abcdef-deadbeef-abad1dea
-- Like UUIDv4, these should be random (probabilistically unique)
-- Unlike UUIDv4, these have 2^6x as much randomness (128 bits, not 122)
module CUAD
@hikari-no-yume
hikari-no-yume / array_object_casting.php
Last active Nov 5, 2016
object/array cast fix benchmark results
View array_object_casting.php
<?php
echo basename(PHP_BINARY), " - array/object benchmark", PHP_EOL;
echo "---", PHP_EOL;
const ITERATIONS = 100000000;
function benchmark(string $title, \Closure $thing) {
echo $title, ":", PHP_EOL;
You can’t perform that action at this time.