Skip to content

Instantly share code, notes, and snippets.

@aavogt
aavogt / string_vs_list.R
Created November 17, 2024 21:09
benchmarking ghc (`elem` "{([") vs. (\c -> c `elem` "{([") vs. ...
library(pacman)
p_load(tidyverse, tictoc, glue, e1071, directlabels, cache)
split <- function(x) unlist(strsplit(x, ""))
sample(c(letters, split("{}[]()")), 10^5, replace = TRUE) %>% as.list() %>% do.call(str_c, .) %>% writeLines("input0.txt")
# map_chr(commands, function(command) readLines(paste0(command, ".hs"))) %>% setNames(commands) %>% deparse %>% writeLines
mains <- c(
@aavogt
aavogt / VVariable.hs
Created November 11, 2024 18:13
ghc parser plugin to assign IORefs
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
module VVariable where
import Control.Monad
import Control.Monad.Trans.Writer
@aavogt
aavogt / warping.R
Created September 18, 2024 14:51
Wang 2006 equation plot
# https://link.springer.com/article/10.1007/s00170-006-0556-9
library(pacman)
p_load(tidyverse, directlabels)
delta <- function(dh,alpha,hdt,dt,L,H) {
n <- H / dh
te <- hdt - dt
tibble(n=n, te=te, delta = n^3 * dh / (6*alpha*dt*(n-1)) * (1 - cos(3*alpha*L/(n*dh) * dt * (n-1)/n^2 )))
}
@aavogt
aavogt / a.Rmd
Created September 16, 2024 01:55
fire tube
# Water Heater
For backpacking weight is an important constraint. Often boiling water is
enough for food and drink -- the food can be precooked and/or dehydrated etc.
such that it doesn't need to simmer. Therefore a stove and a pot could be
unnecessary, if a tube containing burning fuel is put inside a water bottle.
Methanol stoves where the pot has a shield ("caldera cone", jetboil etc.)
@aavogt
aavogt / valliers.jl
Last active August 15, 2024 14:35
values don't change
# Success[0.1, 0.1, 0.1, 0.1, 0.1, 0.09999999999999999, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.09999999999999999, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.09999999999999999, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]%
# The problem is probably the pressure tank composition equation.
# challenge Valliers 2004 sweep gas claim
# flanges are a,b,c,d etc.
# where "a" is upstream and "b" is downstream
#
##
using ModelingToolkit, Plots, DifferentialEquations
@aavogt
aavogt / Layout.hs
Created July 15, 2024 12:34
split rectangles
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeOperators #-}
module Layout where
import Raylib.Types
-- | Horizontal split
newtype H a = H a
@aavogt
aavogt / Gui.hs
Last active July 13, 2024 02:16
raylib essence-of-live-coding
{-# LANGUAGE Arrows #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeApplications #-}
-- ghcid -c 'ghci -isrc' src/Gui.hs -T'sync prog'
module Gui (module Gui) where
import LiveCoding
import Raylib.Util ( WindowResources, drawing )
import Control.Monad.IO.Class ( MonadIO(liftIO) )
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE LambdaCase #-}
import Control.Lens.Plated
import Control.Lens
import Language.Haskell.TH
import Control.Lens.Extras
import Debug.Trace
@aavogt
aavogt / LLine.py
Last active July 10, 2024 18:46
decorator version
def add_last_vertex(f):
"""Call a function with the newest vertex of the workplane as the first argument.
For example, add_last_vertex(Line)(p) is equivalent to Line((0,0), p),
if there was no last vertex, or if the last vertex was (0,0)
"""
def wrapped(*args, **kwargs):
context = Builder._get_context()
loclastpt = Vector()
try:
@aavogt
aavogt / hgcode.hs
Created May 15, 2024 14:11
use `rapid` to reload while keeping the h-raylib window open
{-# NOINLINE runLoop #-}
runLoop :: IORef Bool
runLoop = unsafePerformIO (newIORef True)
main = rapid 0 \ k -> do
HGCode{..} <- return $ HGCode { input = "CE5S1_hex_grid.gcode" &= typ "INPUT" &= argPos 0, output = def &= typ "OUTPUT" &= argPos 1 }
lines <- createRef k "lines" $ runResourceT $ runConduit $ sourceFile input
.| decodeUtf8C
.| parseGcodeC @Pico