Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mortenpi's full-sized avatar

Morten Piibeleht mortenpi

View GitHub Profile
@mortenpi
mortenpi / moduletestset.jl
Created July 31, 2018 12:58
at-testset for modules
using Test
macro moduletestset(ex)
@assert ex.head === :module
modulename = string("module ", ex.args[2])
modulecontents = ex.args[3]
# Add `using Test` as the first expression in the module so that the user could
# use @test etc. without having to have `using Test` all over the place.
pushfirst!(modulecontents.args, :(using Test))
# Just having `using Test` as the very first element in does not work for some
@mortenpi
mortenpi / Markdown2.printmd2.jl
Created June 2, 2018 13:20
printmd2() functions to print Markdown2 trees in Documenter
# printmd2
const INDENT = ". "
printmd2(xs :: Markdown2.MD) = printmd2(xs.nodes)
function printmd2(xs :: Vector; indent=0)
for x in xs
printmd2(x; indent = indent)
end
end
function jsonescape(s)
s = replace(s, '\\' => "\\\\")
s = replace(s, '\n' => "\\n")
replace(s, '"' => "\\\"")
end
@static if VERSION < v"0.7.0-DEV.3734" # https://github.com/JuliaLang/julia/pull/25872
function iobuffer(sizehint)
b = IOBuffer(Base.StringVector(floor(Int, 1.2*sizehint)), true, true)
truncate(b, 0)
@mortenpi
mortenpi / documenter-api-updates.jl
Last active April 11, 2018 06:28
Some speculation about the future of Documenter's user-facing API.
# This would be make.jl.
#
# The user can then interact with this configuration through the
# command line:
#
# julia docs/make.jl doctest
# julia docs/make.jl build --html
# julia docs/make.jl deploy --latex --html
using Documenter, DocumenterLaTeX
@mortenpi
mortenpi / 0 Dropbox
Last active August 1, 2017 09:06
Setup for second Dropbox folder
.
@mortenpi
mortenpi / clean-urls.diff
Created May 25, 2017 11:32
search.html (v0.10.3) vs search/index.html (v0.11.0)
24c24
< "https://fonts.googleapis.com/css?family=Lato|Ubuntu+Mono" rel=
---
> "https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel=
30c30
< documenterBaseURL="."
---
> documenterBaseURL=".."
34,39c34,39
< data-main="assets/documenter.js"></script>
@mortenpi
mortenpi / documenter-world-counter.patch
Last active May 19, 2017 10:04
Work around the world counter issue in Documenter
diff --git a/src/Expanders.jl b/src/Expanders.jl
index 484622f..f7025f4 100644
--- a/src/Expanders.jl
+++ b/src/Expanders.jl
@@ -471,11 +471,7 @@ function Selectors.runner(::Type{ExampleBlocks}, x, page, doc)
# Splice the input and output into the document.
content = []
input = droplines(x.code)
-
- # Special-case support for displaying SVG graphics. TODO: make this more general.
@mortenpi
mortenpi / handle_segfault.c
Last active March 2, 2023 01:41
Recover gracefully from a segmentation fault (SIGSEGV) in C due to invalid pointer.
/*
Credits to:
- https://linux.die.net/man/2/setcontext
- https://stackoverflow.com/questions/8456085/why-cant-i-ignore-sigsegv-signal
*/
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <signal.h>
julia> Pkg.update()
INFO: Updating METADATA...
ERROR: METADATA cannot be updated. Resolve problems manually in /home/morten/Julia/pkg/v0.5/METADATA.
GitError(Code:ERROR, Class:Net, Failed to resolve address for https: Name or service not known)
 in macro expansion at ./libgit2/error.jl:99 [inlined]
 in #fetch#52(::Base.LibGit2.FetchOptions, ::String, ::Function, ::Base.LibGit2.GitRemote, ::Array{AbstractString,1}) at ./libgit2/remote.jl:70
 in (::Base.LibGit2.#kw##fetch)(::Array{Any,1}, ::Base.LibGit2.#fetch, ::Base.LibGit2.GitRemote, ::Array{AbstractString,1}) at ./<missing>:0
 in #fetch#93(::String, ::String, ::Array{AbstractString,1}, ::Nullable{Base.LibGit2.AbstractCredentials}, ::Function, ::Base.LibGit2.GitRepo) at ./libgit2/libgit2.jl:164
 in (::Base.Pkg.Entry.##35#41)(::Base.LibGit2.GitRepo) at ./pkg/entry.jl:371
@mortenpi
mortenpi / capture-streams.jl
Last active November 22, 2020 10:59
Example code to capture STDOUT and STDERR in Julia.
# A wrapper function to capture STDOUT and STDERR into strings.
#
# Heavily inspired by
# https://github.com/JuliaStats/RCall.jl/blob/c1ff136864964cf2ac04b679f0c1b3b243df7e37/src/iface.jl#L35-L46
# referred to by the issue comment
# https://github.com/JuliaLang/julia/issues/12711#issuecomment-133045787
#
# The Base.start_reading(stream, cb) requires fixes in Base.
#