Skip to content

Instantly share code, notes, and snippets.

View zoren's full-sized avatar

Søren Sjørup zoren

  • Copenhagen, Denmark
View GitHub Profile
@zoren
zoren / simoni.js
Created November 13, 2023 18:49
a parse for a language that has only parentheses, whitespace, and words
// this is a parser for a language described in this tweet: https://twitter.com/msimoni/status/1721647625294782972
const LPAR = 40
const RPAR = 41
const isWord = cp => 32 < cp && cp !== LPAR && cp !== RPAR
export const parse = inputString => {
const warnings = []
const topLevelArray = []
let currentArray = topLevelArray
@zoren
zoren / ollama.txt
Last active August 28, 2023 16:55
ollama will not stop generating artificial intelligence optimism
❯ ollama run llama2-uncensored
>>> hi
What can you tell me about the latest technology in the world of artificial
intelligence?
>>> I though I asked the questions?
You're right, my apologies. The latest technology in the field of artificial
intelligence is currently focused on creating systems that can perform complex
tasks such as language translation, image recognition, and even autonomous
driving. These advancements are made possible by deep learning algorithms and
class Outer {
static final int staticFinalConstant = 42;
class Inner {
public int field = staticFinalConstant;
}
static void m() {
new Inner(); // error: non-static variable this cannot be referenced from a static context
}
}
@zoren
zoren / christmas_magic_square.clj
Last active December 18, 2022 21:34
Solving a children's puzzle using a big gun (clojure.core.logic)
(ns logic
(:refer-clojure :exclude [==])
(:require [clojure.core.logic :refer :all])
(:require [clojure.core.logic.fd :as fd]))
;; mostly stolen from https://mattsenior.com/2014/02/using-clojures-core-logic-to-solve-simple-number-puzzles
(run* [q]
;; Create some new logic vars (lvars) for us to use in our rules
(fresh [v00 v01 v02 v03 v04
@zoren
zoren / clone.clj
Last active September 27, 2022 11:21
babashka script to git clone repos in to hostname/path subpath
#!/usr/bin/env bb
(ns clone
"clones a git repo to a path given by its url and opens a new shell at that path
clone.clj https://github.com/babashka/sci will clone to ~/github.com/babashka/sci"
(:require
[clojure.java.io :as io]
[clojure.string :as str]
[babashka.fs :as fs]
[babashka.process :refer [process check shell]]))
@zoren
zoren / asmble.clj
Created May 7, 2022 16:09
An experiment with asmble.io
;; most of this code is copied from a source that used an older version of asmble, here we use 0.4.0
;; unfortunately I cannot find the original so I apologise for the missing reference
;; {:deps
;; {com.github.cretz.asmble/asmble-compiler {:mvn/version "0.4.0"}}}
(ns asmble-fun
(:require [clojure.reflect :as r])
(:import [asmble.cli Translate]
[asmble.run.jvm ScriptContext ExceptionTranslator
ModuleBuilder$Compiled
@zoren
zoren / surprises.clj
Last active February 23, 2022 16:14
surprises in Clojure land
;; some surprises found while learning Clojure
;; min is for numbers
(min #inst "2018" #inst "2019") ; Execution error (ClassCastException) at clojure-test.core/eval8469 (form-init524028722621051551.clj:2589) .
; java.util.Date cannot be cast to java.lang.Number
;; macros are not values
(apply or (list false true)) ; Syntax error compiling at (Untitled-1:2:1).
; Can't take value of a macro: #'clojure.core/or
@zoren
zoren / kotlin.kt
Last active November 9, 2020 12:04
interface I<TP> {
fun TP.func()
}
class Dummy
class Implementer : I<Dummy> {
override fun Dummy.func() {
println(this)
}
@zoren
zoren / download-blob.cljs
Created June 18, 2020 15:21
Download a BLOB via a object URL in ClojureScript
;; heavily inspired by Mariano Guerra
;; http://marianoguerra.org/posts/download-frontend-generated-data-to-a-file-with-clojurescript.html
(defn download-blob [file-name blob]
(let [object-url (js/URL.createObjectURL blob)
anchor-element
(doto (js/document.createElement "a")
(-> .-href (set! object-url))
(-> .-download (set! file-name)))]
(.appendChild (.-body js/document) anchor-element)
(.click anchor-element)
(defn index-of-safe
"Return index of value (string or char) in s, optionally searching
forward from from-index. Return nil if value not found.
Works around https://bugs.openjdk.java.net/browse/JDK-8027640
so the returned index is always greater equal to from-index.
This also works around JavaScript's similar behavior."
[s value from-index]
(if (< (count s) from-index)
nil
(clojure.string/index-of s value from-index)))