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 {
#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;
@ircmaxell
ircmaxell / abstract.md
Created October 13, 2015 21:13
Life of an If Statement

Life of an If Statement

The humble if statement: so simple, so short, so trivial. But do you know how it works? I mean, how it really works? Join us on a trip down the rabbit hole to find out! Our journey will take us from PHP to C, from Assembly to Machine code, from CPU to Transistor and beyond. We'll discover all sorts of interesting things you many never have known about programming, physics and even the universe itself... I can't promise that you'll return from the depths of the CPU, but if you do, you will not be the same.

<?php
function doStuff() {
//blah
//blah
if (!$this->isWhateverCondition(blah, blah, blah)) {
return false;
}
}
@ircmaxell
ircmaxell / code.php
Last active August 29, 2015 14:25
Tuli printing
<?php
$a = 1;
if ($a > 1) {
$b = 2;
} else {
$b = 3;
}