Skip to content

Instantly share code, notes, and snippets.

Avatar
🐶
Meredith Palmer Memorial Celebrity Rabies Awareness ProAm FunRun Race 4 The Cure

Sammy Kaye Powers SammyK

🐶
Meredith Palmer Memorial Celebrity Rabies Awareness ProAm FunRun Race 4 The Cure
View GitHub Profile
@SammyK
SammyK / invert-binary-tree.php
Created Sep 6, 2018
Invert A Binary Tree in PHP (Array Implementation)
View invert-binary-tree.php
<?php
// Similar, but not quite the same as LeetCode problem #226
// @see https://leetcode.com/problems/invert-binary-tree/description/
function invertTree(array $nodes): array
{
$height = (int) floor(log(count($nodes), 2));
$level = 1;
while ($level <= $height) {
$start = 2 ** $level - 1;
@SammyK
SammyK / README.md
Last active Aug 1, 2018 — forked from nikic/varVar.php
Script for finding variable-variable usages potentially affected by uniform variable syntax
View README.md

Find Bugs Related To Uniform Variable Syntax

When upgrading to PHP 7, you might run into really hard-to-debug error messages which might be a result of the uniform variable syntax RFC.

This script (forked from Nikita Popov's gist) will scan a PHP 5 codebase and call out the file and line number of an indirect expression with an offset. The evaluation of these expressions has changed in PHP 7.

Installation

To run this script against a PHP 5 codebase, make sure you have PHP and Composer installed. Then create a directory somewhere and install nikic/php-parser with Composer.

@SammyK
SammyK / Color.php
Created Oct 5, 2017
Color RGB matcher
View Color.php
<?php
class Color
{
private $hex;
private $r;
private $g;
private $b;
public function __construct(string $hex) {
@SammyK
SammyK / readme.md
Created Aug 11, 2017
Northeast PHP Hack-a-thon notes
View readme.md

Northeast PHP Hack-a-thon (php-src) 2017

  • Set up GitHub account + add your SSH keys
  • Fork php-src repo to your GitHub account
  • Clone source (or use USB stick) & cd into directory
  • Update origin remote URL with your fork
$ git remote set-url origin {your-fork-URL}
@SammyK
SammyK / Dockerfile
Last active Apr 10, 2019
Writing tests for php-src: Docker setup
View Dockerfile
FROM ubuntu:16.04
MAINTAINER Sammy Kaye Powers
RUN apt-get update \
&& apt-get install sudo vim git -y \
&& apt-get install build-essential autoconf valgrind -y \
&& apt-get install re2c bison -y \
&& apt-get install libxml2-dev locales lcov -y
@SammyK
SammyK / php-retry-keyword-2.0.md
Last active May 25, 2017
Proposed `retry` keyword in PHP 7.NEXT
View php-retry-keyword-2.0.md

Proposed retry keyword in PHP

This is a pivot of the original syntax proposal thanks to feedback from twitter.

The retry keyword adds to the try\catch\finally block to optionally execute an arbitrary statement before jumping to the top of the try block n times.

TL;DR The retry keyword offers a cleaner, more readable & more efficient solution to a common problem.

A simple example

@SammyK
SammyK / php-retry-keyword.md
Last active Apr 3, 2018
Possible syntax for adding the `retry` keyword to PHP 7.next
View php-retry-keyword.md

Without retry keyword

try {
	$attempts = 0;
	retry:
	throw new Exception('Oops!');
} catch (Exception $e) {
	if ($attempts < 4) {
		$attempts++;
@SammyK
SammyK / MyQueueServiceProvider.php
Last active Sep 23, 2015
AWS SQS Push Queues for Laravel 4.1
View MyQueueServiceProvider.php
<?php namespace App\LaravelExtensions;
use Illuminate\Queue\QueueServiceProvider;
class MyQueueServiceProvider extends QueueServiceProvider {
/**
* Register the connectors on the queue manager.
*
* @param \Illuminate\Queue\QueueManager $manager
@SammyK
SammyK / errors_null.phpt
Created Apr 14, 2015
The test we wrote for Chicago PHP. The file was located at `ext/json/tests/errors_null.phpt`
View errors_null.phpt
--TEST--
Checks for return types on error
--SKIPIF--
<?php
if (!extension_loaded('json')) die('skip: json extension not available');
?>
--FILE--
<?php
var_dump(json_last_error('foo'));
?>