Skip to content

Instantly share code, notes, and snippets.

<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
$context = new PHPCompiler\Bootstrap\Context;
$parser = new PHPCompiler\Bootstrap\Parser($context);
$parser->parse(file_get_contents(__DIR__ . "/example.php"), __FILE__);
@ircmaxell
ircmaxell / gist:a9bfb2dd437458b89250d7190d0c2712
Created July 28, 2018 12:01
0-A-B != REVERSE(0-REVERSE(A)-REVERSE(B))
Hex Dec Binary
A = A0 160 10100000
B = 4C 76 01001100
0 - A
FFFFFF60 -160 1111111101100000 (lowest 16 bits)
0 - A - B
FFFFFF20 -236 1111111100010100 (lowest 16 bits)
Lowest 8 bits of 0-A-B: 00010100
@ircmaxell
ircmaxell / Permutations
Last active July 27, 2018 21:20
Hamming Distance of 1, changed bits
ACTUAL[0000] CASE[10100001 10000010 01001101 11111111 10010001] XOR[0000] ~XOR[1111] SUM[0000] REVSUM[101110] -REVSUM[0010]
ACTUAL[0000] CASE[10100001 10000010 01001101 11111111 10000001] XOR[0000] ~XOR[1111] SUM[0000] REVSUM[101110] -REVSUM[0010]
ACTUAL[0000] CASE[10100001 11000010 01001100 11111111 11111111] XOR[1111] ~XOR[0000] SUM[1101] REVSUM[101101] -REVSUM[0011]
ACTUAL[0000] CASE[10100001 10000010 01001100 11111111 11111111] XOR[1111] ~XOR[0000] SUM[1101] REVSUM[101101] -REVSUM[0011]
ACTUAL[0000] CASE[10100001 10100011 01001101 11111111 11111111] XOR[1111] ~XOR[0000] SUM[1111] REVSUM[111101] -REVSUM[0011]
ACTUAL[0000] CASE[10100001 10010011 01001101 11111111 11111111] XOR[1111] ~XOR[0000] SUM[1111] REVSUM[111101] -REVSUM[0011]
ACTUAL[0001] CASE[10100001 10100011 01001100 11111111 11111111] XOR[1110] ~XOR[0001] SUM[1110] REVSUM[110101] -REVSUM[1011]
ACTUAL[0001] CASE[10100001 11000010 01001101 11111111 11111111] XOR[1110] ~XOR[0001] SUM[1110] REVSUM[110101] -REVSUM[1011]
ACTUAL[0001] CASE[10100001 1000
@ircmaxell
ircmaxell / gist:eef69bbdaaf4dd5e29af139dc15e092b
Last active July 27, 2018 02:02
Keystone air conditioner IR protocol debugging
Toggle Swing: 10100010 00000001
Toggle LED: 10100010 00001000
Set Temp + Mode
Byte 1: 10100001
Byte 2:
|--------|--------|--------|--------|--------|--------|--------|--------|
| POWER | SLEEP | Fan 0 | Fan 1 | FAN 2 | MODE 0 | MODE 1 | MODE 2 |
<?php
interface Lock {
public function advisory(string $identifier): LockContext;
public function exclusive(string $identifier): LockContext;
public function waitForAdvisory(string $identifier, int $timeout = 0): \Generator;
public function waitForExclusive(string $identifier, int $timeout = 0): \Generator;
}
interface LockContext {
@ircmaxell
ircmaxell / bench.php
Last active January 3, 2018 22:33
bench.php
<?php
use ReckiCT\Jit;
if (function_exists('class_alias')) {
// HippyVM doesn't have a class_alias, so this will break things.
require __DIR__ . '/../vendor/autoload.php';
}
define("IM", 139968);
@ircmaxell
ircmaxell / collection.php
Last active October 19, 2017 14:47
Monads - PHP
<?php
class CollectionMonad extends Monad {
public function __construct(array $value) {
$this->value = $value;
}
public function bind($callback) {
$newValues = array();
foreach ($this->value as $value) {
$newValues[] = $this->callCallback($callback, $value);
<?php
function fibo(int $n): int {
return match($n) {
case 1: 1;
case 0: 1;
case _<0: throw new Exception("Less than 0 is not allowed, " . _ . " provided");
case _: fibo(_ - 1) + fibo(_ - 2);
};
}
#include "pins_arduino.h"
#include "SPI_USART.h"
uint8_t SPIUsartClass::ss[SPIUSART_COUNT];
void SPIUsartClass::begin(uint8_t _usart, uint8_t _ss) {
if (_usart > SPIUSART_COUNT) {
return;
}
ss[_usart] = _ss;
.offset 0xC000
boot:
MOV RJ1, 0x00;
MOV RJ2, 0x00;
MOV RA, 0xD0;
STORE RA;
MOV RJ2, 0x01;
MOV RA, 0x00;
STORE RA;