Skip to content

Instantly share code, notes, and snippets.

View iwanbolzern's full-sized avatar

Iwan Bolzern iwanbolzern

View GitHub Profile
@iwanbolzern
iwanbolzern / migrate.sh
Created June 17, 2019 10:38
Migrate one private docker registry into another
source_acr="my.private-registry.com:5000"
target_acr="my-other.private-registry.com:5001"
# read username password for source registry (needed to query api)
echo -n "Insert Username: "
read username
echo -n "Insert Password: "
read -s pw
echo
@iwanbolzern
iwanbolzern / migrate-repository.sh
Created June 17, 2019 10:49
Migrate docker repository from hub.docker.com into private registry
original_image="iwanbolzern/my-awesome-repo"
new_name="iwanbolzern/my-awesome-repo"
target_acr="my-private-registry:5000"
# Download all images
docker pull $original_image --all-tags
# retag image and push to new acr
docker images $original_image \
--format "docker tag {{.Repository}}:{{.Tag}} $target_acr/$new_name:{{.Tag}} | docker push $target_acr/$new_name:{{.Tag}}" |
@iwanbolzern
iwanbolzern / adb_screenshot.bat
Created July 15, 2019 09:26
Script to take a screenshot of an Android phone
adb devices
adb shell screencap -p /sdcard/screen.png
adb pull -p -a /sdcard/screen.png
adb shell rm /sdcard/screen.png
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-3 delims=/:" %%a in ("%TIME%") do (set mytime=%%a-%%b-%%c)
set mytime=%mytime: =%
@iwanbolzern
iwanbolzern / cloud-config.yml
Created July 15, 2019 11:55
Sample cloud-config.yml for basic RancherOS configuration
#cloud-config
hostname: [HOSTNAME e.g. rancher02]
rancher:
network:
interfaces:
eth*:
dhcp: false
eth0:
address: [IP e.g. 192.168.1.141/24]
@iwanbolzern
iwanbolzern / pitfall.md
Created July 17, 2019 06:04
Docker randomly blocks containers

If docker randomly blocks containers it could propably be a logging issue. Docker blocks a process if one log socket isn't fast enough to process all logs. This behavoir can be desabled by passing: (moby/moby#22502)

--log-opt mode=non-blocking --log-opt max-buffer-size=4m
@iwanbolzern
iwanbolzern / .gitlab-ci.yml
Last active April 5, 2024 09:05
gitlab-ci pipline for building docker containers, tagging the code in git and pushing the new generated container into your docker registry.
image: docker:latest
services:
- docker:dind
stages:
- Dev
- Dev-publish
- Prod-Tag
- Prod-publish
variables:
REGISTRY: [Your Registry]
@iwanbolzern
iwanbolzern / log.py
Created July 25, 2019 12:03
Simple logging configuration for python
# setup logging
stdout_handler = logging.StreamHandler(stream=sys.stdout)
rotate_handler = RotatingFileHandler('../log/face-aggregator.log', maxBytes=2000, backupCount=10)
logging.basicConfig(level=logging.INFO,
format='[%(asctime)s] [%(levelname)s] %(message)s',
handlers=[stdout_handler, rotate_handler])
@iwanbolzern
iwanbolzern / period.py
Created August 13, 2019 18:25
This is a simple solution to work with periods in time. For a detailed description of how to use this class check the attached Readme
from datetime import datetime, timedelta
class PeriodException(Exception):
def __init__(self, message: str):
super(PeriodException, self).__init__(message)
class Period:
from datetime import datetime, timedelta
class DateIterator:
def __init__(self, from_date: datetime, to_date: datetime, interval: timedelta, closed: bool = True):
assert (from_date < to_date), 'to_date must be greater than from_date'
self.from_date = from_date
self.to_date = to_date
@iwanbolzern
iwanbolzern / confusion_matrix_pretty_print.py
Created October 9, 2019 06:35
function to convert an sklearn confusion_matrix into a string representation
def confusion_matrix_to_str(cm, labels: List[str], precision: int = 0) -> str:
# get int portion of biggest number
max_entry = len(str(int(cm.flatten().max())))
column_width = max([len(x) for x in labels])
column_width = max(column_width, max_entry + 1 + precision) # + 1 is because the dot (max_entry.precision)
str_rep = ' ' * column_width + '\t'
# Print header
for label in labels: