Skip to content

Instantly share code, notes, and snippets.

@icodealone
icodealone / AssociativeArrayToString.php
Created March 1, 2018 10:21
Convert associative array to string (like an INI file)
static public function asString(array $a) : string
{
return array_reduce(array_keys($a), function($str, $sectionName) use ($a) {
$sub = $a[$sectionName];
return $str . "[$sectionName]" . PHP_EOL .
array_reduce(array_keys($sub), function($str, $key) use($sub) {
return $str . $key . '=' . $sub[$key] . PHP_EOL;
}) . PHP_EOL;
});
}
@icodealone
icodealone / keyed_array_map.php
Created March 1, 2018 11:10
keyed_array_map
function keyed_array_map($fn, array $a) : array
{
return array_column(array_map($fn, array_keys($a), $a), 1, 0);
}
@icodealone
icodealone / samTemplate.yaml
Created October 26, 2018 09:39
Multiple Lambda functions in the samTemplate.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Outputs the date/time
Resources:
TimeFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs8.10