Skip to content

Instantly share code, notes, and snippets.

View jasny's full-sized avatar

Arnold Daniels jasny

View GitHub Profile
@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 / 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 / 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 / create.php
Created April 23, 2020 02:34
Stripe example PHP code
<?php
require 'vendor/autoload.php';
// This is a sample test API key. Sign in to see examples pre-filled with your key.
\Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
# retrieve JSON from POST body
header('Content-Type: application/json');
$json_str = file_get_contents('php://input');
@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 / CMakeList.txt
Created October 7, 2019 01:21
CMake configuration for php-src
cmake_minimum_required(VERSION 3.8)
project(php C)
# 32bit or 64bit
set(BITNESS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITNESS 64)
endif()
# Global definitions
@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 / build-packagexml.php
Last active July 24, 2022 16:56
Build package.xml for PECL extensions
<?php
/**
* Generate package.xml for pecl extensions.
* Works for new and existing extensions.
*
* Add it to `Makefile.frag`
* package.xml: php_$(PHP_PECL_EXTENSION).h
* $(PHP_EXECUTABLE) build-packagexml.php
*
@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);