Skip to content

Instantly share code, notes, and snippets.

@zyth0s
zyth0s / coffee_alarm.jl
Created August 3, 2020 01:05
Coffee alarm at the office.
using Dates: DateTime, issaturday, issunday, now, tonext, Hour, hour, Minute
isweekend(dt::DateTime) = issaturday(dt) || issunday(dt)
# Step from now on by 1 hour lapses until the next coffee time is found.
next_coffee_t = tonext(floor(now(),Hour), step=Hour(1)) do dt
!isweekend(dt) && # We do not work at the office on weekends.
(hour(dt) == 13 || # After lunch, or
hour(dt) == 17) # in the evening.
@zyth0s
zyth0s / julia_tricks.jl
Last active August 3, 2020 21:01
Julia tricks
# # One-liners
low, high = minmax(4,3)
low, high = extrema([1,3,5,7])
# double factorial
dfactorial(n::Int) = prod(n:-2:1)
# Non equivalent pairs
_pairs(n::Int) = ((i,j) for i in 1:n for j in 1:(i-1)) # upper triangle without diagonal
_pairs_wself(n::Int) = ((i,j) for i in 1:n for j in 1:i) # upper triangle with diagonal
@zyth0s
zyth0s / magic_run.jl
Last active August 9, 2020 19:30
Run Julia scripts from the interpreter with a macro (like an IPython magic command).
# Run Julia files from the REPL with the following syntax:
# > @run "../file.jl" <-- String (any rel/abs path) [si autocompletion]
# > @run file.jl <-- Expr (no ./ or ../ etc) [no autocompletion]
# > @run file <-- Symbol (no ./ or ../ etc) [no autocompletion]
macro run(filename)
if filename isa String
include(filename)
elseif filename isa Expr
include(join([string(filename.args[1]),
string(filename.args[2].value)],
@zyth0s
zyth0s / quickstart_example.cc
Created December 8, 2018 17:58
TIleDB backend to save/load Armadillo objects
/**
* @file quickstart_dense.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2018 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy