Skip to content

Instantly share code, notes, and snippets.

View b-b3rn4rd's full-sized avatar

Bernard Baltrusaitis b-b3rn4rd

  • Bendigo Bank
  • Melbourne
View GitHub Profile
@b-b3rn4rd
b-b3rn4rd / example.git
Last active May 29, 2023 09:20
Moving pushed commit from one branch to another
// moving 71b8026 from features/project-part-2 to features/project-part-1
git checkout features/project-part-2
git revert 71b8026
// for sanity check can run git diff to between branched for particular file(s)
git difftool features/project-part-2..features/project-part-1 -- ./website/app/controllers/ExampleController.php
git push origin features/project-part-2
git checkout features/project-part-1
git cherry-pick 71b8026
@b-b3rn4rd
b-b3rn4rd / issue-rule-priority
Created November 16, 2017 01:44
auto-increment ALB ListenerRule priority
#!/usr/bin/python
import boto3
import sys
import os
from operator import itemgetter
def main(listener_arn):
client = boto3.client('elbv2')
@b-b3rn4rd
b-b3rn4rd / index.py
Created January 16, 2019 23:52
AWS lambda using RAM by sending HTTP API request without external dependencies
import os
import boto3
import json
import botocore.auth
import botocore.credentials
from botocore.awsrequest import AWSRequest
from botocore.endpoint import BotocoreHTTPSession
from botocore.auth import SigV4Auth
@b-b3rn4rd
b-b3rn4rd / function_v1.php
Last active March 28, 2018 19:06
Convert adjacency list into tree without recursion and second array.
<?php
function array_to_tree(array $array, $parent_id = 0)
{
$array = array_combine(array_column($array, 'id'), array_values($array));
foreach ($array as $k => &$v) {
if (isset($array[$v['parent_id']])) {
$array[$v['parent_id']]['children'][$k] = &$v;
}
@b-b3rn4rd
b-b3rn4rd / hook-dns-01-lets-encrypt-route53.py
Created October 12, 2016 00:06
Python 3 script to use as a hook for the letsencrypt.sh client
#!/usr/bin/env python3
# How to use:
#
# LE_HOSTED_ZONE=XXXXXX LE_AWS_PROFILE=dns-access ./letsencrypt.sh --cron --domain example.org --challenge dns-01 --hook /tmp/hook-dns-01-lets-encrypt-route53.py
#
# More info about letsencrypt.sh: https://github.com/lukas2511/letsencrypt.sh/wiki/Examples-for-DNS-01-hooks
# Using AWS Profiles: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-multiple-profiles
# Obtaining your Hosted Zone ID from Route 53: http://docs.aws.amazon.com/cli/latest/reference/route53/list-hosted-zones-by-name.html
@b-b3rn4rd
b-b3rn4rd / handler.py
Last active October 4, 2016 04:51
API Gateway decorators for transforming request and response templates to lambda Proxy
def handler_pre_dispatch(handler):
"""
Request decorator to convert APIG Proxy params to the old style
Merge GET, POST, STAGE into new event dict
:param handler: resource handler
:return:
"""
def request_decorator(event, content):
event_decorated = {}
@b-b3rn4rd
b-b3rn4rd / ArrayObjectHydrator.php
Created January 6, 2014 10:06
Custom hydrator for Doctrine2, allows to access array elements using getters, similar to the ObjectHydrator
<?php
namespace My\Doctrine\Hydration;
use Doctrine\ORM\Internal\Hydration\ArrayHydrator,
My\ArrayObject as ArrayObject;
/**
* Custom Doctrine2 hydrator, allows to access array properties using getters like
* in ObjectHydrator
*
@b-b3rn4rd
b-b3rn4rd / ArrayObject.php
Last active December 29, 2015 09:49
Accessing array properties through magic getters and setters.
<?php
namespace My;
use Doctrine\Common\Util\Inflector;
/**
* Allow to access array properties using getters/setters
*
* @method null set${Property}(mixed $value) set array property
* @method mixed get${Property}() get array property
* @author Bernard Baltrusaitis <bernard@runawaylover.info>
@b-b3rn4rd
b-b3rn4rd / Form.php
Created October 3, 2013 06:31
Get flatten Zend_Form error messages
<?php
class My_Form extends \Zend_Form
{
/**
* Flatten Zend_Form error messages
*
* @param \Zend_Form|null $form
* @param array|null $messages
* @param int $i
* @return array
@b-b3rn4rd
b-b3rn4rd / UpdateCommand.php
Last active December 20, 2015 19:09
Allow 'orm:schema-tool:update' to filter entities
<?php
namespace My\Doctrine\ORM\Tools\Console\Command\SchemaTool;
use Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand as UpdateCommand2,
Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console\Input\InputInterface,
Symfony\Component\Console\Output\OutputInterface,
Doctrine\ORM\Tools\SchemaTool,
Doctrine\ORM\Tools\Console\MetadataFilter;