Skip to content

Instantly share code, notes, and snippets.

View autocorr's full-sized avatar

Brian Svoboda autocorr

View GitHub Profile
#!/usr/bin/env python
# encoding: utf-8
from os.path import splitext
from argparse import ArgumentParser
from markdown import markdown
from weasyprint import HTML
parser = ArgumentParser(description='Write a markdown file to PDF.')
@autocorr
autocorr / fizzbuzz.py
Created May 26, 2014 22:54
FizzBuzz implementation in python
wl = [(3, 'Fizz'),
(5, 'Buzz'),
(7, 'Qux')]
for i in range(0, 101):
print ''.join([w for n, w in wl if not i % n]) or i
!!! write spectra to fits
@p:header
!!! read in and select data
file in class_022.smt
set source "RhoOphE"
set line "HTCOP"
set telescope SMT-FQM-*
find
@autocorr
autocorr / factory.py
Last active August 29, 2015 14:11
A factory function
"""
An example of a class and a factory function.
"""
import model_fit # fit_func lives here
class Fitter(object):
# This would be the starting point for your fit routine,
# and the different methods could do different parts. You could
@autocorr
autocorr / gist:4f5568d853acd7024e04
Last active August 29, 2015 14:11
Some OOP things
class BaseFitter(object):
# Put everything common to all fitting routines in this class
def __init__(self, *args):
# handle the arguments
pass
def interpolate(self):
pass
def calc_covariance(self):
@autocorr
autocorr / essential_git
Created January 28, 2015 00:43
Essential git
# if you haven't setup a ~/.gitconfig, make one with these lines:
git config --global user.name "Your Name"
git config --global user.email "you@email.com"
# first enter the directory you want to version-control and initialize the repository
git init
# git works by storing the changes to files rather than the files themselves,
# so you first have to add the files, or start tracking them
# add all files in the current directory:
@autocorr
autocorr / dark.py
Last active August 29, 2015 14:14
Something dark
def make_dark(infilen, targetfilen, outfilen='masterdark'):
# step 1: median stack the darks
darklist = open(infilen,'r')
darklist = darklist.readlines()
n = len(darklist)
fits = pyfits.open(darklist[0])
darkheader = fits[0].header
imdark = fits[0].data
@autocorr
autocorr / gist:c64020fd24e8ed2062aa
Last active August 29, 2015 14:21
simple prime checker
#!/usr/bin/env python2
def is_prime(x):
assert type(x) == int
assert x > 0
if x == 2:
return True
for n in xrange(2, x / 2 + 1):
if not x % n:
@autocorr
autocorr / cvimrc
Last active February 11, 2016 00:59
" settings
let barposition = "bottom"
let scrollstep = 150
let mapleader = ","
" options
set nosmoothscroll
set scalehints
set linkanimations
set numerichints
@autocorr
autocorr / read_cds_table.py
Created March 19, 2016 22:15
Reading a CDS fixed width table into a pandas dataframe
import pandas as pd
from astropy import table
# use the astropy table reader method to read the file and convert
# to a `pandas.DataFrame`
df = table.Table.read('table1.txt', format='ascii.cds').to_pandas()
df.to_csv('table1.csv', index=False)
# when reading the files, remember to set the index column for
# matching and other things