Skip to content

Instantly share code, notes, and snippets.

View JohnnyJayJay's full-sized avatar
🏔️
Now on Codeberg

Johnny JohnnyJayJay

🏔️
Now on Codeberg
View GitHub Profile
@JohnnyJayJay
JohnnyJayJay / quick-oauth.clj
Created March 29, 2024 14:30
babashka script to quickly perform the oauth2 authorization_code flow locally to get an access token
#!/usr/bin/env bb
(require
'[babashka.http-client :as hc]
'[babashka.deps :as deps]
'[org.httpkit.server :as hs]
'[clojure.java.browse :refer [browse-url]])
(deps/add-deps '{:deps {ring/ring-core {:mvn/version "1.12.1"}}})
@JohnnyJayJay
JohnnyJayJay / highlight.clj
Last active May 25, 2024 17:40
cryogen extension for AOT syntax highlighting
;; SPDX-License-Identifier: MIT
;; SPDX-FileCopyrightText: 2023 JohnnyJayJay
;;
;; AOT syntax highlighting for cryogen blogs using highlight.js and GraalVM polyglot features.
;; How to use:
;; 1. Add Graaljs as a dependency: https://mvnrepository.com/artifact/org.graalvm.js/js/23.0.1 (or build your blog on GraalVM directly)
;; 2. Place a minimal highlight.js distribution at the root of your cryogen project. You can get one by downloading without selecting any languages from https://highlightjs.org/download
;; 3. In your cryogen.core namespace, call `compile-assets-timed` with `{:update-article-fn highlight-code-in-article}`
;; 4. Remove the highlight.js scripts from your theme's templates - they're not needed anymore. A highlight.js *theme* is still needed though!
(ns cryogen.highlight
@JohnnyJayJay
JohnnyJayJay / challenge-schema.json
Created August 3, 2023 21:53
challenge codosseum schema
{
"$schema": "http://json-schema.org/draft/2020-12/schema",
"type": "object",
"description": "This is the basic challenge format schema.\nIt defines the *minimal* requirements that a challenge file has to conform to to be accepted by\nthe codosseum backend (and clients). Many of the fields are therefore optional.\n\nFor the core challenge repository maintained by the codosseum team, the requirements are more strict and refined – if you wish to contribute there, refer to the variant of the schema defined in that repository.\n",
"required": [
"title",
"text",
"public_tests"
],
"properties": {
@JohnnyJayJay
JohnnyJayJay / borg_backup.clj
Created April 27, 2023 10:51
Babashka script for daily backups using borg, polkit and zenity
#!/usr/bin/env bb
(ns borg-backup
(:require [babashka.process :as p :refer [shell process sh]]
[clojure.string :as str]
[clojure.java.io :as io]))
(def keep
{:daily 5
:weekly 3
@JohnnyJayJay
JohnnyJayJay / day1.bqn
Created December 1, 2022 14:24
advent of code 2022 day 1 (BQN codegolf)
+´¨1‿3{↑⟜𝕩¨ 𝕨}∨+´¨•BQN⚇¯2 1↓{(¬×1++`)¬×≠¨𝕩}⊸⊔•FLines"input"
@JohnnyJayJay
JohnnyJayJay / bigswap.clj
Last active March 8, 2022 22:33
A Clojure function for atoms that I'm currently missing
(defn bigswap!
"`swap!` into an atom *and* return a custom value produced in the atomic function.
`atom` is the atom.
`f` is a function of two arguments: the first is a function `atom-set` that 'sets' the atom to the given value.
The second is the current value in the atom.
In essence, `bigswap!` returns the value of `f` while setting the value of the atom to the value set by `atom-set`, if applicable."
[atom f]
(let [return-val (volatile! nil)]
@JohnnyJayJay
JohnnyJayJay / measurements.json
Created March 2, 2022 16:46
Plotting variable interaction graph layout mesasurement results
[ {
"variables" : 250,
"clauses" : 1065,
"name" : "https://gbd.iti.kit.edu/file/6ffbc2b1851be02a3b040af9b7d15a42/",
"time" : 526
}, {
"variables" : 430,
"clauses" : 9080,
"name" : "https://gbd.iti.kit.edu/file/218aba6ee61e235dfb9bcde2894a007c/",
"time" : 1502
@JohnnyJayJay
JohnnyJayJay / example-tests.clj
Created July 23, 2021 13:44
Macro that can be used for small in-place tests and documentation
(defmacro examples
"Macro to generate illustrative tests for a function based on input-output pairs.
`f` is the function to test.
`equals` is the function used to compare the expected and actual result.
Each example call is a sequence where the first n - 1 items are the inputs and the last item is the expected output."
{:style/indent 1}
[f equals & example-calls]
`(fn []
~@(for [call example-calls
@JohnnyJayJay
JohnnyJayJay / discljord-slash-commands.md
Last active February 19, 2023 09:34
Quick primer for slash commands in discljord

Working with Slash Commands in discljord

At the end of 2020, Discord introduced a new feature that is available to bots: Slash Commands.
Slash Commands belong to a new feature category called "Interactions" which finally allows bots to enhance the Discord UI. As such, the way slash commands (and upcoming interactions such as clickable buttons aka. "components") work is quite different from other parts of the API.

What exactly are Slash Commands?

Slash commands are Discord entities that you can create, edit and delete through requests. Registered commands have a name and a description and are accessible in Discord clients by typing /name.
There are two types of commands: guild and global. As the names indicate, commands of the former type are only accessible in one specific guild

@JohnnyJayJay
JohnnyJayJay / haste.clj
Created April 5, 2021 23:26
A small babashka script to post text to a haste-server and get the url back
#!/usr/bin/env bb
(def ^:const base-url "https://hastebin.com")
(as-> (or (first *command-line-args*) System/in) $
(io/input-stream $)
(curl/post (str base-url "/documents") {:body $})
(:body $)
(json/parse-string $ true)
(:key $)