Skip to content

Instantly share code, notes, and snippets.

View mpizenberg's full-sized avatar

Matthieu Pizenberg mpizenberg

View GitHub Profile
@mpizenberg
mpizenberg / code-block-example.typ
Created April 3, 2023 07:28
Example for code blocks in Typst
#set par(justify: true)
*Goal*: being able to add line numbers, which are correct even in case of long lines that need wrapping.
*Strategy*: duplicate the code block, once for getting the line numbers correct, and the other for syntax highlighting. The idea is to split lines and prefix each line with its line number such that line wrapping should be respected.
#show raw.where(block: true): it => { set par(justify: false); grid(
columns: (100%, 100%),
column-gutter: -100%,
block(width: 100%, inset: 1em, for i, line in it.text.split("\n") {
@mpizenberg
mpizenberg / cached.m
Last active January 20, 2017 15:46
Transform a matlab function into a cached function (result stored in a file).
function varargout = cached(cache_filepath, f, varargin )
if exist(cache_filepath, 'file') == 2
load(cache_filepath, 'varargout');
else
[varargout{1:nargout}] = f( varargin{:} );
save(cache_filepath, 'varargout');
end
end
type Msg = Debounce VirtualTime | ...
-- create a deferred (by timeout) command taking currentVirtualTime as an argument
checkIfNothingHappenedIn : Time -> VirtualTime -> Cmd Msg
checkIfNothingHappenedIn timeout currentVirtualTime =
deferredCmd timeout (Debounce currentVirtualTime)
deferredCmd : Time -> Msg -> Cmd Msg
isItLongEnoughCmd : Cmd Msg
isItLongEnoughCmd = Task.perform IsItLongEnough Time.now
type alias Model = { ... , state : Debounce.State }
@mpizenberg
mpizenberg / medium_lodash_debounce.js
Last active December 7, 2016 09:14
Medium Debounce
// Avoid costly calculations while the window size is in flux.
jQuery(window).on(‘resize’, _.debounce(calculateLayout, 150));