Skip to content

Instantly share code, notes, and snippets.

@imh
imh / betaln.py
Created November 16, 2022 01:03
More stable evaluation of betaln than is currently in jax
from jax import lax
import jax.numpy as jnp
def algdiv(a, b):
"""
The algdiv function from scipy.
See https://github.com/scipy/scipy/blob/c89dfc2b90d993f2a8174e57e0cbc8fbe6f3ee19/scipy/special/cdflib/algdiv.f
and licence https://github.com/scipy/scipy/blob/c89dfc2b90d993f2a8174e57e0cbc8fbe6f3ee19/LICENSE.txt
def prefix_in(prefs, id):
return any(map(lambda x: str(id).startswith(str(x)), prefs))
def check_range(x,y, id):
l = len(str(x))
trunc_id = str(id)[:l]
return str(x) <= trunc_id and trunc_id <= str(y)
def prefix_in_ranges(pref_ranges, id):
return any(map(lambda (x,y): check_range(x, y, id), pref_ranges))
def mk_tuple(r):
import numpy as np
def charlookup(num_chars):
if num_chars <= 0:
return ' '
if num_chars <= 1:
return '.'
if num_chars <= 2:
return ':'
# if num_chars <= 3:
# bash/zsh git prompt support
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Distributed under the GNU General Public License, version 2.0.
#
# This script allows you to see repository status in your prompt.
#
# To enable:
#
# 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
@imh
imh / .bashrc
Last active August 29, 2015 13:57
export PATH=/Users/imh/.cabal/bin:$PATH
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/share/python:$PATH
export PYTHONPATH=/usr/local/lib/python:$PYTHONPATH
export ANDROID_HOME=/Users/imh/software/android/adt-bundle-mac-x86_64-20131030/sdk
export PATH=/Users/imh/software/android/adt-bundle-mac-x86_64-20131030/sdk/platform-tools:$PATH
@imh
imh / setup.sh
Last active August 29, 2015 13:57
first time setup of a debian based machine
apt-get install curl
apt-get install git
apt-get install vim
apt-get install haskell-platform
apt-get install gfortran gfortran-doc
apt-get install libblas libblas-dev libblas-doc
apt-get install liblapack liblapack-dev liblapack-doc
apt-get install python-virtualenv
apt-get install python-dev
@imh
imh / endo.hs
Last active August 29, 2015 13:57
function arithmetic feels weird
{-# OPTIONS_GHC -Wall #-}
module Main where
import Control.Applicative
instance Num b => Num (a -> b) where
(+) = liftA2 (+)
(*) = liftA2 (*)
abs = liftA abs
@imh
imh / gist:2940082
Created June 16, 2012 05:32
vertical calendar
#!/usr/bin/env ruby
require 'Date'
ABBR_DAYNAMES = {0, 'Su', 1, 'Mo', 2, 'Tu', 3, 'We', 4, 'Th', 5, 'Fr', 6, 'Sa'}
ABBR_MONAMES = {1, 'Jan', 2, 'Feb', 3, 'Mar', 4, 'Apr', 5, 'May', 6, 'Jun', 7, 'Jul', 8, 'Aug', 9, 'Sep', 10, 'Oct', 11, 'Nov', 12, 'Dec'}
def days_in_month(year, month)
if month < 13 then
if month > 0 then
return (Date.new(year, 12, 31) << (12 - month)).day
else