Skip to content

Instantly share code, notes, and snippets.

Avatar

Arnold Daniels jasny

View GitHub Profile
@jasny
jasny / CrudClient.php
Last active Jul 14, 2020
Example of a CRUD controllers for new framework
View CrudClient.php
<?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
ICU 66.1 for Ubuntu 20.04
View icu-config
#!/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
PHP comparison gotchas
View comparison-gotchas.php
<?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 Apr 23, 2020
Stripe example PHP code
View create.php
<?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 Nov 29, 2019
Example controllers for Jasny PHP framework
View PasswordResetController.php
<?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 Oct 7, 2019
CMake configuration for php-src
View CMakeList.txt
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 Oct 2, 2019
Set the properties (including protected and private) of an object
View object_init.php
<?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 Sep 11, 2019
Build package.xml for PECL extensions
View build-packagexml.php
<?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 Sep 4, 2019
Use Twig with PHPMailer
View Email.php
<?php
/**
* Render and send e-mail
*/
class Email extends PHPMailer
{
/**
* @var Twig_Environment
*/
@jasny
jasny / poc-standard.php
Created Jun 26, 2019
Proof of concept where `strict_types` affects `==` and `!=` operators
View poc-standard.php
<?php
var_dump("1" == 1);
var_dump("1" != 1);
You can’t perform that action at this time.