Skip to content

Instantly share code, notes, and snippets.

@mhl
mhl / extract-tree-from-git.py
Created July 29, 2010 15:37
A script to extract a tree from a git repository
#!/usr/bin/python3.1
from subprocess import call, Popen, PIPE, check_call
import re
import sys
import os
import errno
# !! n.b. You probably shouldn't be using this - it's vastly faster and safer to use
# one of the other methods mentioned here:
@mhl
mhl / meld-compare-refs.py
Created July 29, 2010 16:46
Extract the trees from two commits to a temporary directory and run meld on them
#!/usr/bin/python3.1
# This is script that extracts the trees of two commits to temporary
# directories and then runs meld on both directories, so you can compare
# them using meld's nice recursive browsing interface.
#
# This is for an answer to this question:
# http://stackoverflow.com/questions/2006032/view-differences-of-branches-with-meld
from subprocess import call, Popen, PIPE, check_call
@mhl
mhl / Process_Diadem_Neuromuscular.clj
Created August 4, 2010 16:41
A clojure script for Fiji to help process the Diadem Neuromuscular data set
(import '(ij.io DirectoryChooser))
(import '(java.io File))
(import '(java.io FileWriter))
(import '(ij.plugin FolderOpener))
(import '(ij IJ))
(import '(ij.io FileSaver))
;; d should be a java.io.File object
(defn files-in-directory [d]
#!/usr/bin/python2.6
# This script "unsubmodulizes" a git repository - i.e. it takes a git
# repository with submodules and replaces the submodules with the
# history of the submodule merged into a subdirectory of the same
# name. I knocked this up quickly as an answer to this stackoverflow
# question:
#
# http://stackoverflow.com/questions/4542729/undo-submodulization-in-git
#
Checking prerequisites of (fiji.build.SubFake) jars/weka.jar <- fiji jars/Fiji.jar ...
Building (fiji.build.SubFake) jars/weka.jar <- fiji jars/Fiji.jar ...
Building in modules/weka/
Checking prerequisites of (fiji.build.ExecuteProgram) weka.jar <- weka/dist/weka.jar
Checking prerequisites of (fiji.build.ExecuteProgram) weka/dist/weka.jar <-
Building (fiji.build.ExecuteProgram) weka/dist/weka.jar <-
Executing: '../../fiji' '--ant' '-f' 'weka/build.xml' 'exejar'
Found that JAVA_HOME was: '/usr/lib/jvm/java-6-openjdk/'
Buildfile: weka/build.xml
@mhl
mhl / SWC_Display.py
Created February 22, 2011 14:00
In Fiji display SWC files in the 3D Viewer
import re
import os
from java.awt import Color
from ij3d import Image3DUniverse
univ = Image3DUniverse(512, 512)
univ.show()
# d = '/home/mark/painting-demo/static/data'
@mhl
mhl / squash-all.bash
Created March 11, 2011 06:38
A script that squashes your entire branch down to a single commit
#!/bin/bash
# A script that squashes your entire current branch down to a single commit,
# if this repository has a single root commit. This will change the object
# name of the root commit. This is for an answer to the Stack Overflow
# question: http://stackoverflow.com/questions/5266340/
if [ -n "$(git status --porcelain)" ]
then
echo "git status wasn't clean - refusing to run..."
@mhl
mhl / Convert_Traces_to_SWC.py
Created March 26, 2011 05:39
Batch convert Simple Neurite Tracer's .traces files to SWC format
import os
import re
from tracing import PathAndFillManager
# An example script showing how to convert all the .traces
# files in a directory to SWC files. (The .traces format
# is the native file format of Simple Neurite Tracer.)
def run():
d = IJ.getDirectory("Choose your directory of .traces files...")
@mhl
mhl / git-fetch-and-fast-forward-all-branches.sh
Created April 22, 2011 11:35
An example script to show how to fetch from all default remotes and do any fast-forwards of local branches from upstream possible
#!/bin/sh
set -e
CURRENT_BRANCH="$(git symbolic-ref HEAD)"
CURRENT_BRANCH_UPSTREAM="$(git rev-parse --symbolic-full-name @{u} 2> /dev/null)"
# Update the remote-tracking branches for every remote for which
# remote.<name>.skipDefaultUpdate is not true:
git remote update default
@mhl
mhl / wilson-interval.rb
Created July 1, 2011 17:10
Naive pairwise comparisons power
#!/usr/bin/ruby -w
require 'statistics2'
class Numeric
def to_percent
"#{(self * 100).round}%"
end
end