Skip to content

Instantly share code, notes, and snippets.

View samjarrett's full-sized avatar
:shipit:

Sam Marley-Jarrett samjarrett

:shipit:
View GitHub Profile
import argparse
import yaml
import boto3
CLOUDFORMATION = boto3.client("cloudformation")
def main():
parser = argparse.ArgumentParser(prog="convert_parameters")
@samjarrett
samjarrett / paginate.py
Created June 11, 2021 12:51
boto paginators the right way
def paginate(method, **kwargs):
client = method.__self__
paginator = client.get_paginator(method.__name__)
for page in paginator.paginate(**kwargs).result_key_iters():
for result in page:
yield result
# usage:
import boto3
@samjarrett
samjarrett / assume_role.py
Created May 18, 2021 05:25
Botocore's built-in Refreshable role assumption
import botocore.session
from botocore.credentials import (
AssumeRoleCredentialFetcher,
DeferredRefreshableCredentials,
)
import boto3
def get_boto3_session(assume_role_arn=None):
session = boto3.Session()
@samjarrett
samjarrett / .gitlab-ci.yml
Created November 3, 2016 05:53
gitlab-ci.yml for building and shipping containers to gitlab registry
build_image:
image: docker:git
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker pull registry.gitlab.com/[username]/[project-name]:latest
- docker build -t registry.gitlab.com/[username]/[project-name] .
- docker push registry.gitlab.com/[username]/[project-name]:latest
only:
@samjarrett
samjarrett / Campaign.php
Created March 3, 2015 09:48
Trying to validate an object two different ways
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class Campaign
* @package AppBundle\Entity
@samjarrett
samjarrett / property_access.php
Created October 28, 2013 04:31
#melbsf2 Symfony Components: Using the PropertyAccess component (see http://samjarrett.github.io/Symfony2-Components-Presentation/pres.html)
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
function getData($items, $columns) {
$accessor = PropertyAccess::createPropertyAccessor();
$rows = array();
foreach ($items as $item) {
$rows[] = array_map(function ($path) use ($item, $accessor) {
@samjarrett
samjarrett / convert.php
Last active December 26, 2015 17:59
#melbsf2 Symfony Components: Using the Process component (see http://samjarrett.github.io/Symfony2-Components-Presentation/pres.html)
<?php
use Symfony\Component\Process\Process;
$process = new Process('svn2git ' . $svnHref);
$process->setTimeout(3600);
$process->run(function ($type, $buffer) {
if (Process::ERR === $type) {
$output->write('<error>' . $buffer . '</error>');
} else {
@samjarrett
samjarrett / app.php
Last active December 26, 2015 17:59
#melbsf2 Symfony Components: Using Finder component (see http://samjarrett.github.io/Symfony2-Components-Presentation/pres.html)
<?php
// building from the last example...
use Symfony\Component\Finder\Finder;
$finder = Finder::create()
->files()
->in(__DIR__ . DIRECTORY_SEPARATOR . 'Command')
->name('*Command.php');
@samjarrett
samjarrett / app.php
Last active December 26, 2015 17:59
#melbsf2 Symfony Components: Using Console component (see http://samjarrett.github.io/Symfony2-Components-Presentation/pres.html)
<?php
$loader = require(__DIR__.'/vendor/autoload.php');
// Do some bootstrapping of your application
use Symfony\Component\Console\Application;
$application = new Application;
$application->add(new \MyProject\Command\SomeCommand);
@samjarrett
samjarrett / 1_Result.php
Created March 24, 2013 04:13 — forked from cystbear/1_Result.php
A quick mock-up of how you can create custom annotation mappings in Symfony2.
<?php
class DefaultController extends Controller
{
/**
* Dashboard page.
* @Permissions(perm="dashboard_view")
* @Route("/", name="ITEDashboardBundle_index")
* @Template()
* @return array