Skip to content

Instantly share code, notes, and snippets.

@leonoel
leonoel / prepl.clj
Last active February 21, 2024 16:47
Example of clojure prepl usage with missionary
(ns prepl
(:require [clojure.core.server :as s]
[missionary.core :as m])
(:import (java.io PipedReader PipedWriter)
(java.util.concurrent Executors)))
(defn remote "
Returns a function taking a `java.io.PipedWriter` and returning a flow connecting to a remote prepl on given `host` and
`port`, sending the content of the pipe to the remote peer and emitting received evaluation results. The pipe is closed
on flow cancellation.
@chase-lambert
chase-lambert / chatgpt-cli.clj
Last active June 7, 2023 08:35
chatGPT API cli
#!/usr/bin/env bb
;; You need to have an OpenAI API key and set it like:
;; export OPENAI_API_KEY=<your key> in your .bashrc
;;
;; Make sure you have babashka installed
;; https://github.com/babashka/babashka#installation
;;
;; One way to run this is to install bbin
;; https://github.com/babashka/bbin
@ssrihari
ssrihari / clojure-learning-list.md
Last active April 15, 2024 14:54
An opinionated list of excellent Clojure learning materials

An opinionated list of excellent Clojure learning materials

These resources (articles, books, and videos) are useful when you're starting to learn the language, or when you're learning a specific part of the language. This an opinionated list, no doubt. I've compiled this list from writing and teaching Clojure over the last 10 years.

  • 🔴 Mandatory (for both beginners and intermediates)
  • 🟩 For beginners
  • 🟨 For intermediates

Table of contents

  1. Getting into the language
// I had been intending for people to just play around with this for fun and for personal use,
// but I've been advised to remove the first portion due to regulatory uncertainty.
// This way people can still use the merge check however they want.
/** @notice Determine whether we're running in Proof of Work or Proof of Stake
@dev Post-merge, the DIFFICULTY opcode gets renamed to PREVRANDAO,
and stores the prevRandao field from the beacon chain state if EIP-4399 is finalized.
If not the difficulty must be be 0 according to EIP-3675, so both possibilities are checked here. */
function haveWeMergedYet() public view returns (bool) {
@alpox
alpox / example.clj
Last active November 21, 2023 20:29
Clojure -> Python Async
(defn sleep [s]
(-> (asyncio/sleep s)
(pp/then (fn [_] s))))
(defn fun []
(pp/let [x (sleep 1)
z (pp/resolved 5)
y (sleep 2)]
(+ x y z)))
(defn async-iteration [from-process
to-process
output-channel
& {:keys [values-selector some? init]
:or {values-selector vector
some? some?}}]
(async/go
(async/>! to-process init)
(loop [value (async/<! from-process)]
(if (some? value)
@borkdude
borkdude / bipe
Last active April 9, 2024 21:21
vipe for babashka - see https://github.com/juliangruber/vipe
#!/usr/bin/env bash
# temp file
t=/tmp/bipe.$$.txt
touch $t
# read from stdin
if [ ! -t 0 ]; then
cat > $t
@anypercent
anypercent / gist:3a56ee569ae271aafb8044f10b39baa7
Created September 11, 2021 21:07
top 100 solamanders listed on digitaleyes
ranking price link
76 7 https://digitaleyes.market/item/7r8oLSVhJTN4kiGEfaBpEbcFVFgR1y8FyMVgeyKcYqHu
56 11 https://digitaleyes.market/item/77t27sPYMjzFxfh7CfNbCvPNrDNPZUyato87gRyjcxnW
60 11.4 https://digitaleyes.market/item/66ajoiSKRZdkiZiu6Rzb9TdJs6PnH7T8GP4u3tdZuEsf
79 13 https://digitaleyes.market/item/HQN7o6apRMfj6o8GdUgM6fy5YRRD9trpeNAWVr7ixbdf
17 15 https://digitaleyes.market/item/FuXgMCGBwyiMFwtZoAG7EjbzTzDQxi2SdtMSnHq7RtSS
89 15 https://digitaleyes.market/item/Euss8ejH1ouaaMEuKo1dnfcg3XsAzBa9zXPJRwi1R5Pn
51 16 https://digitaleyes.market/item/CRPYKua576bg8LUefia16zSZRcXMQpSe5ydiKbXanjfC
48 20 https://digitaleyes.market/item/5tsNXSU3utmgcjwt4APWQXeNDyxQPPnJDTeS5WYVpUbx
28 21 https://digitaleyes.market/item/47Mx4hAF7Cpsu771pSfNGJv4p5xG95vsowYjAxopaAdp
@didibus
didibus / clojure-right-tool.md
Last active January 15, 2024 11:23
When is Clojure "the right tool for the job"?

My answer to: https://www.reddit.com/r/Clojure/comments/pcwypb/us_engineers_love_to_say_the_right_tool_for_the/ which asked to know when and at what is Clojure "the right tool for the job"?

My take is that in general, the right tool for the job actually doesn't matter that much when it comes to programming language.

There are only a few cases where the options of tools that can do a sufficiently good job at the task become limited.

That's why they are called: General-purpose programming languages, because they can be used generally for most use cases without issues.

Let's look at some of the dimensions that make a difference and what I think of Clojure for them:

@matthewdowney
matthewdowney / web3.clj
Created August 28, 2021 00:18
Call a smart contract from Clojure to query data from the Ethereum blockchain.
(ns web3
"Call an Ethereum smart contract (Uniswap v2) from Clojure.
Requires https://github.com/clj-python/libpython-clj for python interop. Also
make sure to $ pip install web3."
(:require [libpython-clj2.python :as py]
[libpython-clj2.require :refer [require-python]]))
(comment ;; deps.edn