Instantly share code, notes, and snippets.

# Morten Piibelehtmortenpi

• Sort options
Last active Feb 18, 2020
Example code to capture STDOUT and STDERR in Julia.
View capture-streams.jl
 # 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. #
Created Mar 17, 2014
Previous / current / next iterator in Python
View pcniter.py
 def previous_current_next(iterable): """Make an iterator that yields an (previous, current, next) tuple per element. Returns None if the value does not make sense (i.e. previous before first and next after last). """ iterable=iter(iterable) prv = None cur = iterable.next() try:
Last active Feb 7, 2020
Recover gracefully from a segmentation fault (SIGSEGV) in C due to invalid pointer.
View handle_segfault.c
 /* Credits to: - https://linux.die.net/man/2/setcontext - https://stackoverflow.com/questions/8456085/why-cant-i-ignore-sigsegv-signal */ #include #include #include #include
Created Aug 28, 2015
Function to create a vector of evenly spaced numbers in C++.
View range.cc
 // Create a vector of evenly spaced numbers. vector range(double min, double max, size_t N) { vector range; double delta = (max-min)/double(N-1); for(int i=0; i
Last active Nov 26, 2019
View .gitignore
 *.css
Last active Jun 12, 2019
View katex-bug.html
 KaTeX rendering bug example
Created Jun 4, 2019
Function to partition a set according to a predicate.
View partition.jl
 """ partition(f, xs) Partitions a collection according to a predicate f. Similar to filter, but returns the both the elements for which f is true and for which it is false, in two different collections. Returns a tuple of vectors, where the first vector contains the elements for which f is true and the second the elements for which f is false. """
Last active May 30, 2019
A short program to watch changes in Sass files and recompile them automatically
View sasscwatcher.jl
 # Copyright 2019 Morten Piibeleht # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons # to whom the Software is furnished to do so, subject to the following conditions: # #The above copyright notice and this permission notice shall be included in all copies or #substantial portions of the Software.
Created Feb 18, 2019
Documenter.jl with Fortran highlighting
View documenter.js
 /* * Part of Documenter.jl * https://github.com/JuliaDocs/Documenter.jl * * License: MIT * * Should be dropped into docs/src/assets/ and it will replace Documenter's own documenter.js. * * Assumes Documenter 0.21.4 -- make sure that Documenter is pinned to that version, just in case. * Changes to Documenter in future versions may break this.
Created Sep 24, 2018
View Manifest.toml
 [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" [[BinaryProvider]] deps = ["Libdl", "Pkg", "SHA", "Test"] git-tree-sha1 = "48c147e63431adbcee69bc40b04c3f0fec0a4982" uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" version = "0.5.0" [[CSV]]
You can’t perform that action at this time.