Skip to content

Instantly share code, notes, and snippets.

View danielsz's full-sized avatar

Daniel Szmulewicz danielsz

View GitHub Profile
@danielsz
danielsz / pr.scm
Last active August 31, 2024 00:35
Primitive recursion
(use-modules (srfi srfi-26))
;; Zero function
(define Z (lambda _ (const 0)))
;; Successor function
(define (S n) (+ n 1))
;; Projector function
(define (P i) ;
@danielsz
danielsz / pr.clj
Last active August 31, 2024 00:18
Primitive Recursion
(ns pr.core)
;;; basic functions on numbers: zero, successor and projection
(def Z #(fn [& _] 0))
(def S inc)
(defn P [i]
(fn [& args] (nth args (dec i))))
@danielsz
danielsz / http.clj
Last active May 23, 2024 15:04
Ring-compliant web server from scratch
(ns socket.http
(:require
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log])
(:import [java.net ServerSocket]
[java.net SocketException]
[java.nio.file Files]
[java.io File]
[java.io InputStream OutputStream]))
@danielsz
danielsz / cbor.clj
Created March 24, 2024 04:46
Cbor-clj parser
(ns recursiveparser.cbor
(:require [clojure.tools.logging :as log])
(:import [com.google.iot.cbor CborMap CborTextString CborInteger CborArray CborByteString CborSimple]
[co.nstant.in.cbor.model Map Array SimpleValue UnicodeString ByteString]
[peergos.shared.cbor CborObject$CborMap CborObject$CborString CborObject$CborByteArray CborObject$CborBoolean CborObject$CborList CborObject$CborLong CborObject$CborMerkleLink]))
(defprotocol Cbor
(parse [this]))
(extend-type CborMap
@danielsz
danielsz / polling.clj
Last active October 7, 2024 05:05
Polling endpoint with core.async
(ns clojure.polling
(:require [clj-http.client :as client]
[clojure.core.async :as async :refer [>!! timeout <! go-loop]]
[cheshire.core :as json]
[clojure.tools.logging :as log]))
(defn client
([endpoint]
(client/get endpoint))
([endpoint c e]
@danielsz
danielsz / meyvn.org
Last active October 14, 2021 11:05
Meyvn: going Clojureless

Mevyn

Download Meyvn to your local repository

mvn org.apache.maven.plugins:maven-dependency-plugin:3.2.0:get -Dartifact=org.meyvn:meyvn:1.6.0

Check out https://meyvn.org/

{
"run_type": "client",
"local_addr": "127.0.0.1",
"local_port": 1080,
"remote_addr": "naphtali.tuppu.net",
"remote_port": 443,
"password": ["yourpassword"],
"log_level": 1,
"ssl": {
"verify": true,
@danielsz
danielsz / nrepl.clj
Created January 10, 2020 20:11
nrepl from clojure
(ns nrepl
(:require [nrepl.core :as nrepl])
(:import [java.net ConnectException]))
(defn nrepl-send [repl-port x]
(let [message (cond
(string? x) {:op "eval" :code x :id (utils/uuid)}
(map? x) x
:else (throw (AssertionError. "Wrong input.")))]
(with-open [conn (nrepl/connect :port repl-port)]
@danielsz
danielsz / pretty-lambda.el
Created May 24, 2019 13:35
Custom font locking for Clojure mode
(eval-after-load 'clojure-mode
(font-lock-add-keywords
'clojure-mode `(("(\\(fn\\)[\[[:space:]]"
(0 (progn (compose-region (match-beginning 1)
(match-end 1) "λ")
nil))))))
(eval-after-load 'clojure-mode
(font-lock-add-keywords
'clojurescript-mode `(("(\\(fn\\)[\[[:space:]]"
@danielsz
danielsz / fsm-ho.scm
Last active May 19, 2019 22:55
Refactoring of William Byrd's higher-order implementation of a finite state machine with driver
(define fsm-ho2
(lambda (str)
(letrec ([S0 (lambda (b)
(case b
[(0) S0]
[(1) S1]
[else #t]))]
[S1 (lambda (b)
(case b
[(0) S2]