Skip to content

Instantly share code, notes, and snippets.

@aavogt
aavogt / main.hs
Created March 15, 2024 18:33
c pointer/struct syntax for haskell wip
{-# LANGUAGE ViewPatterns, ApplicativeDo #-}
module Main (main) where
import Text.Regex.Applicative
import Data.List
import Control.Monad
import System.Exit
import System.Environment
import Data.Maybe
import Data.Char
import Data.IntMap (IntMap)
@aavogt
aavogt / Ribbon3.py
Last active March 13, 2024 18:05
cadquery 3d strip
import cadquery as cq
from copy import copy
class Ribbon3:
""" A ribbon is a way to make a sequence of Workplane.box
end-to-end without repeating dimensions.
I like the offset2D approach:
cq.Workplane().hLine(5).vLine(6).offset2D(2).extrude(3)
@aavogt
aavogt / active_learning.Rmd
Created January 12, 2024 16:18
EPM contour algorithm racing
# empirical performance model (EPM) contour active learning
I have two or three different algorithms for finding the closest pair of points between two point sets.
I want to know which one is faster, depending on the size of the point sets and the distance between them.
There are several parts to this project:
- [ ] level set method for contour curvature and normal vector / directional derivative of the EPM
- [ ] debug the distance transform and
- [ ] caret::knn.reg if it exists?
- [ ] shape constrained splines (SCAM) instead of mgcv::gam?
@aavogt
aavogt / fem.py
Created January 4, 2024 19:39
freecad macro autoload and geometry optimization
# Purpose: optimize the thicknesses of the shell to minimize the maximum stress
# The geometry of a shell is set by 12 parameters in the spreadsheet ts.
# Here we directly search for the 12 parameters that minimize the maximum stress,
# subject to the constraint that the volume is 8000 mm^3.
#
# TODO
# - package as a macro/workbench with buttons
# - 1D option?
# - Z88OS which has "real beam and shell elements" but it's not really possible https://github.com/FreeCAD/FreeCAD/issues/8559
# - maximum is not a good objective. Perhaps the goal is to have each segment
library(glue)
library(stringr)
require(rlang)
require(rextendr)
# drop-in replacement for rextendr::rust_source
# use a build directory in the current working directory
# if the source file is lib.rs the build is in lib_build
# code= needed for https://github.com/extendr/rextendr/issues/234
rust_source <- function(file, code= paste0(readLines(file), collapse="\n"), features="ndarray", ...) {
# https://github.com/extendr/rextendr/issues/291
@aavogt
aavogt / shiny_speculative.R
Last active June 17, 2023 13:33
speculative evaluation for R shiny
# I have a shiny app to display points calculated from an image <https://tinypic.host/i/oe0W7x>.
# There is some lag when I pick a new word (by changing number 7 in the picture) that I would like to get rid of.
# I plan to go through these plots in order, so while I'm looking at or clicking on number 7, number 8's plot
# or points could be calculated. This sort of gets it done: it takes 1s to calculate the points when jumping
# to a plot that isn't in order. But rendering the plot still takes longer than it should. Ideally
# the plot could be prerendered and then the image is just displayed. But that would leave me without input$plot_click
library(pacman)
p_load(tidyverse, ggplot2, jsonlite,
shiny, keys, magick, promises, future, memoise, tictoc)
plan(multisession)
@aavogt
aavogt / main.hs
Created March 15, 2023 20:59
streaming-osm with binary and zstd cache
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
@aavogt
aavogt / main.hs
Last active March 8, 2023 17:02
gi-gtk and hint threads
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
module Main (main) where
import qualified GI.Gdk as Gdk
import qualified GI.Gtk as Gtk
import Reactive.Banana.Frameworks
import Data.GI.Base (on)
import Language.Haskell.Interpreter as Hint
@aavogt
aavogt / zipper.rs
Last active February 21, 2023 02:31
struct Zipper<'a, T> {
up : Vec<&'a mut T>,
focus : &'a mut T,
down : Vec<&'a mut T>,
}
impl<'a, T> Zipper<'a, T> {
fn focus_n(&'a mut self, n: i32) -> Option<&mut Self> {
let mut x = self.focus_top()?;
// n focus downs from the top
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
type family Remove v xs where
Remove x (x ': xs) = Remove x xs
Remove x (y ': xs) = y ': Remove x xs
Remove x '[] = '[]