Skip to content

Instantly share code, notes, and snippets.

@zyth0s
zyth0s / coffee_alarm.jl
Created Aug 3, 2020
Coffee alarm at the office.
View coffee_alarm.jl
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.
View julia_tricks.jl
# # 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 Aug 9, 2020
Run Julia scripts from the interpreter with a macro (like an IPython magic command).
View magic_run.jl
# 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 Dec 8, 2018
TIleDB backend to save/load Armadillo objects
View quickstart_example.cc
/**
* @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