Skip to content

Instantly share code, notes, and snippets.

View caniko's full-sized avatar
❤️‍🔥
Love is the answer

Can H. Tartanoglu caniko

❤️‍🔥
Love is the answer
View GitHub Profile
@caniko
caniko / clean_3d_mask.py
Last active March 15, 2023 16:25
Delete smaller artifacts from a single object binary image volume
from typing import Iterable
from scipy.ndimage import label, find_objects
def volume_from_slices(*slices: Iterable[slice]):
volume = 1
for comp_slice in slices:
volume *= (comp_slice.stop - comp_slice.start)
return volume
@caniko
caniko / README.md
Last active November 25, 2023 15:58
My way of integrating poetry to docker container

Poetry docker integration

I landed on using archlinux as my base image. I use chaoti-aur to install the latest poetry from git, I can choose the exact Python version I want thanks to pyenv (made it conveniant by adding this as an env var, PYTHON_VERSION).

You can install your poetry package after copying it to your WORKDIR by poetry install --no-dev. Flush the poetry cache by poetry cache clear --all; no neat way to do this yet #887.

Advantages of archlinux + poetry in containarized production

  • Installing poetry through pacman installs the poetry as root. Poetry installer is rootless by default, which is not production-friendly; it is now! Don't forget to switch to a user wihtout write-access to root! Otherwise, you won't benefit from this safety feature.
  • Separation of Python used for production code, and poetry code. Poetry will run on the latest stable version of Python, while production code will run on whatever version it was designed for.
  • Less maintanance of `dockerf
@caniko
caniko / parsedCsvToDataframe.dart
Last active January 20, 2022 11:46
Convert header + row data to Dart df
import 'package:df/df.dart';
import 'package:grizzly_io/io_loader.dart'; // to parse CSV string
DataFrame _convertHeaderRowDataToDf(List<List<String>> headerRowData) {
List<String> headers = headerRowData[0];
List<Map<String, Object?>> mappedData = [];
for (int i = 1; i < headerRowData.length; i++) {
Map<String, Object?> mappedRow = {};
headerRowData[i].asMap().forEach((int rowIndex, value) {
mappedRow[headers[rowIndex]] = value;
@caniko
caniko / morphological_interpolation.py
Created January 5, 2022 09:34
Implementation of morphological interpolation along the z-axis for binarized images
from typing import Union
import itk
import numpy as np
from yaspin import yaspin
from yaspin.spinners import Spinners
INTERPOLATION_TEXT = "Interpolating for the first time"
@caniko
caniko / create_materialized_view.py
Last active January 20, 2022 11:35
Create materialized view with Python Datastax Driver
from logging import warning
from typing import Union, Iterable, Optional
from cassandra.cqlengine.models import Model
from cassandra.cluster import Session
def join_null_check_columns(column_keys):
return " ".join(f"AND {key} IS NOT NULL" for key in column_keys)