Skip to content

Instantly share code, notes, and snippets.

@gsfr
gsfr / SendToTerminal.vim
Created November 28, 2016 20:03
Send current or highlighted line(s) from MacVim to Terminal
" Send current or highlighted line(s) to Mac OS Terminal.app
function! SendToTerminal(visual, trim_leadspace) range
" move to next line if not in visual mode
if !a:visual
execute "normal \<C-n>"
endif
let cmds = []
if a:trim_leadspace
for line in getline(a:firstline,a:lastline)
let cmds += [escape(escape(substitute(line, '^\s\+', '', ''), '\"'), '\"`!#$%')]
@gsfr
gsfr / tar_zip_bench.py
Created April 27, 2016 00:36
Python tar and zip benchmarking with chunking
import os, zipfile, tarfile
def zip_all(path, outfile):
if os.path.exists(outfile):
os.remove(outfile)
files = [os.path.join(path, f) for f in os.listdir(path)]
with zipfile.ZipFile(outfile, 'a') as zf:
for f in files:
zf.write(f)
@gsfr
gsfr / bids_post.py
Last active August 29, 2015 14:22
Examples of POST and DELETE requests on a scitran API
#!/usr/bin/env python
import os
import sys
import pytz
import time
import hashlib
import requests
import datetime
@gsfr
gsfr / bids_get.py
Last active August 29, 2015 14:21
Query a scitran API and omit BIDS-formatted output
#!/usr/bin/env python
import os
import sys
import requests
import collections
if len(sys.argv) != 3:
print 'usage: %s API_URL USERNAME' % os.path.basename(sys.argv[0])
sys.exit(1)
@gsfr
gsfr / README.mkd
Last active March 28, 2016 23:43
promiscuous mode patch for DCMTK's movescu

How to apply this patch on Ubuntu 14.04

curl http://dicom.offis.de/download/dcmtk/snapshot/old/dcmtk-3.6.1_20150924.tar.gz | tar xz
cd dcmtk-*
curl https://gist.githubusercontent.com/gsfr/3bbe2f89b76019792985/raw/movescu.cc.patch | patch --strip 1
./configure --prefix=$VIRTUAL_ENV
make all
make install
@gsfr
gsfr / serve-https
Created August 5, 2014 17:30
A simple Python HTTPS server
#!/usr/bin/env python
import os
import ssl
import sys
import BaseHTTPServer
import SimpleHTTPServer
port = int(sys.argv[1]) if len(sys.argv) > 1 else 4443
certfile = os.path.dirname(__file__) + '/localhost.pem'
@gsfr
gsfr / R.vim
Created August 10, 2012 04:21
R-MacVim
" send current file path to be sourced by R, optionally temporarily changing R's working directory
function! RSourceFile(filepath, chdir)
let cmd = 'source(\\\"' . a:filepath . '\\\", chdir=' . a:chdir . ')'
silent execute '!osascript -e "tell application \"R64\" to cmd \"' . cmd . '\""'
endfunction
" execute current or highlighted line(s) in R
function! RExecuteLines(visual) range
" move to next line if range is one line
if !a:visual