Skip to content

Instantly share code, notes, and snippets.

View christopherlovell's full-sized avatar
🍊

Chris Lovell christopherlovell

🍊
View GitHub Profile
@hannes-brt
hannes-brt / pyximport_numpy.py
Created December 28, 2010 13:08
Setup pyximport to include the numpy headers
import pyximport
import numpy as np
pyximport.install(setup_args={'include_dirs': np.get_include()})
n <- 50
m <- 50
set.seed(1)
mu <- -0.4
sig <- 0.12
x <- matrix(data=rlnorm(n*m, mu, sig), nrow=m)
library(fitdistrplus)
## Fit a log-normal distribution to the 50 random data set
f <- apply(x, 2, fitdist, "lnorm")

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@ramnathv
ramnathv / gh-pages.md
Created March 28, 2012 15:37
Creating a clean gh-pages branch

Creating a clean gh-pages branch

This is the sequence of steps to follow to create a root gh-pages branch. It is based on a question at [SO]

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" &gt; index.html
@phn
phn / part1.rst
Created July 5, 2012 17:15
Astropython.org PyFits tutorial

PyFITS: FITS files in Python

In this article, we provide examples of using the python module PyFITS for working with FITS data. We first go through a brief

@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.";
@why-not
why-not / gist:4582705
Last active February 1, 2024 00:44
Pandas recipe. I find pandas indexing counter intuitive, perhaps my intuitions were shaped by many years in the imperative world. I am collecting some recipes to do things quickly in pandas & to jog my memory.
"""making a dataframe"""
df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
"""quick way to create an interesting data frame to try things out"""
df = pd.DataFrame(np.random.randn(5, 4), columns=['a', 'b', 'c', 'd'])
"""convert a dictionary into a DataFrame"""
"""make the keys into columns"""
df = pd.DataFrame(dic, index=[0])
@jbwhit
jbwhit / Automatic Voigt Profile Fitting.ipynb
Last active January 15, 2024 07:14
My attempt to create an automatic Voigt Profile Fitting program using PyMC and barak python libraries.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jakevdp
jakevdp / discrete_cmap.py
Last active May 29, 2024 18:50
Small utility to create a discrete matplotlib colormap
# By Jake VanderPlas
# License: BSD-style
import matplotlib.pyplot as plt
import numpy as np
def discrete_cmap(N, base_cmap=None):
"""Create an N-bin discrete colormap from the specified input map"""
@nonsleepr
nonsleepr / tokenizer.R
Created February 12, 2015 21:58
N-gram tokenizer function without any Java dependencies (like in RWeka)
ngrams.tokenizer <- function(x, n = 2) {
trim <- function(x) gsub("(^\\s+|\\s+$)", "", x)
terms <- strsplit(trim(x), split = "\\s+")[[1]]
ngrams <- vector()
if (length(terms) >= n) {
for (i in n:length(terms)) {
ngram <- paste(terms[(i-n+1):i], collapse = " ")
ngrams <- c(ngrams,ngram)
}
}