Skip to content

Instantly share code, notes, and snippets.

View iwanbolzern's full-sized avatar

Iwan Bolzern iwanbolzern

View GitHub Profile
@iwanbolzern
iwanbolzern / readme.md
Last active March 14, 2022 11:12
Have you ever been in a situation where you would have liked others to give you a data frame with the right columns? If no, you're a lucky one. 🤩 If yes, check out this gist 🧐

First step in the direction of a really typed DataFrame

I come across many great libraries every day, but unfortunately most of them are not well suited for enterprise or medical projects, because they lack the possibility for proper interface definitions or the ussage of refactoring capabilities of your IDE.

This is especially true if it comes to libraries in the data science area. Just remember your last df['my_feature'] = df['my_feature'] * 2 😉 And unfortunately, exactly these libraries are also the ones that are written for super fast computations.

Well it seems that we have the choice between the super fast not typed option and a bunch of slow crappy other implementations...

Hard life... 😥

@iwanbolzern
iwanbolzern / multi_feature_done_callback.py
Created January 22, 2020 07:17
Simple code snipped for adding a done callback to multiple features ✨
def multi_feature_done_callback(futures: List[Future], final_cb: Callable):
head = futures.pop(0)
if len(futures) <= 0:
head.add_done_callback(lambda future: final_cb())
return
head.add_done_callback(lambda _: self._wait_future_async(futures, final_cb))
@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:
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 / 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:
@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 / .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 / 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 / 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 / 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: =%