Skip to content

Instantly share code, notes, and snippets.

View hanslovsky's full-sized avatar

Philipp Hanslovsky hanslovsky

View GitHub Profile
@hanslovsky
hanslovsky / recompress.kts
Last active February 21, 2023 03:57
Recompress zarr array inplace using n5-zarr. Untested, use at own risk. Does not deal with non-existing blocks. Not multi-threaded. Run with kscript: https://github.com/kscripting/kscript
@file:Repository("https://maven.scijava.org/content/groups/public")
@file:DependsOn("org.janelia.saalfeldlab:n5-zarr:0.0.8")
import kotlin.math.ceil
import org.janelia.saalfeldlab.n5.zarr.N5ZarrWriter
import org.janelia.saalfeldlab.n5.zarr.ZArrayAttributes
import org.janelia.saalfeldlab.n5.zarr.ZarrCompressor
require(args.size == 2) { "Two arguments required, zarr group and dataset"}
@hanslovsky
hanslovsky / Pipfile
Last active July 5, 2022 14:35
Explore quicksort with numba
[packages]
numba = "~=0.55"
matplotlib = "~=3.5"
[requires]
python_version = "3.9"
package me.hanslovsky.konkorde
import com.sun.jna.Library
import com.sun.jna.Memory
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure
interface ConcordeLib : Library {
@hanslovsky
hanslovsky / extension-func-resolution.kt
Created March 30, 2022 20:10
Exploring how kotlin extension functions are resolved
interface Base<T: Base<T>>
interface Derived<T: Derived<T>> : Base<T>
class Impl: Derived<Impl>
data class Container<T>(val t: T)
@JvmName("f1")
fun <T: Base<T>> Container<T>.someFunc(c: Container<T>) =
println("generic: $c")
@JvmName("f2")
fun Container<out Derived<*>>.someFunc(c: Container<out Derived<*>>) =
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
imglyb = "~=2.0"
jupyter = "~=1.0"
matplotlib = "~=3.4"
pillow = "~=8.4"
@hanslovsky
hanslovsky / numpy-cacheloader.kts
Last active June 9, 2021 03:01
Example use case for using Jep to generate numpy arrays in CacheLoader
#!/usr/bin/env kscript
// requires kscript: https://github.com/holgerbrandl/kscript
// install jep native libraries with
// python -m pip install jep
// When using Python interpreter in a a non-standard location, set PYTHONHOME appropriately.
@file:MavenRepository("scijava", "https://maven.scijava.org/content/groups/public")
@file:DependsOn("net.imglib2:imglib2-cache:1.0.0-beta-16")
@file:DependsOn("net.imglib2:imglib2:5.12.0")
@hanslovsky
hanslovsky / ThreadsafeInterpreter2.kt
Last active May 10, 2021 02:48
JEP threadsafe interpreter
import java.lang.Class
import java.lang.Thread
import java.util.concurrent.Callable
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import jep.Interpreter
import jep.SharedInterpreter
class ThreadsafeInterpreter2(
@hanslovsky
hanslovsky / find-duplicates.py
Last active July 5, 2022 00:03
Find duplicates in jars
#!/usr/bin/env python3.9
from functools import reduce
from pathlib import Path
from subprocess import check_output
import re
m2_repo = Path.home() / '.m2' / 'repository'
import net.imglib2.imklib.*
import net.imglib2.type.volatiles.*
import net.imglib2.type.numeric.integer.*
// pick any data here
val rawData = imklib.io.n5.openUntypedHDF5("/home/zottel/Downloads/sample_A_20160501.hdf", "volumes/raw").asUnsignedBytes()
val rawDataExtended = rawData.extendBorder().asInts()
val gradientMagnitudeData = (0..2)
.map { d -> LongArray(3) { if (it == d) 1 else 0 } }
.map { rawDataExtended[rawData + it].zeroMin - rawDataExtended[rawData - it].zeroMin }