Skip to content

Instantly share code, notes, and snippets.

@saikyun
saikyun / main.janet
Last active November 26, 2020 19:40
repling with jaylib
# build jaylib (or use it as a dependency if you can)
# run `janet main.janet`
# in another terminal, run `janet main.janet connect`
# then modify and eval the `(defn frame ...)` form
# then run `(set frame-f frame)`
(use ./build/jaylib)
(import spork/netrepl)
(var font nil)
;;; -*- lexical-binding: t -*-
(require 'company)
(with-eval-after-load "company"
;; everywhere
(global-company-mode)
;;
;;(global-set-key (kbd "<tab>") #'helm-company)
(global-set-key (kbd "M-TAB") #'company-complete)
@saikyun
saikyun / README.md
Last active January 11, 2021 03:27
Getting started with clojure / calva
@saikyun
saikyun / readme
Created June 12, 2020 12:13
calling c from clojure using graalvm
// tested using graalvm 20.2 dev
// https://github.com/graalvm/graalvm-ce-dev-builds/releases
// thanks u/duhace for https://www.reddit.com/r/java/comments/8s7sr8/interacting_with_c_using_graalvm/
main.c
====
#include <stdio.h>
void printHello() {
FILE *f = fopen("file.txt", "w");
@saikyun
saikyun / zig_watch.clj
Last active April 8, 2021 09:40
babashka command to watch a folder for changes to .zig-files
#!/usr/bin/env bb
(if *command-line-args*
(def in (str (first *command-line-args*)))
(do
(println "Which bin to run?")
(def in (str *input*))))
(println "Watching" "*.zig" "->" (str "./" in))
@saikyun
saikyun / let.cljc
Last active April 21, 2020 06:01
let with return and error handling operators
(ns miracle.let
(:refer-clojure :exclude [let])
(:require [clojure.walk :refer [postwalk]]
[clojure.test :as t :refer [is deftest]]))
(defn in-form
[form pred]
(clojure.core/let [vars (transient [])]
(postwalk (fn [f]
(when (pred f)
(ns miracle.thread
(:require [clojure.pprint :refer [pprint]]
[clojure.string :as str]
[clojure.walk :refer [postwalk]]))
(defn used-vars
[form]
(let [vars (transient [])]
(postwalk (fn [f]
(when (and (symbol? f)
@saikyun
saikyun / monad.clj
Created April 17, 2020 10:15
control flow macro v2
(ns miracle.monad
(:require [clojure.pprint :refer [pprint]]))
;; make clj-kondo happy
(def | ::err)
(defn left
[o]
{::left o})
@saikyun
saikyun / monad.clj
Last active April 17, 2020 09:23
control flow macro
(ns miracle.monad
(:require [clojure.pprint :refer [pprint]]))
;; make clj-kondo happy
(def | ::err)
(defn handle-form
[forms]
(if (empty? forms)
nil
@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>