Skip to content

Instantly share code, notes, and snippets.

@hmenke
hmenke / type-imp-alegreya.mkiv
Created July 21, 2017 07:15
Alegreya typescript for ConTeXt MKIV
\starttypescriptcollection [alegreya]
\starttypescript [serif] [alegreya]
\setups[font:fallback:serif]
\definefontsynonym [Serif] [file:Alegreya-Regular.ttf] [features=default]
\definefontsynonym [SerifItalic] [file:Alegreya-Italic.ttf] [features=default]
\definefontsynonym [SerifSlanted] [file:Alegreya-Italic.ttf] [features=default]
\definefontsynonym [SerifBold] [file:Alegreya-Bold.ttf] [features=default]
\definefontsynonym [SerifBoldItalic] [file:Alegreya-BoldItalic.ttf] [features=default]
\definefontsynonym [SerifBoldSlanted] [file:Alegreya-BoldItalic.ttf] [features=default]
@hmenke
hmenke / .appveyor.yml
Created November 8, 2017 00:46
Boost.Test on AppVeyor
platform:
- x64
environment:
GENERATOR: "Visual Studio 14 2015 Win64"
CONFIG: Debug
BOOST_ROOT: "C:\\Libraries\\boost_1_59_0"
BOOST_LIBRARYDIR: "C:\\Libraries\\boost_1_59_0\\lib64-msvc-14.0"
PATH: "%BOOST_LIBRARYDIR%;%PATH%"
@hmenke
hmenke / siman.cpp
Created November 24, 2017 04:02
C++11 class interface for GSL simulated annealing
#include <functional>
#include <memory>
#include <gsl/gsl_siman.h>
namespace gsl {
template < typename State >
class Siman {
static double Ef(void *xp) {
@hmenke
hmenke / pdf-to-svg.lua
Last active February 18, 2023 13:33
Render an SVG image as PDF using librsvg2 and cairo.
local ffi = require"ffi"
ffi.cdef[[
// Cairo types
typedef struct _cairo_surface cairo_surface_t;
typedef int cairo_status_t;
typedef struct _cairo cairo_t;
// Poppler types
typedef struct _PopplerPage PopplerPage;
@hmenke
hmenke / R.lua
Last active October 19, 2022 07:29
Call other scripting languages from LuaJIT via FFI
local ffi = assert(require("ffi"))
local libR = assert(ffi.load("libR.so"))
local c_str = function(text)
local str = ffi.new("char[?]", #text + 1)
ffi.copy(str, text)
return str
end
ffi.cdef[[
@hmenke
hmenke / matheval.lua
Last active February 29, 2020 21:10
Simple mathematical expression parser and evaluator in Lua with LPEG
local lpeg = require"lpeg"
local C, P, R, S, V = lpeg.C, lpeg.P, lpeg.R, lpeg.S, lpeg.V
local white = S(" \t") ^ 0
local digit = R("09")
local dot = P(".")
local eE = S("eE")
local sign = S("+-")^-1
local mantissa = digit^1 * dot * digit^0 + dot * digit^1 + digit^1
@hmenke
hmenke / luacode.tex
Last active April 23, 2018 11:06
Absolutely minimal boilerplate for a luacode environment
\protected\def\startluacode
{\begingroup
\catcode`\^^M=12
\catcode`\%=12
\catcode`\#=12
\startluacodeindeed}
\def\startluacodeindeed#1\stopluacode
{\expanded{\noexpand\endgroup\directlua{#1}}}
@hmenke
hmenke / XeTeXemulate.sty
Last active January 28, 2023 01:42
Emulate XeTeX font primitives in LuaTeX
\ifcsname ProvidesPackage\endcsname
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{XeTeXemulate}[2018/09/03 v0.0 Emulate the XeTeX font primitives in LuaTeX]
\fi
\def\XeTeXemulate{%
\chardef\XeTeXversion=0
\def\XeTeXrevision{.99999}%
% Circumvent \outer error
\csname newcount\endcsname\XeTeXtracingfonts \XeTeXtracingfonts=0
@hmenke
hmenke / protrusion-quality.tex
Created September 10, 2018 02:07
Quality protrusion vectors in LuaTeX
\documentclass{article}
\usepackage{fontspec}
\usepackage{luacode}
\usepackage{xcolor}
\begin{luacode*}
local byte = string.byte
fonts.expansions.setups['quality'] = {
stretch = 2, shrink = 2, step = .5, factor = 1,
@hmenke
hmenke / json.lua
Last active December 19, 2018 21:37
Very simple JSON parser and serializer with LPEG
local lpeg = assert(require("lpeg"))
local C, Cf, Cg, Ct, P, R, S, V =
lpeg.C, lpeg.Cf, lpeg.Cg, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.V
-- number parsing
local digit = R"09"
local dot = P"."
local eE = S"eE"
local sign = S"+-"^-1
local mantissa = digit^1 * dot * digit^0 + dot * digit^1 + digit^1