Skip to content

Instantly share code, notes, and snippets.

View jasny's full-sized avatar

Arnold Daniels jasny

View GitHub Profile
@jasny
jasny / object_init.php
Last active October 2, 2019 10:54
Set the properties (including protected and private) of an object
<?php
/**
* Set the properties (including protected and private) of an object.
* This should only be called by the object itself.
*/
function object_init(object $object, array $values): void
{
$init = function ($values) {
foreach ($values as $prop => $value) {
@jasny
jasny / PasswordResetController.php
Last active November 29, 2019 13:52
Example controllers for Jasny PHP framework
<?php
declare(strict_types=1);
use Jasny\Auth;
use Jasny\Auth\Confirmation\InvalidTokenException;
use Jasny\Persist\Gateway;
use Jasny\Session;
use Psr\Http\Message\ResponseInterface as Response;
@jasny
jasny / bootstrap-em.less
Last active January 5, 2020 15:36
Use em or rem font-size in Bootstrap 3
/**
* Use em or rem font-size in Bootstrap 3
*/
@font-size-root: 14px;
@font-unit: 0rem; // Pick em or rem here
// Convert all variables to em
@jasny
jasny / comparison-gotchas.php
Last active May 24, 2020 13:50
PHP comparison gotchas
<?php
/**
* `a > b > c > a` should always result in false.
*/
function all_greater($a, $b, $c)
{
return ($a > $b) && ($b > $c) && ($c > $a);
}
// Fails due to type juggling.
@jasny
jasny / gen.php
Last active July 6, 2020 14:21
rfc:strict_operators - Generate every combination of operands and operators
<?php
$one = [
'arithmetic' => ['+$a', '-$a'],
'bitwise' => ['~$a'],
'incdec' => ['++$a', '--$a'],
'logical' => ['!$a'],
];
$two = [
@jasny
jasny / CrudClient.php
Last active July 14, 2020 17:52
Example of a CRUD controllers for new framework
<?php
use Jasny\DB\Option\Functions as opts;
use Jasny\HttpAttributes\Request\Accept;
use Jasny\HttpAttributes\Request\ParsedBody;
use Jasny\HttpAttributes\Request\PathParam;
use Jasny\HttpAttributes\Response\ContentType;
use Jasny\HttpAttributes\Route\Delete;
use Jasny\HttpAttributes\Route\Get;
use Jasny\HttpAttributes\Route\Post;
@jasny
jasny / unit.php
Last active July 6, 2021 22:15
Idea for Unit PHP extension
<?php
$distance = new Meter(3);
$cm = $distance->in(Centimeter::class);
ecoh $distance; // 3m
echo $cm; // 300cm
$distance == Decimeter(30); // True
$distance === Decimeter(30); // False
@jasny
jasny / tinytextindex.md
Last active July 6, 2021 22:23
TinyTextIndex

Tiny Text Index

Lightweight text indexer for PHP

Uses the dba extension (with db4)


Storing

Hello my name is Arnold and I'm not crazy. Arnold's kids are crazy though.

@jasny
jasny / icu-config
Created May 26, 2020 01:34
ICU 66.1 for Ubuntu 20.04
#!/bin/sh
## -*-sh-*-
#set -x
# BEGIN of icu-config-top
# Copyright (C) 2016 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html
#******************************************************************************
# Copyright (C) 1999-2013, International Business Machines
# Corporation and others. All Rights Reserved.
#******************************************************************************
@jasny
jasny / find_seed.py
Last active April 5, 2022 19:32
Recover LTO seed from known words
from lto.accounts import AccountFactoryED25519
from itertools import permutations
address = "3JzSs25zWMomDHmw3jA3v9rpqqxxzmCAd9Hs"
words = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"]
factory = AccountFactoryED25519('L')
def find_insert_word():
print("Changing the position of each word")