Skip to content

Instantly share code, notes, and snippets.

@dfm
dfm / _chi2.c
Created August 3, 2012 13:41
How to wrap C code in Python
#include <Python.h>
#include <numpy/arrayobject.h>
#include "chi2.h"
/* Docstrings */
static char module_docstring[] =
"This module provides an interface for calculating chi-squared using C.";
static char chi2_docstring[] =
"Calculate the chi-squared of some data given a model.";
@dfm
dfm / LICENSE
Last active September 9, 2023 23:56
XKCD-style plots in d3
Copyright (c) 2012–2013 Daniel Foreman-Mackey
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@dfm
dfm / settings.json
Created February 17, 2023 13:44
Settings for using tectonic with LaTeX Workshop in VSCode
{
"latex-workshop.latex.external.build": {
"command": "tectonic",
"args": ["--print", "--synctex", "%DOC%.tex"]
}
}
@dfm
dfm / betterstep.py
Last active March 1, 2023 18:49
A 'better' step function for matplotlib
import matplotlib.pyplot as plt
def betterstep(bins, y, **kwargs):
"""A 'better' version of matplotlib's step function
Given a set of bin edges and bin heights, this plots the thing
that I wish matplotlib's ``step`` command plotted. All extra
arguments are passed directly to matplotlib's ``plot`` command.
Args:
% Expand NASA ADS journal macros
% ref: https://ui.adsabs.harvard.edu/help/actions/journal-macros
@string{aas="American Astronomical Society Meeting Abstracts"}
@string{aj="Astronomical Journal"}
@string{actaa="Acta Astronomica"}
@string{araa="Annual Review of Astron and Astrophysis"}
@string{apj="Astrophysical Journal"}
@string{apjl="Astrophysical Journal, Letters"}
@string{apjs="Astrophysical Journal, Supplement"}
@string{ao="Applied Optics"}
@dfm
dfm / booboos.sh
Created May 25, 2012 05:46
Count the number of occurrences of "FIXME", "TODO", etc. in the current git repository
function count_code_booboos() {
GIT_DIR=$(git rev-parse --git-dir 2> /dev/null) || return
NOTES_PATTERN="FIXME|TODO|MAGIC"
NOTES_RES=$(echo $(ack -hi --ignore-dir="venv" --ignore-dir="build" \
"\b$NOTES_PATTERN\b" "$(dirname $GIT_DIR)" 2>/dev/null))
for NM in "FIXME" "MAGIC" "TODO"
do
num=$(echo $(echo $NOTES_RES | ack -i "\b$NM\b" | wc -l))
if [ $num != 0 ]
then
@dfm
dfm / intro-to-jax-part2.ipynb
Created June 28, 2022 22:38
intro-to-jax-part2.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dfm
dfm / intro-to-jax-part3.ipynb
Created June 28, 2022 22:38
intro-to-jax-part3.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dfm
dfm / Makefile
Created August 13, 2012 19:51
ctypes chi2 example by @jrwren
libchi2.so: chi2.o
gcc -shared -Wl,-soname,libchi2.so.1 -o libchi2.so.1.0.0 chi2.o -lc
chi2.o: chi2.c
gcc -fPIC -g -c -Wall chi2.c
@dfm
dfm / live-intro-to-jax.ipynb
Last active March 29, 2022 05:15
Live coded notebooks for the GPRV workshop. Check out https://github.com/dfm/gprv for more self contained versions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.