Skip to content

Instantly share code, notes, and snippets.

View isaksky's full-sized avatar

Isak Sky isaksky

View GitHub Profile
@holyjak
holyjak / http-server.bb
Last active March 19, 2023 04:36
Babashka HTTP server for serving static files, similar to `python -m http.server` but more flexible :)
#!/usr/bin/env bb
#_" -*- mode: clojure; -*-"
;; Based on https://github.com/babashka/babashka/blob/master/examples/image_viewer.clj
(ns http-server
(:require [babashka.fs :as fs]
[clojure.java.browse :as browse]
[clojure.string :as str]
[clojure.tools.cli :refer [parse-opts]]
[org.httpkit.server :as server]
@hindol
hindol / websocket.clj
Created June 12, 2020 18:06
Access WebSocket session in Pedestal
(defn ws-listener
[_request _response ws-map]
(proxy [WebSocketAdapter] []
(onWebSocketConnect [^Session ws-session]
(proxy-super onWebSocketConnect ws-session)
(when-let [f (:on-connect ws-map)]
(f ws-session)))
(onWebSocketClose [status-code reason]
(when-let [f (:on-close ws-map)]
(f (.getSession this) status-code reason)))
(ns scratch)
(defn map [f]
(fn [xf]
(fn
([] (xf))
([acc] (xf acc))
([acc itm]
(xf acc (f itm))))))
@pesterhazy
pesterhazy / clj_to_js.md
Last active February 26, 2024 20:18
ClojureScript Do's and Don'ts: clj->js

ClojureScript Do's and Dont's: clj->js

You should prefer

#js["tag" #js{"k1" v1, "k2" v2}]

over

@mrange
mrange / on-tail-recursion.md
Last active March 15, 2022 04:57
On the topic of tail calls in .NET

On the topic of tail calls in .NET

Let's say you have implemented a small data pipeline library to replace LINQ.

module TrivialStream =
  type Receiver<'T> = 'T            -> unit
  type Stream<'T>   = Receiver<'T>  -> unit

  module Details =
@jswny
jswny / Flexible Dockerized Phoenix Deployments.md
Last active July 3, 2023 05:25
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

(ns switch
(:require [clojure.pprint :as pprint]))
(defn project-clj-map [filename]
(->> (slurp filename)
(read-string)
(drop 1)
(partition 2)
(map vec)
(into {})))
@mrange
mrange / 1.md
Last active August 2, 2023 16:43

Thinking about Async/Await

A couple of weeks ago I listened to .Net Rocks! #1433 about Visual Studio 17 with Kathleen Dollard. A very good episode interest but with stuck with me was Kathleen's comment that after all these years she sees very smart people still struggle with async. This is my and others experience as well.

A few years ago I wrote a blog post on why I thought async in C# isn't that great. I took it down a bit later even though it was popular it was also divisive and my understanding of async had grown which made me want to rewrite the whole piece into something better and less divisive.

I used to think that the implicit coupling in async to the SynchronizationContext is a major problem for async but today I think that it's a minor problem for most developers. The reason is that if you are writing ASP.NET you will always have the ASP.NET SynchronizationContext and that gives particular but consistent async behavior. If y

// ----------------------------------------------------------------------------------------------
// Copyright 2017 Mårten Rånge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
@reborg
reborg / rich-already-answered-that.md
Last active February 23, 2024 13:09
A curated collection of answers that Rich gave throughout the history of Clojure

Rich Already Answered That!

A list of commonly asked questions, design decisions, reasons why Clojure is the way it is as they were answered directly by Rich (even when from many years ago, those answers are pretty much valid today!). Feel free to point friends and colleagues here next time they ask (again). Answers are pasted verbatim (I've made small adjustments for readibility, but never changed a sentence) from mailing lists, articles, chats.

How to use:

  • The link in the table of content jumps at the copy of the answer on this page.
  • The link on the answer itself points back at the original post.

Table of Content