Skip to content

Instantly share code, notes, and snippets.

View lispyclouds's full-sized avatar
💤
On a mission to civilise. One day.

Rahuλ Dé lispyclouds

💤
On a mission to civilise. One day.
View GitHub Profile
@lispyclouds
lispyclouds / rotate_keys.clj
Last active January 8, 2023 10:59
Babashka script to rotate all CircleCI deploy keys in GitHub
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {org.babashka/http-client {:mvn/version "0.0.2"}}})
(require '[babashka.http-client :as http]
'[cheshire.core :as json])
(import '[java.net URL])
(defn get-projects
@lispyclouds
lispyclouds / commit.clj
Last active November 27, 2022 23:19
A commit message helper in babashka
#!/usr/bin/env bb
(require '[babashka.process :as p]
'[clojure.string :as str])
(def authors
{"rd" {:name "Rahul De"
:email "rahul080327@gmail.com"}})
(defn exec
@lispyclouds
lispyclouds / M.java
Created April 15, 2021 15:01
MWord.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.function.Function;
interface Result<T> {
<R> Result<R> then(Function<T, Result<R>> nextFn);
}
record Success<T>(T value) implements Result<T> {
@Override
@lispyclouds
lispyclouds / animals.clj
Last active July 9, 2021 07:24
Guess the animal game with learning, runs on https://babashka.org
; JSON Schema
; {
; "definitions": {
; "fact": {
; "type": "object",
; "properties": {
; "question": { "type": "string" },
; "guess": { "type": "string" },
; "no": { "$ref": "#/definitions/fact" },
; "wrongGuess": { "$ref": "#/definitions/fact" }
@lispyclouds
lispyclouds / m.go
Created December 9, 2020 10:24
Attempt at monadic Go
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
type Result interface {
@lispyclouds
lispyclouds / commit
Last active November 27, 2022 16:11
A commit message helper supporting story numbers and Co-authored-by
#!/usr/bin/env bash
set -eo pipefail
changed=$(git status --porcelain)
is_github_repo=$(git config --get remote.origin.url; echo $?)
declare -A github_users
github_users=(
["rd"]="Rahul De <rahul080327@gmail.com>"
@lispyclouds
lispyclouds / zsh-hist-clean.clj
Created October 19, 2020 17:46
Removes dupes from ZSH history, preserving timestamps. Compatible with babashka
(require '[clojure.java.io :as io]
'[clojure.string :as s])
(defn line->cmd
[line]
^String
(some->> (s/index-of line \;)
inc
(subs line)))
@lispyclouds
lispyclouds / M.scala
Last active May 21, 2020 05:13
Dotty ADTs
import scala.io.StdIn
// Result[+T] is a Monoid with flatMap as the join fn
enum Result[+T] {
case Success(value: T)
case Failure(exception: Throwable)
// bind hence a Monad
def flatMap[U](f: T => Result[U]) =
this match {
@lispyclouds
lispyclouds / pod-bb-python-sqlite.py
Created May 5, 2020 12:27
A simple example for a SQLIte pod for Babashka
import json
import sqlite3
import sys
from bcoding import bencode, bdecode
def read():
return dict(bdecode(sys.stdin.buffer))
@lispyclouds
lispyclouds / Monads.scala
Last active April 26, 2020 13:43
Finally understood Types.
import scala.io.StdIn
// Result[+T] is a Monoid with bind as the join fn
sealed trait Result[+T] {
// makes this a Functor
def map[U](f: T => U): Result[U]
// bind hence a Monad
def flatMap[U](f: T => Result[U]): Result[U]
}