Skip to content

Instantly share code, notes, and snippets.

View keflavich's full-sized avatar

Adam Ginsburg keflavich

View GitHub Profile
@pkgw
pkgw / affils.sty
Last active March 16, 2016 15:58
Automatically-numbered affiliations using textual keys.
% affils.sty -- automatically number affiliations
% Copyright 2016 Peter Williams <peter@newton.cx>
% Licensed under the MIT License.
%
% To use:
%
% 1. Save this file next to your .tex file and add \usepackage{affils} at its top.
%
% 2. Before your author list, write:
%
@jakevdp
jakevdp / JSClass1.js
Last active August 29, 2015 13:57
A simple Javascript inheritance pattern
/**********************************************************************
I've been working with javascript for a bit, and I miss my
Python-style namespaces and class inheritance. Here's a little
pattern I came up with that allows me to do things (kind of)
the way I wish I could within javascript. I'd be curious if any
experienced JS users have comments or critiques. Thanks!
Edit - also see the second version (which I think is more clean)
below.
**********************************************************************/
#!/bin/env python
# Re-projects a 2D FITS image so that it is aligned pixel-for-pixel with
# another reference FITS image.
# Usage:
# wcsalign.py <infile> <reffile> <outfile>
#
# <infile> = Input fits file
# <reffile> = Reference fits file
@zonca
zonca / planckhighresmap.py
Last active February 15, 2023 01:44
Create a high resolution image of the Planck CMB map
# Script by Andrea Zonca, http://zonca.github.io
import matplotlib
matplotlib.use("agg")
import healpy as hp
import matplotlib.pyplot as plt
use_planck_cmap = True
# Colormap available from https://github.com/zonca/paperplots/raw/master/data/Planck_Parchment_RGB.txt
# Maps available at: http://irsa.ipac.caltech.edu/data/Planck/release_1/all-sky-maps/
@minrk
minrk / nbstripout
Last active June 6, 2023 06:23
git pre-commit hook for stripping output from IPython notebooks
#!/usr/bin/env python
"""strip outputs from an IPython Notebook
Opens a notebook, strips its output, and writes the outputless version to the original file.
Useful mainly as a git filter or pre-commit hook for users who don't want to track output in VCS.
This does mostly the same thing as the `Clear All Output` command in the notebook UI.
LICENSE: Public Domain
@phn
phn / year_to_jd.py
Created May 4, 2012 11:11
Julian dates, decimal years, Gregorian calendar dates, and Julian epochs.
import jdcal
from jdcal import ipart, fpart, is_leap, gcal2jd, jd2gcal
CJ = 36525.0
def days_in_year(year, c="g"):
"""Number of days in a calendar year (Gregorian/Julian)."""
if c.lower() == "g":
return 366 if is_leap(year) else 365
@Grayson
Grayson / isOptionKeyPressed.scpt
Created August 18, 2011 14:03
Applescript snippet to test if Option key is held down.
on isOptionKeyPressed()
return (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSAlternateKeyMask > 1'") is "True"
end isOptionKeyPressed
import pymc as pm
import numpy as np
# FIXME: Need to store duplicates too, when jumps are rejected. That means some mechanism
# for making sure the history is full-rank needs to be employed.
class HistoryCovarianceStepper(pm.StepMethod):
_state = ['n_points','history','tally','verbose']
@endolith
endolith / frequency_estimator.py
Last active October 30, 2023 18:08
Frequency estimation methods in Python
from __future__ import division
from numpy.fft import rfft
from numpy import argmax, mean, diff, log, nonzero
from scipy.signal import blackmanharris, correlate
from time import time
import sys
try:
import soundfile as sf
except ImportError:
from scikits.audiolab import flacread