Skip to content

Instantly share code, notes, and snippets.

View tehrengruber's full-sized avatar

Till Ehrengruber tehrengruber

  • ETH Zuerich
  • Zürich
View GitHub Profile
@tehrengruber
tehrengruber / subtitle_shift.jl
Last active August 29, 2015 14:26
open a subtitle file (typically srt format) from src, shift the time by Δt and write it to dest
# open a subtitle file (typically srt format) from src, shift the time by Δt and write it to dest
Δt = Dates.Second(0)
src = ""
dest = ""
subs = readall(src);
new_subs = replace(subs, r"(\d+):(\d+):(\d+),(\d+)",
(match) -> begin
time_point = DateTime(match, "H:M:S,s")-Δt
@sprintf "%02d:%02d:%02d,%03d" Dates.hour(time_point) Dates.minute(time_point) Dates.second(time_point) Dates.millisecond(time_point)
@tehrengruber
tehrengruber / Convert.hpp
Last active August 29, 2015 14:27
Dune <-> Eigen Matrix, Vector Converter
#include <type_traits>
#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
#include <Eigen/Dense>
namespace NPDE15 {
template <class T1, class T2, class Enable = void>
struct Convert{};
/*
@tehrengruber
tehrengruber / split.jl
Created September 11, 2015 15:15
split array into equal parts
A=rand(20)
[A[ceil(step*i)+1:floor(step*(i+1)-0.1)+1] for i=0:parts-1, step=length(A)/parts]
julia> c=b.args[2]^C
julia> c = Condition()
@Condition(Any[])
julia> @as^C
julia> @async begin
wait(c)
println("im notifyed")

Keybase proof

I hereby claim:

  • I am tehrengruber on github.
  • I am tehrengruber (https://keybase.io/tehrengruber) on keybase.
  • I have a public key whose fingerprint is 675A 2D63 6334 66F9 E5E6 BDD1 D07E 4BB3 AF4C 76E3

To claim this, I am signing this object:

@tehrengruber
tehrengruber / void_cb.cpp
Created March 22, 2017 20:09
Optional callback in C++
/**
* Functor behaving like an unset function pointer (nullptr) with
* arbitrary number of arguments.
*
* Usage:
* ```
* #include "Utils/void_cb.hpp"
*
* template <typename CB=void_cb>
* void f(CB callback=nullptr) {
# given some code
code = """
for(int i=0; i<10; ++i) {
a=2
}
"""
# turn code into an array of tokens
# write a function tokenize(code) using https://www.lysator.liu.se/c/ANSI-C-grammar-y.html
# and https://github.com/iamed2/PyLexYacc.jl that allows you to do this
immutable Bla{A}
end
a() = Bla{3*2}
@code_warntype a()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tehrengruber
tehrengruber / field_descriptor.cpp
Created May 5, 2021 21:09
ghex non-type template argument problem for py bindings
template<typename T, typename Arch, typename DomainDescriptor, typename Order>
void export(py::class_<gridtools::ghex::structured::regular::field_descriptor<T, Arch, DomainDescriptor, Order>>> cls) {
// add bindings to cls
// ...
}
using orders = gridtools::meta::list<int_tuple_constant<0, 1, 2>, int_tuple_constant<2, 1, 0>>;
GHEX_PYBIND11_EXPORT_TYPE(gridtools::ghex::structured::regular::field_descriptor,
ghex4py::type_list::architecture_types,