Skip to content

Instantly share code, notes, and snippets.

@cossio
cossio / str-natural-sort.jl
Last active August 14, 2017 10:15
Sort strings in natural order (numbers are inside are treated by value).
# done by Sebastian Pfitzner
function naturalsort(x::Vector{String})
f = text -> all(isnumber, text) ? string(Char(parse(Int, text))) : text
sorter = key -> join(f(c) for c in matchall(r"[0-9]+|[^0-9]+", key))
sort(x, by=sorter)
end
# see https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/
@cossio
cossio / svg2tiff
Created November 21, 2017 17:20 — forked from matsen/svg2tiff
A script to convert SVG to a TIFF acceptable to PLOS
#!/bin/sh
# Convert all arguments (assumed SVG) to a TIFF acceptable to PLOS
# Requires Inkscape and ImageMagick 6.8 (doesn't work with 6.6.9)
for i in $@; do
BN=$(basename $i .svg)
inkscape --without-gui --export-png="$BN.png" --export-dpi 300 $i
convert -compress LZW -alpha remove $BN.png $BN.tiff
mogrify -alpha off $BN.tiff
@cossio
cossio / bash-colors.md
Created November 23, 2017 16:18 — forked from iamnewton/bash-colors.md
The entire table of ANSI color codes.

Regular Colors

Value Color
\e[0;30m Black
\e[0;31m Red
\e[0;32m Green
\e[0;33m Yellow
\e[0;34m Blue
\e[0;35m Purple
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
@cossio
cossio / show.jl
Created December 6, 2017 21:22
@show number array without losing digits
@show rand(3);
# out
# rand(3) = [0.867693, 0.141908, 0.0269334]
# doesn't show all digits.
show(IOContext(STDOUT, :compact=>false), rand(3));
# out
# [0.6212121566260771, 0.9149696195383878, 0.6989968224489542]
# shows all digits
@cossio
cossio / repos.jl
Last active January 5, 2018 19:51
List packages with their remotes, filtered to contain my name (serves to identify my own packages).
pkgdirs = filter(d -> isdir(d) && !startswith(basename(d), "."),
Pkg.dir.(readdir(Pkg.dir())));
for dir in pkgdirs
remote = first(split(readchomp(`git -C $dir remote -vv`), "\n"))
if contains(remote, "cossio")
println(remote)
end
end
@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
@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 / rsync.sh
Created December 21, 2017 17:50
rsync flags
rsync -avzP source destination
@cossio
cossio / post-commit.sh
Created December 21, 2017 21:40
git post-commit
#!/bin/sh
git push origin master