Skip to content

Instantly share code, notes, and snippets.

View dpo's full-sized avatar
💭
Hacking

Dominique dpo

💭
Hacking
View GitHub Profile
@dpo
dpo / etime.sh
Created November 8, 2010 20:15
Comment out declaration of ETIME as EXTERNAL in Fortran files.
#!/bin/bash
# etime intrinsic cannot be declared as EXTERNAL with gfortran on OSX.
files_with_etime=`find . -name "*.[fF]" | xargs grep -l -i 'etime'`
for fname in $files_with_etime
do
mv $fname ${fname}.backup
sed -e 's/^ \(EXTERNAL[ ]*ETIME.*\)/C \1/' ${fname}.backup > $fname
rm ${fname}.backup
done
@dpo
dpo / Auto-profiling in Python
Created December 5, 2010 21:37
Create a pdf with profile information in the form of a directed graph. Requires graphviz and gprof2dot.py
#!/bin/bash
outfile="profile-$$"
python -m cProfile -o ${outfile}.pstats $@
if [[ $? ]]; then
gprof2dot.py -f pstats ${outfile}.pstats | dot -Tpdf -o ${outfile}.png
echo "Profile graph is in ${outfile}.png"
else
echo "Profile creation aborted."
fi
@dpo
dpo / amplog
Created September 3, 2011 23:00
Simple AMPL Decoding
#!/bin/sh
#
# This script helps save keystrokes when decoding AMPL models.
#
# "amplog name.mod" means "ampl -ogname name.mod"
# "amplog name2 name.mod" means "ampl -ogname2 name.mod"
# "amplog name2 name.mod name.dat" means "ampl -ogname2 name.mod name.dat"
#
dat=
if (( $# == 1 )); then
@dpo
dpo / memo.py
Created September 16, 2011 17:09
Memoization of functions and methods with sha1 digest of numpy arrays.
import numpy as np
import functools
import hashlib
class Memoized(object):
"""
Decorator class used to cache the most recent value of a function or method
based on the signature of its arguments. If any single argument changes,
the function or method is evaluated afresh.
"""
@dpo
dpo / vim.rb
Created March 9, 2012 03:57
Homebrew formula to build vim against Homebrew Python 2.7.3 with client/server feature
# Install with --without-ruby if you observe segfaults.
require 'formula'
class Vim < Formula
homepage 'http://www.vim.org/'
# Get the base 7.4 tarball from Vim.org. But once patches start again, go
# back to tracking Debian unstable here:
# http://ftp.de.debian.org/debian/pool/main/v/vim/
url 'http://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2'
require 'formula'
class ASLDownloadStrategy < NoUnzipCurlDownloadStrategy
def _fetch
# The Netlib FTP server is picky about the password
# used for anonymous access; an @-terminated string isn't enough.
curl '-u', 'anonymous:stout@homebrew.com', @url,
'--output', @tarball_path
end
@dpo
dpo / BibTeX.sublime-build
Last active March 2, 2020 21:56
Sublime build definition to clean up auxiliary LaTeX files. CleanLatexFiles.sublime-build is taken from https://gist.github.com/2852859. Other files are adapted from various sources. Place all files in Packages/User/
{
"cmd": ["bibtex", "$project_path/$project_base_name"],
"working_dir": "$project_path",
"path": "$PATH:/usr/texbin:/usr/local/bin",
"file_regex": "^(...*?):([0-9]+): ([0-9]*)([^\\.]+)",
"selector": "text.tex.latex"
}
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012) (format=pdflatex 2012.6.30) 15 FEB 2013 11:50
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**pkrylov.tex
(./pkrylov.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
@dpo
dpo / mail2things.scpt
Last active December 13, 2015 20:08
An Automator workflow to add an email from Mail.app to Things' Inbox. This is a modification of http://dl.dropbox.com/u/8019/MailToThings.scpt. Create an Automator Service, start with "Get Selected Mail Messages", then "Run AppleScript" and paste the contents of this gist as script. Subsequently, you can process the list of new todo items. I lik…
on run {input, parameters}
set todoList to {}
repeat with theMessage in input
-- Grab message info.
tell application "Mail"
-- Remove apostrophes from Subject as they wreak havoc.
set AppleScript's text item delimiters to {"'"}
#!/bin/bash
np=4
tmpfile=`mktemp -t scalapack`
(( $# > 0 )) && execs="$@" || execs=`find . -type f -perm +111`
fmt='%12s %4s %4s\n'
printf "$fmt" "test" "fail" "skip"
for exec in ${execs[@]}
do
mpirun -np ${np} ${exec} > $tmpfile 2>&1