Skip to content

Instantly share code, notes, and snippets.

View philsturgeon's full-sized avatar
🌳
Planting Trees

Phil Sturgeon philsturgeon

🌳
Planting Trees
View GitHub Profile
@philsturgeon
philsturgeon / 0-intro.md
Last active June 7, 2018 09:34
PSR-2 v CodeSniffer PSR-2

This is a list of issues or discrepencies between the wording or intention of PSR-2 itself and the CodeSniffer PSR-2 ruleset.

Add suggestions in the comments or tweet me (@philsturgeon) if you have more inconsistencies to report.

@philsturgeon
philsturgeon / composer.json
Created July 11, 2013 15:16
Composer Dev Requirements
{
"require": {
"laravel/framework": "4.0.*",
},
"require-dev": {
"behat/behat": "2.4.*",
"mockery/mockery": "0.7.*",
"fzaninotto/Faker": "1.2.*",
"pdepend/pdepend" : "1.1.*",
@philsturgeon
philsturgeon / rewards.md
Last active December 19, 2015 03:09
285 mile "Braking Aids" bike ride sponsorship rewards https://bit.ly/BRAKEAIDS

$1 - That warm fuzzy feeling of being a good person
$5 - A thank you tweet praising your or your company
$10 - Any one of the following:

@philsturgeon
philsturgeon / gist:5859679
Created June 25, 2013 15:58
Kibana user error
[2013-06-25T15:50:22+00:00] INFO: Processing template[/etc/sudoers] action create (sudo::default line 41)
[2013-06-25T15:50:22+00:00] INFO: Processing execute[apt-get-update] action run (apt::default line 22)
[2013-06-25T15:50:22+00:00] INFO: Processing execute[apt-get update] action nothing (apt::default line 29)
[2013-06-25T15:50:22+00:00] INFO: Processing package[update-notifier-common] action install (apt::default line 36)
[2013-06-25T15:50:22+00:00] INFO: Processing execute[apt-get-update-periodic] action run (apt::default line 40)
[2013-06-25T15:50:22+00:00] INFO: Processing directory[/var/cache/local] action create (apt::default line 50)
[2013-06-25T15:50:22+00:00] INFO: Processing directory[/var/cache/local/preseeding] action create (apt::default line 50)
[2013-06-25T15:50:22+00:00] INFO: Processing package[git] action install (git::default line 24)
[2013-06-25T15:50:22+00:00] INFO: Processing package[build-essential] action install (build-essential::default line 48)
[2013-06-25T15:50:22+00:00] INFO:
@philsturgeon
philsturgeon / example.md
Created May 7, 2013 13:56
PSR-0 != Composer

A native implementation of PSR-0 using only the autoloader from the PSR-0 example in the spec would expect a folder structure like this:

League\Oauth2\Client\Foo = myapp/somefolder/League/Oauth2/Client/Foo.php
League\Oauth2\Server\Bar = myapp/somefolder/League/Oauth2/Server/Bar.php

If I was making these as packages, I could make them into two packages, which would be installed in different locations, because thats how Composer rolls:

League\Oauth2\Client\Foo = myapp/vendor/league/oauth2/src/League/Oauth2/Client/Foo.php
League\Oauth2\Server\Bar = myapp/vendor/league/oauth2-server/src/League/Oauth2/Server/Bar.php
@philsturgeon
philsturgeon / gist:5465246
Last active May 23, 2022 12:29
API Golden Rules

Never Expose DB Results Directly

  1. If you rename a field, then your users are fucked. Convert with a hardcoded array structure.
  2. Most DB drivers [for PHP] will show integers as numeric strings and false as "0", so you want to typecast them.
  3. Unless you're using an ORM with "hidden" functionality, people will see passwords, salts and all sorts of fancy codes. If you add one and forget to put it in your $hidden array then OOPS!

Use the URI sparingly, and correctly

  1. Use the query string for paired params instead of /users/id/5/active/true. Your API does not need to be SEO optimised.
  2. ?format=xml is stupid, use an Accept: application/xml header. I added this to the CodeIgniter Rest Server once for lazy people, and now people think it's a thing. It's not.
@philsturgeon
philsturgeon / gist:5417208
Created April 19, 2013 00:18
Magical PSR-0 Replacement
function autoload($className)
{
if (file_exists('autoload.php')) {
require_once('autoload.php');
return;
}
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
@philsturgeon
philsturgeon / broken.py
Last active December 15, 2015 23:29
Apple Push Notification (APN) is a whiny little bitch which needs a new connection every single time. Using time.sleep(1) will cause the SSH connection to break after 4 or 5 pushes, so you need to make a new connection each time. Yay.
from apns import APNs, Payload, PayloadAlert
import time
tokens = [u'tokenhexabcdef0123456789']
apns = APNs(use_sandbox=True, cert_file='client.pem', key_file='key.pem')
alert = PayloadAlert("", loc_key="FOO", loc_args=['Some Guy'])
payload = Payload(alert=alert, sound="default", badge=1)
for token in tokens:
@philsturgeon
philsturgeon / example.php
Last active December 15, 2015 18:19
Generating a 'X','Y' string from an array for an IN query with as little code as possible in Python and PHP. This is done as a learning exercise for me to see how list comprehensions work, being used for some random Twitter "your friends signed up" worker.
<?php
$users = [['id' => 1, 'name' => 'Jack'], ['id' => 2, 'name' => 'Jill']];
echo implode(',', array_map(function($u) { return "'{$u['id']}'"; }, $users));
@philsturgeon
philsturgeon / gist:5281485
Created March 31, 2013 18:08
PHP, you crazy bitch.
php > $i = '';
php > var_dump(++$i);
string(1) "1"
php > var_dump(++$i);
int(2)
php > var_dump(++$i);
int(3)