Skip to content

Instantly share code, notes, and snippets.

@ihnorton
ihnorton / gist:083f64dbbe7f3150efa226e7040a6f80
Created October 17, 2019 14:36
run clang-format on the current branch, show diff, optionally apply
#!/bin/sh
PARENT="origin/dev"
clang_format=$(which clang-format || (echo "could not find clang-format!"; return 1))
diff_files=$(git diff --name-only $PARENT)
diff_cc_files=$(find $diff_files -name "*.cc" -or -name "*.c" -or -name "*.h")
if [[ -z "$diff_cc_files" ]]; then
return 0;
#include <tiledb/tiledb>
#include <iostream>
#include <limits>
#include <iomanip>
std::string array_path("/tmp/test_cc");
std::string array_path2("/tmp/test_cc_2");
std::string attr_name("a");
@ihnorton
ihnorton / ex.jl
Last active June 16, 2019 02:14
Overloading getproperty to dereference fields of a pointer-to-struct
julia> function pointer_field(p::Ptr{T}, sym) where T
idx = findfirst(s -> s==sym, fieldnames(T))
ptype = fieldtypes(T)[idx]
unsafe_load(Ptr{ptype}(Ptr{UInt8}(p) + fieldoffset(T, idx)))
end
pointer_field (generic function with 1 method)
julia>
julia> struct X
import gzip, shutil
# inverted from the python gzip docs
def gunzip(f):
with gzip.open(f, 'rb') as gzip_in, open(f[0:f.find('.gz')], 'wb') as f_out:
shutil.copyfileobj(gzip_in, f_out)
@ihnorton
ihnorton / fetch.sh
Last active November 7, 2019 03:05
Installing devtoolset-3 without root
#!/bin/sh
# pull the listing
wget http://mirror.centos.org/centos/6/sclo/x86_64/rh/devtoolset-3/
# yank the hrefs
egrep -o 'href=\"(.*\.rpm)"' index.html | cut -d \" -f2 > rpm.list
# download them
for f in `cat rpm.list`;
@ihnorton
ihnorton / cmake_prof.py
Last active June 21, 2018 07:13
bare-bones uniq for cmake trace profiling
#!/usr/bin/python
# usage:
# > cmake --trace > foo
# > cmake_prof.py foo
# Return a sorted list of (hitcount, line) for lines in a given file
# dramatically faster than running `sort | uniq` on large files.
@ihnorton
ihnorton / exp_tubes.py
Last active March 14, 2018 19:53
export a set of vtk polylines as tubes
import vtk, os
from glob import glob
def exp_tubes(fname):
rdr = vtk.vtkPolyDataReader()
rdr.SetFileName(fname)
pd = rdr.GetOutputPort()
tf = vtk.vtkTubeFilter()
tf.SetInputConnection(pd)
tf.SetNumberOfSides(6)
@ihnorton
ihnorton / rewrite_includes.jl
Last active January 17, 2018 20:39
Rewrite Slicer VTK and ITK includes to use relative paths
const FS = Base.Filesystem
const regex = r"^((?!//))(#include\s+)(<|\")(\S+)(>|\")\s+"
function get_includes(dir, prefix, exclude="")
includes = Dict{String,String}()
for path in readlines(`bash -c "find $dir -name $prefix*.h -not -path $exclude"`)
(bp,h) = FS.splitdir(path)
bp = replace(bp, dir*"/", "")
if haskey(includes, h)
@ihnorton
ihnorton / gist:bc452cbd54a6d74fd2aa30bf0a53fc01
Last active June 23, 2017 18:42
find new authors between git tags in julia
begin
# assuming pwd is a julia git clone
vers = ["v0.2.0", "v0.3.0", "v0.4.0", "v0.5.0", "release-0.6"]
auths = Dict{String, Vector{String}}()
for v in vers
auths[v] = unique(map(chomp, readlines(`git log --format=%aN $v`)))
end
for i in 2:length(vers)
v1,v2 = vers[i-1],vers[i]
diff = setdiff(auths[v2], auths[v1])
https://app.assembla.com/spaces/slicerrt/subversion/source/HEAD/trunk/SlicerRt/data/eclipse-8.1.20-phantom-prostate/Original/RP.1.2.246.352.71.5.2088656855.377401.20110920153647.dcm?_format=raw