Skip to content

Instantly share code, notes, and snippets.

View SammyK's full-sized 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 / the-modern-php-developer.md
Last active April 7, 2017 03:19
Gone is the age of procedural WordPressy web apps in PHP. The modern PHP developer grabs best practices by the horns to be a coding badass.

The Modern PHP Developer

If you want to be a respectable PHP programmer in this age, make sure you know about a few important things!

PHP Framework Interoperability Group (FIG) Standards

Familiarize yourself with PSR standards. The most important one is PSR-0 as it changed the way PHP is coded in version 5.3.

@SammyK
SammyK / php-function-header.md
Created August 25, 2014 18:09
Possible PHP RFC? Call function based on function header

I don't know enough about how programming languages work to even know what this is called. But when working on an event emitter, I thought it'd be cool if PHP would be able to support this:

class FooClass {
  function bam() { echo 'BAM!'; }
}

function foo(array $bar = []) {
  print_r($bar);
}

Keybase proof

I hereby claim:

  • I am SammyK on github.
  • I am sammyk (https://keybase.io/sammyk) on keybase.
  • I have a public key whose fingerprint is AD0B 4822 0571 049A D52C 995E 0D8B 1EF3 853E 00F4

To claim this, I am signing this object:

@SammyK
SammyK / random_hex.c
Last active August 29, 2015 14:15
Ripped this out of the PHP CRPRNG PR since it got no love! :'(
// Copy/pasted from string.c
static char hexconvtab[] = "0123456789abcdef";
// Copy/pasted from string.c
static zend_string *php_bin2hex(const unsigned char *old, const size_t oldlen)
{
zend_string *result;
size_t i, j;
result = zend_string_safe_alloc(oldlen, 2 * sizeof(char), 0, 0);
@SammyK
SammyK / errors_null.phpt
Created April 14, 2015 03:45
The test we wrote for Chicago PHP. The file was located at `ext/json/tests/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'));
?>
@SammyK
SammyK / MyQueueServiceProvider.php
Last active September 23, 2015 12:01
AWS SQS Push Queues for Laravel 4.1
<?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 / php-retry-keyword.md
Last active April 3, 2018 05:47
Possible syntax for adding the `retry` keyword to PHP 7.next

Without retry keyword

try {
	$attempts = 0;
	retry:
	throw new Exception('Oops!');
} catch (Exception $e) {
	if ($attempts < 4) {
		$attempts++;
@SammyK
SammyK / php-retry-keyword-2.0.md
Last active May 25, 2017 13:11
Proposed `retry` keyword in PHP 7.NEXT

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

This works and takes args!
@SammyK
SammyK / Dockerfile
Last active April 10, 2019 03:02
Writing tests for php-src: Docker setup
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