Skip to content

Instantly share code, notes, and snippets.

@nbassler
nbassler / mytypes.c
Last active February 13, 2023 19:54
test platform dependent types
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
int main(void) {
size_t *s;
double *d;
int *i;
@nbassler
nbassler / pretty_float.py
Last active December 16, 2019 18:42
A nicer way to print floating point values.
from math import log10
from math import floor
def pretty(x, min_digits=4, exponent=2):
"""
A nicer way to print floats than the {:g} format.
min_digits: the minimum number of significant digits which will be printed.
@nbassler
nbassler / template.py
Created November 15, 2019 15:16
Python Script Template
import sys
import logging
import argparse
logger = logging.getLogger(__name__)
def main(args=sys.argv[1:]):
""" Main function for trip2dicom.py
"""
@nbassler
nbassler / ptdcm.py
Last active June 21, 2018 12:30
PyTRiP read DICOM
# Example of how to load DICOM data using PyTRiP
# lots of DICOM may be found at SlicerRT
# https://github.com/SlicerRt/SlicerRtData
import pytrip as pt
dp = "/local/dicom/pinnacle3-9.9-phantom-imrt/"
dcm = pt.dicomhelper.read_dicom_dir(dp)
@nbassler
nbassler / test_ppstruct.c
Created May 24, 2018 15:54
Working with list of pointer to structures in C.
#include <stdio.h>
#include <stdlib.h>
/* gcc test_ppstruct.c -o test_ppstruct -Wall */
struct point {
double x;
double y;
};
@nbassler
nbassler / treeview_test.py
Created April 29, 2018 15:03
PyQt5 TreeView with QAbstractItemModel
"""
Reworked code based on
http://trevorius.com/scrapbook/uncategorized/pyqt-custom-abstractitemmodel/
Adapted to Qt5 and fixed column/row bug.
TODO: handle changing data.
"""
import sys
### Keybase proof
I hereby claim:
* I am nbassler on github.
* I am unabdingbar (https://keybase.io/unabdingbar) on keybase.
* I have a public key ASCiRk0ACJmOXLBynm9X7T0gONnCZJIvtqWa3G41RoEiWgo
To claim this, I am signing this object:
@nbassler
nbassler / rebase.txt
Created October 5, 2017 16:16
rebasing
How to rebase:
go to branch to be rebased
$ git rebase master
in case of conflict, fix/edit the file
$ git add file
$ git rebase --continue
repeat until nothing more to be applied.
git push feature/111-mybranch --force
@nbassler
nbassler / pubsub.py
Last active July 30, 2017 14:34
pubsub example
# first line below is necessary only in wxPython 2.8.11.0 since default
# API in this wxPython is pubsub version 1 (expect later versions
# of wxPython to use the kwargs API by default)
from wx.lib.pubsub import setupkwargs
# regular pubsub import
from wx.lib.pubsub import pub
class SomeReceiver(object):
def __init__(self):
@nbassler
nbassler / dicomdiff.py
Last active February 28, 2017 20:21
Make a nice formatted diff on two dicoms
import pytrip as pt
#dcmf = "/local/dicom/pinnacle3-9.9-phantom-imrt"
dcmf = "/local/dicom/xio-4.33.02-phantom-chest/"
dcm = pt.dicomhelper.read_dicom_folder(dcmf)
dcmf2 = "chestdcm"
dcm2 = pt.dicomhelper.read_dicom_folder(dcmf2)
c1 = dcm['images']