Skip to content

Instantly share code, notes, and snippets.

View eerohele's full-sized avatar
🐺

Eero Helenius eerohele

🐺
View GitHub Profile
--- /var/folders/r_/pv69pzqn2gd02b4d0hq617hm0000gq/T/pp/cpp.clj 2023-10-03 00:05:14
+++ /var/folders/r_/pv69pzqn2gd02b4d0hq617hm0000gq/T/pp/pp.clj 2023-10-03 00:05:14
@@ -26,9 +26,7 @@
(conj v (name spec))
(let
[p (first spec) cs (rest spec)]
- (into1
- v
- (map (fn* [p1__45589#] (str p "." p1__45589#)) cs)))))
+ (into1 v (map (fn* [p1__45589#] (str p "." p1__45589#)) cs)))))
@eerohele
eerohele / xpath.clj
Created February 14, 2023 13:04
Clojure XPath
(set! *warn-on-reflection* true)
(require '[clojure.edn :as edn])
(require '[clojure.core.protocols :refer [Datafiable]])
(require '[clojure.datafy :as datafy])
(require '[clojure.java.io :as io])
(import '(java.io StringReader PushbackReader))
(import '(java.time LocalDateTime))
(import '(java.time.format DateTimeFormatter))
"Encode and decode integers (such as database identifiers) using Knuth's multiplicative hashing
algorithm. Based on https://github.com/jenssegers/optimus."
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;;
(def eval-context (atom {}))
(defn handle
"Imaginary message handler that sets the namespace received out of band."
[ns]
(swap! eval-context assoc #'*ns* (find-ns ns)))
(defn repl
[]
(loop []
@eerohele
eerohele / bytecode.clj
Last active February 4, 2022 19:34
bytecode.clj
(ns tutkain.bytecode
(:require [clojure.java.io :as io]
[tutkain.backchannel :refer [handle respond-to]])
(:import (java.io PrintWriter StringWriter)
(java.util.spi ToolProvider)
(java.nio.file Files)
(java.nio.file.attribute FileAttribute)))
(set! *warn-on-reflection* true)
@eerohele
eerohele / hello-again.clj
Last active November 19, 2021 16:56
JEP 408 com.sun.net.httpserver: Clojure Hello World
(import '(com.sun.net.httpserver HttpHandlers HttpServer Headers Filter))
(import '(java.net InetSocketAddress))
(import '(java.util.function UnaryOperator))
(defn make-handler
[{:keys [status headers body]}]
(HttpHandlers/of status (Headers/of headers) body))
(def identity-filter
(Filter/adaptRequest "Identity"
@eerohele
eerohele / stacktrace.edn
Created May 31, 2021 11:59
ClojureScript stack trace
#error {
:cause nil
:via
[{:type clojure.lang.ExceptionInfo
:message failed compiling file:src/hello_world/core.cljs
:data {:file #object[java.io.File 0x630a647c src/hello_world/core.cljs], :clojure.error/phase :compilation}
:at [cljs.compiler$compile_file$fn__4001 invoke compiler.cljc 1747]}
{:type clojure.lang.ExceptionInfo
:message nil
:data #:clojure.error{:source src/hello_world/core.cljs, :line 6, :column 3, :phase :compilation}
@eerohele
eerohele / README.md
Last active December 20, 2021 08:20
Start Clojure Socket REPL server and write the port number into .repl-port

In your ~/.clojure/deps.edn, add an alias like this:

:socket-repl {:extra-deps {me.flowthing/shiv {:git/url "https://gist.github.com/eerohele/8611d1a98bd2d5e8ddda14d8394d720a"
                                              :sha "339ef83def69e62ac969a2fd797a9be1d3c1fe83"}}
              :exec-fn shiv/start-server
              :exec-args {:name "server"
                          :port 0
                          :accept clojure.core.server/repl
 :server-daemon false}}
--------------------------------------------------------------------------------
79 |
80 |
81 | (deftest surgeon
82 | (spec/test-with (spec/browser) page
---------^----------------------------------------------------------------------
null
StackOverflowError:
shadow.build.cljs-hacks/shadow-resolve-var (cljs_hacks.cljc:154)
shadow.build.cljs-hacks/shadow-resolve-var (cljs_hacks.cljc:148)
BEGIN MESSAGE.
ZlGCeaVIOme2sCc k7aM5azZDf8EwrX 4dUaIaKru5MOfW7 xDTolSOzxKTDA2f
q36EErpEcULTthd 1khuiM9BjaUTCKq 6Xr2MZHgg6smaIL BpjOvAsq7EbxijZ
fSj5kuHbySVTnuH YIWUnXY5GoHnZlS aqDRMsNR9btNJlP pzv7I0aNlDoMQsU
Z1imMSmbnfS2TgB avyYaeJjLH8GrrZ jTEzl0Qz5Z.
END MESSAGE.