Skip to content

Instantly share code, notes, and snippets.

View philsturgeon's full-sized avatar

Phil Sturgeon philsturgeon

View GitHub Profile
@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 / 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: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 / 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 / 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 / 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 / gist:6378999
Last active December 21, 2015 22:59
PSR-2 Control Structures and Statements

Class/method blocks:

These things are "blocks" of code, always on their own lines because they are always by themselves.

<?php
class Foo
{
  public function doSomeShit() 
 {
@philsturgeon
philsturgeon / Syntax Examples.md
Last active December 22, 2015 02:39
PHP Named Param History

Example A

Inside the function declaration all values are assigned to variables, so using variable syntax on the outside seems to make sense too.

$api->getFriends($screen_name = 'phpdrama', $include_user_entities = true);

Pro:

@philsturgeon
philsturgeon / README.md
Last active December 22, 2015 09:59
MySQL Enum Quiz

Preperation

Read the SQL statements in instructions.sql.

Question

Only one of the following queries will produce 1, the other two will produce 0.

Which query will produce the number 1?

@philsturgeon
philsturgeon / examples.php
Created November 26, 2013 19:35
Proposed short logical assignment operator
<?php
$foo = null;
// If's - verbose and uneccassry
if (! $foo) {
$foo = 'default';
}
// Short Ternary syntax