Skip to content

Instantly share code, notes, and snippets.

@sportebois
sportebois / ecr-add-tag.sh
Created March 29, 2018 18:55
Add tag to a docker image in ECR via AWS CLI
#!/usr/bin/env bash
function ecr-add-tag() {
if (( $# < 3 )); then
echo "Wrong number of arguments. Usage: ecr-add-tag ECR_REPO_NAME TAG_TO_FIND TAG_TO_ADD [AWS_PROFILE]"
return
fi
local repo_name=$1
local existing_tag=$2
local new_tag=$3
@sportebois
sportebois / firacode_in_bitbucket.css
Created February 18, 2018 20:48
FiraCode in Bitbucket (stylish rule)
/* Bitbucket */
@import url(https://cdn.rawgit.com/tonsky/FiraCode/1.204/distr/fira_code.css);
/* Bitbucket code and diffs */
.refract-content-container .line-numbers,
.refract-content-container .source,
body.adg3 .wiki-content pre,
body.adg3 ak-editor-bitbucket .ProseMirror pre,
body.adg3 ak-editor-bitbucket .code,
@sportebois
sportebois / How-to-change-Flash-Builder-langage.md
Created October 20, 2013 22:20
How to change the langage of Flash Builder IDE

Flash Builder does not provide any setting to select the langage of your choice. The used locale is based on your OS locale. To select the locale of your choice (either to get the message in your own locale, or to get the default english error message, which are often more useful), you can just add a locale argument to your Flash Builder shortcut/alias :

Your default Flash Builder shortcut should be somethinf like this :

"C:\Program Files\Adobe\Adobe Flash Builder 4.7 (64 Bit)\FlashBuilder.exe"

You only have to add this argument :

# file: tests/test_dry_demo_01.py
import re
from hypothesis import assume, example, given, strategies
from app.dry_demo_01 import drn_pattern, is_valid_project_drn
valid_drn = strategies.from_regex(drn_pattern)
# file: app/dry_demo_01.py
import re
# The urn pattern describe a workspace, and a resource id
# Examples:
# drn:23f742:bc4b57dd0bec433198a58cd36b6c7ee8
# (drn for Demo Resource Name, or random identifier for demo purposes)
drn_pattern = r"^drn:[a-z0-9]{6}:[a-f0-9]{32}$"
@sportebois
sportebois / docker_registry_cleaner.py
Last active September 25, 2021 10:02
Clean untagged images from AWS ECR registry
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import argparse
import boto3
parser = argparse.ArgumentParser(description='Cleanup Docker images form ECR.')
parser.add_argument('--repository-name', metavar='repo', dest='repository_name', required=True, help='Repository name')
parser.add_argument('--registry-id', metavar='registry', dest='registry_id', required=False, help='Registry ID.If you do not specify a registry, the default registry is assumed.')
parser.add_argument('--delete', dest='delete', required=False, default=False, action='store_true', help='If set to true, delete the untagged images. Otherwise (default), only list them')
@sportebois
sportebois / find-bom.sh
Last active January 27, 2021 13:54
Remove BOM from UTF8 files
#!/usr/bin/env bash
set -eu
# find-bom searches for nonbinary files starting with a BOM marker
# Path of BOM-encoded files is print to stdout
# Exit status is 0 if no BOM files has been found
# Exit status is 1 if at least one BOM file has been found
readonly TARGET_ROOT=${1:-$PWD}
echo "Searching for BOM in $TARGET_ROOT"
@sportebois
sportebois / api_helpers.py
Created October 13, 2020 16:44
Flask custom test client class overridden open()
from flask.testing import FlaskClient
class ApiTestClient(FlaskClient):
def open(self, *args, **kw):
resp: Response = super().open(*args, **kw)
# Send a copy of the request to the sink so that it’s visible for the Akita Agent
resp.freeze()
_publish_to_exposer(kw, deepcopy(resp))
return resp
@sportebois
sportebois / akita-flask-article-snippet-02-fixtures.diff
Last active October 13, 2020 16:38
Update the common fixture to trigger a new one which will started an exposer thread
@pytest.fixture
- def test_client():
+ def test_client(exposer_thread):
configure_app(flask_app, config_name=Environments.TESTS)
# I use this a lot for custom Test client classes to inject custom things
my_project.app.test_client_class = CustomApiTestClient
client = my_project.app.test_client
yield client
@sportebois
sportebois / akita-flask-article-snippet-01-fixtures.py
Last active October 13, 2020 16:37
Common pytest fixture to use Flask test client
@pytest.fixture
def client():
my_project.app.config['TESTING'] = True
with my_project.app.test_client() as client:
with my_project.app.app_context():
# Do some initialization stuff
yield client
# Or