Skip to content

Instantly share code, notes, and snippets.

@chris-taylor
chris-taylor / FieldExtension.hs
Created December 23, 2013 17:19
Simple field extensions in Haskell
module FieldExtension where
{-
This module lets you define the exact Fibonacci function using the mathematically
elegant definition in terms of phi = (1 + sqrt 5) / 2, without losing precision
due to calculations being carried out in floating point.
phi :: Q5
phi = 0.5 :+ 0.5
@chris-taylor
chris-taylor / gist:5868299
Last active December 19, 2015 00:20
Testing GFM

Heading 1

Some Q code

fib: {[n]
  $[n<2; n; fib[n-1]+fib[n-2]]
}
@chris-taylor
chris-taylor / salary.py
Created June 2, 2013 17:03
Quick script to pull out salary data from indeed.co.uk and compute averages
# -*- coding: utf-8 -*-
import re
import sys
import locale
from bs4 import BeautifulSoup
from urllib2 import urlopen
%% Read in files and extrapolate mortality rate
x = csv.read('life.csv','format', '%f %f');
age = x{1};
prob = x{2};
model = stats.lm(log(prob(61:end)), log(age(61:100)));
pfun = @(a) util.if_(a<60, @()prob(a), util.if_(a>121, 1, exp(model.beta(1) + model.beta(2) * log(a))));
@chris-taylor
chris-taylor / homebrew-opencv.log
Last active December 16, 2015 23:50
OpenCV failed to build on 10.7.5
This file has been truncated, but you can view the full file.
## Output of brew --config
crntaylor:opencv crntaylor$ brew --config
HOMEBREW_VERSION: 0.9.4
ORIGIN: https://github.com/mxcl/homebrew
HEAD: 7be8b458f96da9d37d009c1a96888419f646c7cf
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit sandybridge
OS X: 10.7.5-x86_64
@chris-taylor
chris-taylor / mcode.matlab
Created May 3, 2013 14:27
Writes code that evaluates to a given Matlab object.
function code = mcode(x)
% MCODE Returns a char array containing Matlab code that evaluates to the
% object x. That is, the two quantities
%
% >> x
% >> eval(mcode(x))
%
% should be identical.
%
@chris-taylor
chris-taylor / search.matlab
Created April 30, 2013 09:18
Download images from Google image search
function search(query,path)
% Download full size images from Google image search. Saves image files
% locally. Do not print or republish images without permission.
%
% Based on Python code by Craig Quiter at https://gist.github.com/crizCraig/2816295
%
% Requires the JSONLab package, available from
% http://www.mathworks.com/matlabcentral/fileexchange/33381-jsonlab-a-toolbox-to-encodedecode-json-files-in-matlaboctave
%
% USAGE
@chris-taylor
chris-taylor / em.lhs
Last active December 14, 2015 05:48
eilenberg moore category (wip)
Given a class representing covariant functors between categories
> import Control.Category
> class (Category hom, Category hom') => Covariant f hom hom' where
> cmap :: hom a b -> hom' (f a) (f b)
and a class for adjunctions
> class (Covariant f hom hom', Covariant g hom' hom) => Adjunction f g hom hom' where
@chris-taylor
chris-taylor / adjunction.hs
Created February 18, 2013 14:22
Adjunctions in Haskell
{-# LANGUAGE NoImplicitPrelude
, MultiParamTypeClasses
, FlexibleInstances
, FunctionalDependencies
, UndecidableInstances #-}
import Prelude hiding (id, (.))
import qualified Prelude
@chris-taylor
chris-taylor / ADT.hs
Created February 10, 2013 23:01
Code to accompany my series on algebraic data types.
{-# LANGUAGE FlexibleContexts, UndecidableInstances, RankNTypes, ConstraintKinds #-}
module ADT where
------------
-- Part 1 --
------------
-- The unit type '1', equivalent to '()'