Skip to content

Instantly share code, notes, and snippets.

@saikyun
saikyun / copy-on-write-tuple.janet
Last active February 28, 2023 21:35
Copy on write tuples for janet
(defn push
[l v]
[;l v])
(defn pop
[l]
(if (empty? l)
l
(tuple/slice l 0 -2)))
@saikyun
saikyun / repl.c
Last active January 12, 2023 08:54
// needs clang
// probably only macos
// usage:
// clang main.c && ./a.out
// try entering `5 * 5`, or `printf("hello\n")`
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
@saikyun
saikyun / compile-and-run
Last active December 30, 2022 15:00
example of how to automatically reload dylibs when they change
#!/bin/zsh
# exit when a command fails
set -e
mkdir -p bin
cc -dynamiclib lib.c -o ./bin/lib.dylib
cc reload_dylibs.c -o bin/main && ./bin/main
@saikyun
saikyun / loc-since-day.janet
Last active April 11, 2022 11:56
Functions for seeing changes to lines of code since a given day.
(defn git-log-stat-since
[&opt date]
(let [d (os/date)
date (or date
(string/format "%i-%02i-%02i" (d :year)
(inc (d :month)) # 0-indexed
(inc (d :month-day)) # 0-indexed
))
p (os/spawn ["git" "log" "--stat" (string `--since="` date ` 00:00"`)]
:p
@saikyun
saikyun / angles.janet
Created April 7, 2022 07:45
Sector overlap / collision in freja with visualization.
(use freja/flow)
(defn tau->deg
[t]
(math/round (* 180 t)))
(defn rad->tau
[r]
(/ r math/pi))
@saikyun
saikyun / steps.md
Created February 19, 2022 11:48
running jpm build from powershell
  1. install needed stuff
  2. in powershell:
notepad $PROFILE

Copy paste the below, change the path to match your own vcvars64.bat location:

function jpm-build {
 &amp; cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" &amp; jpm build'
# doesn't work
(setdyn :dynamic-defs true)
(defn main
[& args]
(print "hello"))
# doesn't work
(setdyn :dynamic-defs true)
(defn import-c*
[module-name src]
(def so-name (string module-name "-" (hash src) ".so"))
(unless (os/stat so-name)
(spit (string module-name ".c") src)
(os/execute ["cc"
"-I" "/usr/local/include/janet"
"-shared"
(def code
``
(+ 1 2
(+ 3 4))
``)
(def token-peg
~{:tuple-start (/ (* ($) "(" ($)) ,(fn [start stop] [:tuple-start "(" start stop]))
:tuple-stop (/ (* ($) ")" ($)) ,(fn [start stop] [:tuple-stop ")" start stop]))
:symbol (/ (* ($) '(some (if-not :d (if-not :s 1))) ($))
(+ 1 (* 2 3 4
#
))
(import freja/new_gap_buffer :as gb)
(import freja/state)
# will contain the parsers for each line
(def cache @[])