Skip to content

Instantly share code, notes, and snippets.

@cossio
cossio / fibonacci_fast_doubling.jl
Created July 23, 2018 14:14
Fast doubling algorithm to compute Fibonacci numbers. This is faster than matrix exponentiation.
function fib(n::Integer)
@assert n ≥ 0
if iszero(n)
return zero(n)
elseif n == 1 || n == 2
return one(n)
end
k = div(n,2)
if iseven(n)
return fib(k) * (2fib(k+1) - fib(k))
@cossio
cossio / ZeroTensor.jl
Created July 11, 2018 11:38
A tensor of zeros (Julia)
"A tensor of zeros"
struct ZeroTensor{T <: Number, N} <: AbstractArray{T,N}
dims::NTuple{N,Int}
function ZeroTensor{T,N}(dims::Vararg{Integer,N}) where {T <: Number, N}
all(dims .≥ 0) || error("invalid ZeroTensor dimensions")
new(dims)
end
end
ZeroTensor(T::DataType, dims::Vararg{Integer,N}) where N = ZeroTensor{T,N}(dims...)
ZeroTensor(dims::Vararg{Integer,N}) where {N} = ZeroTensor{Float64,N}(dims...)
@cossio
cossio / pdftoimg.sh
Created April 4, 2018 14:20
Scanned PDF to image
pdfimages -j input.pdf output
@cossio
cossio / edit-vim.jl
Created January 9, 2018 21:41
Use VIM as default editor in Julia. Raw
ENV["JULIA_EDITOR"] = "vim -R"
@cossio
cossio / git-alldirs.sh
Created January 8, 2018 15:56
I keep this script around which lets me apply a git command to every subdirectory:
#!/usr/bin/env zsh
submodules=("${(@f)$(find . -type d -depth 1)}")
for submodule in $submodules
do
print "=== $submodule"
git --work-tree=$submodule --git-dir=$submodule/.git $*
print
done
@cossio
cossio / myPkgs.jl
Created January 3, 2018 14:03
Install my Julia packages.
Pkg.clone("https://github.com/cossio/Utils.jl")
Pkg.clone("https://github.com/cossio/COBRAUtils.jl")
Pkg.clone("https://github.com/cossio/TruncatedNormal.jl")
@cossio
cossio / post-commit.sh
Created December 21, 2017 21:40
git post-commit
#!/bin/sh
git push origin master
@cossio
cossio / rsync.sh
Created December 21, 2017 17:50
rsync flags
rsync -avzP source destination
@cossio
cossio / InsertDate.gs
Created December 15, 2017 16:37 — forked from thomxc/InsertDate.gs
Google Docs Script Macro: Insert Date
/**
* The onOpen function runs automatically when the Google Docs document is
* opened. Use it to add custom menus to Google Docs that allow the user to run
* custom scripts. For more information, please consult the following two
* resources.
*
* Extending Google Docs developer guide:
* https://developers.google.com/apps-script/guides/docs
*
* Document service reference documentation:
@cossio
cossio / pdf2eps.sh
Created December 14, 2017 20:36
Shell script to convert PDF to encapsulated PostScript.
#!/bin/sh
# $Id: pdf2eps,v 0.01 2005/10/28 00:55:46 Herbert Voss Exp $
# Convert PDF to encapsulated PostScript.
# usage:
# pdf2eps <page number> <pdf file without ext>
pdfcrop $2.pdf
pdftops -f $1 -l $1 -eps "$2-crop.pdf"
rm "$2-crop.pdf"
mv "$2-crop.eps" $2.eps