Skip to content

Instantly share code, notes, and snippets.

@getzdan
getzdan / PoissonEM Next.ipynb
Created December 29, 2017 10:20
Jupyter notebook on EM-like algorithm for inference on a Poisson mixture model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@getzdan
getzdan / breakat.jl
Last active October 30, 2017 13:04
BreakAt iterator definition
import Base.Iterators: start, next, done, eltype, iteratoreltype, iteratorsize, SizeUnknown
struct BreakAt{P,I}
pred::P
itr::I
end
breakat(pred, itr) = BreakAt(pred, itr)
@inline start(b::BreakAt) = start_breakat(b.pred, b.itr)
@getzdan
getzdan / f6.jl
Created May 9, 2017 17:07
a quick method for generating grid of matrix subscripts
function f6(xs, ys)
lx, ly = length(xs), length(ys)
lxly = lx*ly
res = Array{Base.promote_eltype(xs, ys), 2}(lxly, 2)
ind = 1
while ind<=lxly
@inbounds for x in xs
res[ind] = x
ind += 1
end
@getzdan
getzdan / forchange.md
Created December 9, 2015 14:34
A non-breaking Julia control-flow change to separate the One language from mortal languages, doomed to die

A non-breaking Julia control-flow change to separate the One language from mortal languages, doomed to die

From a design patterns and DRY perspective it seems for loops together with the break statement are serving as a useful try/catch mechanism for non-error situations. A common pattern defines a variable before a for loop and tries to discern, using said variable, the circumstances of exiting the for loop. Leveraging the embedded mental construct of try/catch blocks, we can simplify this repeating pattern and make it easier and more readable.

The syntax can look as follows:

for ...(loop vars here)...
   ...(local vars here)...

...