Skip to content

Instantly share code, notes, and snippets.

@bakpakin
bakpakin / patch.diff
Created July 11, 2022 23:39
a remarkable patch
diff --git a/project.janet b/project.janet
index f1bd87c..90a6f6e 100644
--- a/project.janet
+++ b/project.janet
@@ -10,11 +10,11 @@
(declare-executable
:name "remark"
- :entry "src/remarkable.janet")
+ :entry "src/remarkable/init.janet")
@bakpakin
bakpakin / utf8.janet
Last active January 19, 2022 11:34
Use pegs to parse utf8
###
### utf8.janet
###
### Pure janet utf8 utils. You should probably just use C.
###
(defn utf8-encode
"Convert a sequence of codepoints to a string."
[x]
(def buf @"")
@bakpakin
bakpakin / evparallel.janet
Created August 27, 2021 13:53
Try (and fail) to repro thread issue.
(defn parallel
[jobs]
(print "Beginning " (length jobs) " jobs...")
(let [results-chan (ev/thread-chan 0)
res @{}]
(each job jobs
(ev/thread (fiber/new job) results-chan :n))
(while (< (length res) (length jobs))
(let [[k v] (ev/take results-chan)]
@bakpakin
bakpakin / dagbuild.janet
Created June 11, 2021 19:13
Parallel, make-like builds - work for adding parallel builds to jpm
###
### dagbuild.janet
###
### A module for building files / running commands in an order.
### Building blocks for a Make-like build system.
###
#
# DAG Execution
#
@bakpakin
bakpakin / *-by.janet
Last active March 4, 2021 03:52
group-by, partition-by in Janet
(defn group-by
``Group elements of `ind` by a function `f` and put the resutls into a table. The keys of
the table are the distinct return values of `f`, and the values are arrays of all elements `x` of `ind`
such that `(f x)` is equal to the key.``
[f ind]
(def ret @{})
(each x ind
(def y (f x))
(if-let [arr (get ret y)]
@bakpakin
bakpakin / main.janet
Last active December 7, 2020 02:09
Janet preloading
(import preloader)
# Files that a use may want to load
(def mod1 (require "mod1"))
(def mod2 (require "mod2"))
(defn main [& args]
(preloader/preload "@mod1" mod1)
(preloader/preload "@mod2" mod2)
(dofile "some-user-file.janet"))
ClJ1bm5pbmcgdGVzdCBzdWl0ZSAzIHRlc3RzLi4uCiAgChtbMzJt4pyUG1swbSAocmFuZ2UgMTAp
OiB0cnVlChtbMzJt4pyUG1swbSAocmFuZ2UgMSAxMCk6IHRydWUKG1szMm3inJQbWzBtIHppcGNv
bGw6IHRydWUKG1szMm3inJQbWzBtIGRlZi06IHRydWUKG1szMm3inJQbWzBtIG1hdGNoIDE6IHRy
dWUKG1szMm3inJQbWzBtIG1hdGNoIDI6IHRydWUKG1szMm3inJQbWzBtIG1hdGNoIDM6IHRydWUK
G1szMm3inJQbWzBtIHJlZ3Jlc3Npb24gMTogdHJ1ZQobWzMybeKclBtbMG0gc2Nhbi1udW1iZXIg
MTogdHJ1ZQobWzMybeKclBtbMG0gc2Nhbi1udW1iZXIgLTE6IHRydWUKG1szMm3inJQbWzBtIHNj
YW4tbnVtYmVyIDEuM2U0OiB0cnVlChtbMzJt4pyUG1swbSBpZi1ub3QgMTogdHJ1ZQobWzMybeKc
lBtbMG0gaWYtbm90IDI6IHRydWUKG1szMm3inJQbWzBtIGlmLW5vdCAzOiB0cnVlChtbMzJt4pyU
G1swbSBpZi1ub3QgNDogdHJ1ZQobWzMybeKclBtbMG0gdW5sZXNzOiB0cnVlChtbMzJt4pyUG1sw
bSBsb29wIDpwYWlyczogdHJ1ZQobWzMybeKclBtbMG0gYmFkIGFyaXR5IDE6IHRydWUKG1szMm3i
Running test suite 3 tests...
✔ (range 10): true
✔ (range 1 10): true
✔ zipcoll: true
✔ def-: true
✔ match 1: true
✔ match 2: true
✔ match 3: true
@bakpakin
bakpakin / client.janet
Created August 10, 2020 19:31
Broken pipe handling in server
(with [conn (net/connect "127.0.0.1" "8000")]
(printf "Connected to %q!" conn)
(:write conn "Echo...")
(print "Wrote to connection...")
(def res (:read conn 1024))
(print "client done")
(pp res))
@bakpakin
bakpakin / pkgbuild-janet-lang.patch
Created May 16, 2020 15:20
Fix pkgbuild skipping static libraries and adds /usr/lib/janet for jpm.
diff --git a/PKGBUILD b/PKGBUILD
index 479ef5e..fc24851 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -12,6 +12,7 @@ provides=('janet')
conflicts=('janet-lang-git')
source=("$pkgname-$pkgver.tar.gz::https://github.com/janet-lang/janet/archive/v${pkgver}.tar.gz")
sha256sums=('02724d6074a0d6fa53a548e8bdaaf49999f082e30b277c73444900f739a53062')
+options=('staticlibs')