Skip to content

Instantly share code, notes, and snippets.

View janpipek's full-sized avatar
🤔
...

Jan Pipek janpipek

🤔
...
View GitHub Profile
@janpipek
janpipek / export.py
Created August 21, 2014 19:35
Export pixel array from DICOM file to HDF5
import dicom
import h5py
def export_pixel_array(in_file, out_file, dataset_name="data"):
pixel_array = dicom.read_file(in_file).pixel_array
h5 = h5py.File(out_file)
h5.create_dataset(dataset_name, data=pixel_array)
h5.close()
@janpipek
janpipek / auto_git.rb
Last active August 29, 2015 14:05
Check git status before doing something and auto-tag
def ask
print "Do you want to continue? (y/N) "
answer = STDIN.gets.strip.downcase
if answer != "y"
return false
end
return true
end
def get_branch
@janpipek
janpipek / use_plat_linux.sh
Created August 31, 2014 10:28
Include platform-necessary Python modules to virtual env (Fedora)
add2virtualenv /usr/lib64/python2.7/plat-linux2/
@janpipek
janpipek / my_loadtxt.py
Last active August 29, 2015 14:06
Load numpy array from a long text file
def my_loadtxt(fname, columns=-1, delimiter=',', dtype='float32'):
with open(fname) as f:
if columns == -1:
line = f.readline()
columns = np.fromstring(line, sep=delimiter).shape[0]
f.seek(0)
rows = 0
for line in f:
rows += 1
f.seek(0)
@janpipek
janpipek / hdftree.py
Last active August 29, 2015 14:06
Quickly show HDF5 tree using pydons
#!/usr/bin/env python
import pydons
import sys
def _wrap_with(code):
def inner(text, bold=True):
c = code
if bold:
c = "1;%s" % c
return "\033[%sm%s\033[m" % (c, text) # '\033[m'
@janpipek
janpipek / gamma.py
Created September 25, 2014 17:41
Calculation of gamma index on two matrices of the same shape (full and optimized version)
import numpy as np
def gamma_matrix(rm, tm, dta=1.0, dd=0.05):
'''Compute matrix of gammma indices.
:param rm: reference matrix (relative values assumed)
:param tm: tested matrix (relative values assumed)
:param dta: maximum distance-to-agreement (in voxels)
:param dd: maximum dose difference
@janpipek
janpipek / small_case_file_names.rb
Created November 8, 2014 08:21
Turn all file names to small case
#!ruby
# Simple script to change all the file names in current directory to small case
require 'fileutils'
Dir.foreach(".") do |fn|
n = fn.downcase
if n != fn
FileUtils.mv(fn, n)
end
@janpipek
janpipek / anaconda.sh
Created November 11, 2014 08:35
"workon" for anaconda
function anaconda {
# Added by Anaconda 2.1.0 installer
export PATH="/opt/anaconda/bin:$PATH"
# Fix to use pure anaconda Qt
export QT_PLUGIN_PATH="/opt/anaconda/plugins"
}
function workon {
echo "Initializing anaconda..."
@janpipek
janpipek / run-all-notebooks.sh
Created November 22, 2014 13:34
Run all ipython notebooks in a directory
#!/bin/bash
# pip install runipy
find . -maxdepth 1 -name "*ipynb" -print0 | xargs -0 -n1 runipy
@janpipek
janpipek / normostrany.vba
Last active August 29, 2015 14:17
Makro pro zobrazení počtu normostran ve Wordu
Sub Normostrany()
Dim Title As String
Dim CharCount As Long
Dim Message As String
Dim Pages As Double
CharCount = ActiveDocument.BuiltInDocumentProperties("Number of characters (with spaces)")
Pages = CharCount / 1800#
Title = "Počet normostran"