Skip to content

Instantly share code, notes, and snippets.

@dfm
dfm / README.md
Last active December 18, 2015 18:49
Change your git push experience forever.

This will change your life. Add this as a git pre-push hook.

How, you ask?

wget https://gist.github.com/dfm/5828028/raw/772270b65a804678db70012d3406f41c79cb53a5/pre-push
chmod +x pre-push
mv pre-push /path/to/your/favorite/repo/.git/hooks
cd /path/to/your/favorite/repo
git push
import flask
def create_app(config_filename=None, ...):
app = flask.Flask(__name__)
# Default settings.
app.config.from_object("myapp.default_settings")
# If a filename was provided, load the requested settings from a file.
if config_filename is not None:
@dfm
dfm / bulk_test.py
Last active December 18, 2015 23:39
Bulk download test...
import json
import urllib2
url = "http://api-dev.sdss3.org/spectrumQuery"
payload = {"ra": ["227.69425d", "227.85043d", "236.84261d"],
"dec": [26.94044, 26.40779, 1.38737]}
# or...
# payload = {"ra": ["227.69425d", "227.85043d", "236.84261d"],
# "dec": [26.94044, 26.40779, 1.38737],
# "radius": [3., 3., 3.]}
@dfm
dfm / line.py
Created July 15, 2013 15:38
emcee: line with 2D errors.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function
import emcee
import numpy as np
import matplotlib.pyplot as pl
np.random.seed(123)
@dfm
dfm / get_tp.py
Last active March 12, 2022 15:44
Get Kepler target pixel files.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import kplr
from urllib2 import HTTPError
# Choose a star.
client = kplr.API()
kic = client.star(10592770)
print("Kepler magnitude: {0}".format(kic.kic_kepmag))
@dfm
dfm / ghsg.py
Last active December 22, 2015 11:49
GitHub activity as a social graph.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import gzip
import redis
import random
import requests
from StringIO import StringIO
from datetime import datetime, timedelta
@dfm
dfm / ind.py
Created October 16, 2013 15:30
Using emcee to generate approximately N independent samples.
import emcee
import numpy as np
sampler = emcee.EnsembleSampler(...)
pos, lnprob, rstate = sampler.run_mcmc(p0, 1000)
nindependent = 0
while nindependent < 500:
pos, lnprob, rstate = sampler.run_mcmc(pos, 1000, rstate0=state, lnprob0=lnprob)
try:
@dfm
dfm / bibliographies.md
Created October 25, 2013 15:10
Call for bibliographies

I'm doing an experiment in natural language processing (NLP) to study models for discovery of (personally) relevant scientific literature and I need your bibliographies! The immediate motivation for this experiment is a class that I'm taking at NYU this semester but I've been interested in this problem for a while and I expect this research to extend past this semester. The basic idea is to take the content of all the astro-ph articles on the arXiv and combine that with user data to generate recommendations of articles that readers might be interested in looking at. The model is based on work by Wang & Blei (2011) but generalized to use a more sophisticated author-topic (AT) model based on Rosen-Zvi, et al. (2010). This is relevant for astro-ph because the user dataset is neccessarily

@dfm
dfm / sparse.c
Created November 8, 2013 17:57
Sparse kernel
#include <math.h>
double params[] = {1.0e-3, 1.0, 5.0};
function kernel (double t1, double t2)
{
double r, omr,
d = x1 - x2,
chi2 = d * d,
p2 = params[2] * params[2],
@dfm
dfm / data.png
Last active December 31, 2015 13:29
Generating some fake data from a GP with a white noise component
data.png