Skip to content

Instantly share code, notes, and snippets.

View jasny's full-sized avatar

Arnold Daniels jasny

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / Email.php
Created September 4, 2019 10:52
Use Twig with PHPMailer
<?php
/**
* Render and send e-mail
*/
class Email extends PHPMailer
{
/**
* @var Twig_Environment
*/
@jasny
jasny / poc-standard.php
Created June 26, 2019 07:16
Proof of concept where `strict_types` affects `==` and `!=` operators
<?php
var_dump("1" == 1);
var_dump("1" != 1);