Skip to content

Instantly share code, notes, and snippets.

View lambdageek's full-sized avatar
🦀

Aleksey Kliger (λgeek) lambdageek

🦀
View GitHub Profile
//! A server with some middleware
//!
//! We have some server process [`server`]
//! that produces byte slices `&[u8]` and feeds them to some
//! [`ServerResponder`] client. Since the client gets the
//! bytes by reference and it must be prepared to receive them
//! for any lifetime, it's effectively a `for<'a> Fn(&'a [u8])` callback.
//!
//! Now to make things more interesting, we also want to have some middleware
//! that transforms the initial vector slice into something.
@lambdageek
lambdageek / net8-wasm-logging.md
Last active October 13, 2023 14:00
.NET 8 Additional WebAssembly logging

In .NET 8, Blazor projects now have a way to pass additional configuration options to the runtime, including setting environment variables before Mono starts.

The way to do it depends on whether you're using a blazorwasm template, or the new blazor (unified Server/Client project)

Blazor WebAssembly

If you created a blazorwasm project from the default template, in wwwroot/index.html replace this:

@lambdageek
lambdageek / aleksey_activate_dotnet.zsh
Last active June 30, 2023 14:43
A zsh script to activate/deactivate a dotnet SDK directory
# To install source this file from your .zshrc file
# Initialize colors.
autoload -U colors
colors
# Allow for functions in the prompt.
setopt PROMPT_SUBST
# Use in a PROMPT variable. For example (together with zsh-git-prompt):
typedef struct _MonoDelegateCodeCache
{
gpointer method_ptr;
gpointer invoke_impl;
} MonoDelegateCodeCache;
typedef struct _MonoDelegate {
...
MonoDelegateCodeCache *cache; // initially NULL
@lambdageek
lambdageek / Array-In-InferRule.md
Last active February 27, 2023 17:33
LaTeX array within inferrule from mathpartir

Sometimes I want to put an array inside of a mathpartir inferrule.

The straightforward thing doesn't work:

\begin{equation*}
\inferrule{Conclusion}{
  Premiss 1 \and
  \begin{array}{ll}
 1 &amp; 2 \\ % note, this is where the problem happens
@lambdageek
lambdageek / GistML.hs
Created November 15, 2014 16:47
The gist of ML modules
{-#
LANGUAGE
DeriveGeneric, DeriveDataTypeable,
MultiParamTypeClasses,
ViewPatterns
#-}
-- A short example of an ML-style module system atop a core lambda calculus.
--
-- The core expression language has variables, applications and
-- lambdas and constants. The type language has variables (of the single kind *)
@lambdageek
lambdageek / nanboxing.ts
Created May 12, 2022 13:46
Fun with NaN boxing
/// We pack 64-bit integers into the 64 bytes of a double
type PackedInt64 = number;
const doubleView = new Float64Array(1);
const int32View = new Int32Array(doubleView.buffer);
export function pack(lo: number, hi: number): PackedInt64 {
int32View[0] = lo;
int32View[1] = hi;
return doubleView[0];
@lambdageek
lambdageek / vscode
Created May 4, 2019 00:11
Visual Studio Code script for Cygwin
#! /usr/bin/env bash
if [ "z$1" == "z--help" ]; then
echo "vscode [FILE]"
echo " Starts Visual Studio Code for Windows"
echo " If FILE is given (as a unix path) it will be opened."
exit;
fi
winpath="C:\\Program Files\\Microsoft VS Code\\Code.exe"
@lambdageek
lambdageek / ak-msbuildify-compilation.el
Created March 8, 2022 17:23
Make Emacs understand MSBuild Exec task compilation output
(defun ak-msbuildify-regexp-str (s)
(replace-regexp-in-string "\\^" "^ \\\\{0,2\\\\}" s))
(defun ak-msbuildify-alist-alist (xss-orig)
(let* ((xss (copy-alist xss-orig))
(l xss))
(while (consp l)
;; l is (('symbol REGEXP ...) ...)
(let* ((x (copy-sequence (car l))) ;; unshare with the original alist
(r (cdr x)))
@lambdageek
lambdageek / dotnet-emscripten-env.sh
Last active November 15, 2021 18:07
Environment for .NET 6 bundled Emscripten
#! /bin/sh
# Source this with `. dotnet-emscripten-env.sh` to set up the paths to use `emcc` from the version of Emscripten bundled with .NET 6
dotnet_packs_dir=/usr/local/share/dotnet/packs
dotnet_emscripten_prefix=Microsoft.NET.Runtime.Emscripten.2.0.23
dotnet_rid=osx-x64
dotnet_ver=6.0.0