Skip to content

Instantly share code, notes, and snippets.

@jjh42
jjh42 / tf_infer_type_and_shape_from_numpy.py
Created April 20, 2020 23:28
Recipe for converting some nested numpy (or similar structure) to tensorflow types.
example_tf = tf.nest.map_structure(
tf.nest.map_structure(tf.convert_to_tensor, example))
output_types = tf.nest.map_structure(lambda t: t.dtype, tf_example)
output_shapes = tf.nest.map_structure(tf.nest.map_structure(
lambda t: t.shape.as_list(), tf_example))
@jjh42
jjh42 / Gamma Code.ipynb
Created February 9, 2020 22:55
Julia implementation and tests for Elias Gamma Coding
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jjh42
jjh42 / viterbi.jl
Created September 8, 2014 02:48
Viterbi decoder in Julia
typealias State Uint
typealias Observation Uint
function decode(x::Vector{Observation}, transition_matrix::Matrix{Float64},
observation_matrix::Matrix{Float64})
n_observations::Uint = uint(length(x))
n_states::Uint = uint(size(transition_matrix)[1])
@assert(size(transition_matrix) == size(transpose(transition_matrix)))
@jjh42
jjh42 / gist:5779722
Created June 14, 2013 05:46
Idea for mock syntax
defmodule MyTest do
use ExUnit.Case
import Mock
test_with_mock "test_name", HTTPotion,
do
new(buck, key, value, _), do: Object[key: {buck, key}, value: value]
get_update_metadata(Object[indexes: indexes]), do: indexes
end
@jjh42
jjh42 / gist:5737777
Created June 9, 2013 05:38
Mix job for putting Elixir docs in github pages.
defmodule Mix.Tasks.Docs.Ghpages do
use Mix.Task
@moduledoc """
A task for uploading documentation to gh-pages.
"""
defp run!(command) do
if Mix.shell.cmd(command) != 0 do
raise Mix.Error, message: "command `#{command}` failed"
@jjh42
jjh42 / gist:5710555
Created June 4, 2013 23:41
Python metaclass to make a class hash consistent across runtimes.
class _HashableType(type):
""""A metaclass which implements a hash based on the module
and class name (so that it is constants across runs
instead of the default which is the memory location of
the class definition.
Use it by changing the metaclass e.g.
class ConstantHash(object):
__metaclass__ = _HashableType
@jjh42
jjh42 / .travis.yml
Last active December 17, 2015 20:29
The simplest example of a .travis.yml for testing using Elixir/mix
language: erlang
otp_release:
- R16B
before_install:
- git clone https://github.com/elixir-lang/elixir
- cd elixir && git checkout v$(cat ../.exenv-version) && make && cd ..
before_script: "export PATH=`pwd`/elixir/bin:$PATH"
script: "MIX_ENV=test mix do deps.get, test"
@jjh42
jjh42 / gist:5529718
Created May 7, 2013 01:46
pyximport when you need numpy.
import pyximport
pyximport.install(setup_args={'include_dirs': [np.get_include()]})
Testing idea
@jjh42
jjh42 / Questions
Created June 21, 2011 01:46
Kiwi Pycon Give-away
GitHub username: jjh42
Day job: PhD student at the Queensland Brain Institute.
Favorite open source project: Well, python would be sucking up. How about VLC, gets me out a codec pickle everytime.
Open Source contributions (if any): extremely minor fixes to Sagemath
Stranded on an island, what 3 items do you take: Book: Idiot's guide to boat building, my leatherman, peanut butter.
Tie-breaker, pick a number between 1 and 20,000: 42