Skip to content

Instantly share code, notes, and snippets.

@dfm
dfm / .vimrc
Created April 26, 2011 03:28
Python template
" TEMPLATES
function! LoadTemplate()
" load a template based on the file extension
silent! 0r ~/.vim/skel/tmpl.%:e
" Replace some placeholders
%s/%FILENAME%/\=expand("%:t")/g
%s/%DATE%/\=strftime("%b %d, %Y")/g
" This last one deletes the placeholder
@dfm
dfm / gist:1030052
Created June 16, 2011 19:39
dude.. gist it
double any_op(double, double, std::function<double(double,double)>);
int main()
{
std::function<double(double,double)> add = [](double a, double b) -> double { return a+b; };
std::function<double(double,double)> sub = [](double a, double b) -> double { return a-b; };
printf("5 + 10 = %0.2f\n", any_op(5., 10., add));
printf("5 - 10 = %0.2f\n", any_op(5., 10., sub));
@dfm
dfm / gist:1041170
Created June 22, 2011 20:57
For Aukosh
from numpy import array,sin,cos,cov
import numpy.random as random
def obs_to_xyz(obs):
D,th,phi,vr,vth,vphi = tuple(obs)
sth,cth = sin(th),cos(th)
sphi,cphi = sin(phi),cos(phi)
return [D*sth*cphi,
D*sth*sphi,
D*cth,
@dfm
dfm / .screenrc
Created July 3, 2011 15:27
screen1
shelltitle "$ |bash"
@dfm
dfm / .bashrc
Created July 3, 2011 15:29
screen2
# command prompt... HOLY SHIT MAGIC!
case $TERM in
screen*)
SCREENTITLE='\[\ek\e\\\]\[\ek\W\e\\\]'
;;
*)
SCREENTITLE=''
;;
esac
export PS1="${SCREENTITLE}[\u@\h \W]\$ "
@dfm
dfm / a.py
Created July 6, 2011 14:03
circular imports suck!
import b
def foobag(a_number):
return a_number+1
@dfm
dfm / bash
Created July 13, 2011 17:01
Reusing ssh connections
time ssh hostname ls
@dfm
dfm / combine_sdss_fields.py
Created August 10, 2011 19:20
Combine SDSS fields for Dustin
# encoding: utf-8
"""
A function for combining adjacent SDSS fields into one image.
History
-------
2011-08-10 - Created by Dan Foreman-Mackey
"""
import cPickle as pickle
import numpy as np
from bson.binary import Binary
from pymongo.son_manipulator import SONManipulator
class NumpySONManipulator(SONManipulator):
def transform_incoming(self, value, collection):
if isinstance(value, (list,tuple,set)):
return [self.transform_incoming(item,collection) for item in value]
if isinstance(value,dict):
@dfm
dfm / test.py
Created December 9, 2011 05:36
Object oriented Python for Ross
import numpy as np
class Catalog(object):
def __init__(self):
self.stars = []
def add_star(self, star):
self.stars.append(star)
@property