Skip to content

Instantly share code, notes, and snippets.

View DarwinAwardWinner's full-sized avatar

Ryan C. Thompson DarwinAwardWinner

View GitHub Profile
;; This makes ido-find-file-other-window,
;; ido-switch-buffer-other-window, et. al obsolete. It’s a much better
;; abstraction, and I believe it should become apart of ido mode,
;; because any command that uses ido-completing-read can benefit from
;; it without any additional effort, including textmate.el’s
;; textmate-goto-symbol.
(require 'ido)
@DarwinAwardWinner
DarwinAwardWinner / .home-rsync-filter
Created April 29, 2011 08:12
Example rsync filter file for excluding temp files and stuff
## Rsync Filter for $HOME
# Universal excludes -- These apply to all subdirs
- [Cc]ache
- temp
- tmp
- octave-core
# Emacs temp files
- .#*
@DarwinAwardWinner
DarwinAwardWinner / argprint.py
Created August 25, 2011 15:26
Print a Python function's arguments every time it is called
# This file defines a decorator '@log_to()' that logs every call to a
# function, along with the arguments that function was called with. It
# takes a logging function, which is any function that accepts a
# string and does something with it. A good choice is the debug
# function from the logging module. A second decorator '@logdebug' is
# provided that uses 'logging.debug' as the logger.
from __future__ import print_function
from functools import wraps
from inspect import getcallargs, getargspec
@DarwinAwardWinner
DarwinAwardWinner / wrapdoc.py
Created August 25, 2011 19:30
Fix the line breaks in a Python functions's doc string
import textwrap
def refill_docstring(func, *args, **kwargs):
"""Fix the text wrapping in a function's docstring.
This can be useful when creating doc strings dynamically.
Additional args are options to textwrap.TextWrapper."""
wrapper = textwrap.TextWrapper(*args, **kwargs)
# Remove trailing whitespace from all lines
@DarwinAwardWinner
DarwinAwardWinner / gff-fix.patch
Created August 27, 2012 17:22
Patch to GFF3 reader in rtracklayer
--- a/R/gff.R 2012-03-30 15:59:39.000000000 -0700
+++ b/R/gff.R 2012-05-11 17:36:59.208145562 -0700
@@ -286,13 +286,12 @@
lines <- rep(seq_along(attrSplit), elementLengths(attrSplit))
attrs <- sub(" *$", "", sub("^ *", "", unlist(attrSplit)))
if (is(file, "GFF3File")) {
- attrs <- paste(attrs, "=", sep = "")
- tvSplit <- strsplit(attrs, "=", fixed=TRUE)
- if (any(elementLengths(tvSplit) != 2))
+
@DarwinAwardWinner
DarwinAwardWinner / emacs-osx-pseudo-daemon.el
Created June 28, 2013 05:50
This implements what I call "pseudo-daemon" mode for Emacs on OS X. Emacs doesn't work properly with the OS X GUI unless there is at least one GUI frame at all times, so normal daemon mode isn't ideal. Instead, this code simply ensures that every time you close the last GUI frame, a new hidden one is created.
(defun frame-is-last-ns-frame (frame)
"Returns t if FRAME is the only NS frame."
(and
;; Frame is ns frame
(eq (framep frame) 'ns)
;; No other frames on same terminal
(>= 1 (length (filtered-frame-list
(lambda (frm) (eq (frame-terminal frm)
(frame-terminal frame))))))))
@DarwinAwardWinner
DarwinAwardWinner / interactive-p-reimplementation.el
Last active December 22, 2015 19:09
Reimplementation of `called-interactively-p` in pure elisp, with bugfixes. Try running this file with `emacs -Q -batch -f toggle-debug-on-error -l interactive-p-reimplementation.el`. You should get no errors, but 3 warnings about cases that the built-in `called-interactively-p` gets wrong but my implementation gets right.
(require 'cl)
(defsubst my-interactive-internal ()
"Eqivalent of the INTERACTIVE macro in the Emacs C source.
This should never be called directly."
(and (not executing-kbd-macro) (not noninteractive)))
(defun backtrace-from (fun)
"Return all backtrace frames, starting with the one for FUN.
@DarwinAwardWinner
DarwinAwardWinner / poc_preload_fastq.R
Last active December 24, 2015 08:39
Proof of concept for a wrapper for ShortRead::FastqStreamer that preloads the next set of reads while the calling code is processing the previous set.
library(ShortRead)
library(parallel)
tsmsg <- function(...) message(format(Sys.time(), "%Y-%m-%d %H:%M:%OS6"), ": ", ...)
## Like readChild but returns NULL when child is finished, and
## automatically unserializes results.
readChildSafe <- function(child) {
res <- parallel:::readChild(child)
if (is.integer(res) || is.null(res)) {
@DarwinAwardWinner
DarwinAwardWinner / prevent-free-vars.R
Last active December 27, 2015 08:48
Proof of concept protection against free variables. The purpose is to avoid passing a function to a subprocess for parallel evaluation when that function depends on variables that are only available in the parent process.
library(codetools)
getNonPackageVars <- function (pos=-1L, envir=as.environment(pos)) {
npvarnames <- c()
while (TRUE) {
if (identical(envir, emptyenv()) ||
identical(envir, .BaseNamespaceEnv)) {
## If we hit the empty env, then we started in a package
## namespace, so there are no non-package vars.
return(character(0))
#!/bin/bash
#$ -cwd
#$ -l jabba,mem_free=10G,h_vmem=2G,h_fsize=1G
#$ -N approach1b
#$ -pe local 20
#$ -m e
echo "**** Job starts ****"
date