Skip to content

Instantly share code, notes, and snippets.

View jeremeamia's full-sized avatar
🌵
WFH in AZ

Jeremy Lindblom jeremeamia

🌵
WFH in AZ
View GitHub Profile
@jeremeamia
jeremeamia / exceptional.php
Last active August 29, 2015 13:57
Throwing and catching non-existent exceptions with class autoloading and aliasing.
<?php
namespace My\Lib
{
class BaseException extends \Exception {}
}
namespace
{
// This should be registered at the end of the autoloading pipeline
@jeremeamia
jeremeamia / psr-cache.php
Last active August 29, 2015 14:02
Why can't we just do a simple cache interface?
<?php
namespace Psr\Cache
{
interface CacheInterface
{
public function get($key, &$isHit); #: mixed
// Note: $isHit is populated with `true` on hit or `false` on miss. This
// is a simple way to distinguish between falsey values and cache misses.
public function has($key); #: bool
@jeremeamia
jeremeamia / box.json
Created July 23, 2014 20:13
box.json for generating aws.phar for AWS SDK for PHP. See http://box-project.org/. Licensed under the Apache 2.0 License.
{
"directories": ["src"],
"files": ["build/aws-autoloader.php"],
"finder": [
{
"exclude": [
"Tests",
"Test"
],
"in": [
@jeremeamia
jeremeamia / iterators.php
Last active August 29, 2015 14:05
Demonstrates that the IteratorIterator must be rewound before it is valid.
<?php
$iter = new IteratorIterator(new ArrayIterator(range('a', 'z')));
var_dump($iter->valid(), $iter->key(), $iter->current());
#> bool(false)
#> NULL
#> NULL
$iter->rewind();
@jeremeamia
jeremeamia / some-iterators.php
Created August 8, 2014 18:57
Some iterators need to be rewound and some don't
<?php
$iter1 = new LimitIterator(new ArrayIterator(range('a', 'z')), 0, 5);
var_dump($iter1->valid(), $iter1->key(), $iter1->current());
#> bool(false)
#> NULL
#> NULL
$iter2 = new MultipleIterator();
$iter2->attachIterator(new ArrayIterator(range('a', 'z')));
@jeremeamia
jeremeamia / min-sdk-instructions.md
Last active August 29, 2015 14:05
Minimal AWS SDK Build

Minimal AWS SDK Build

The AWS SDK for PHP provides API access to 44 of the services offered by Amazon Web Services. It does so by leveraging existing libraries like Guzzle (HTTP client and web service client framework) and the Symfony Event Dispatcher. The best way to install the SDK is using Composer, which helps you install and manage the SDK's dependencies.

However, if you really want to trim down the SDK code for a specific reason, you can download the source of the SDK, and its dependencies using the aws.zip, and remove the parts you don't need. Here is how to do it:

  1. Follow the instructions in the user guide for Installing Via Zip.
  2. Unzip aws.zip.
  3. If you are not using caching features, delete the Doctrine directory.
  4. If you are not using logging features, delete the Monolog and Psr directories.
@jeremeamia
jeremeamia / sesraw.php
Created September 22, 2014 18:27
SES sendRaw API usage in PHP
<?php
$sesClient->sendRaw(array(
'Source' => 'your@email.com',
'Destinations' => array('their@email.com', 'their-other@email.com'),
'RawMessage' => array('Data' => 'MESSAGE')
));
// MESSAGE is the entire raw message, headers and all.
// See http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-raw.html
@jeremeamia
jeremeamia / CacheInterface.php
Last active August 29, 2015 14:07
Simple cache interface idea
<?php
namespace Psr\Cache
interface CacheInterface
{
/**
* @param string $key
* Key for the value in the cache.
* @param bool $isHit
@jeremeamia
jeremeamia / ddb-example.php
Last active August 29, 2015 14:07
Short example of putting a DynamoDB item with new types.
<?php
$dynamoDbClient->putItem([
'TableName' => 'test-table',
'Item' => [
'id' => ['S' => '5432c69300594'],
'name' => ['S' => 'Jeremy'],
'age' => ['N' => '30'],
'phone' => ['L' => [
['M' => ['type' => ['S' => 'mobile'], 'number' => ['S' => '5555555555']]],
@jeremeamia
jeremeamia / Marshaler.php
Last active August 29, 2015 14:07
Idea for DynamoDB helper that supports the new document data model.
<?php
namespace Aws\DynamoDb;
/**
* Marshals JSON documents or array representations of JSON documents into the
* parameter structure required by DynamoDB. Also allows for unmarshaling. Does
* not support binary (B) or set (*S) types, since they are not supported
* explicitly in JSON.
*/
class Marshaler