Skip to content

Instantly share code, notes, and snippets.

View jacobemcken's full-sized avatar

Jacob Emcken jacobemcken

View GitHub Profile
@jacobemcken
jacobemcken / README.md
Last active July 11, 2025 21:53
Exploring writing "Tool servers" for AI with Babashka

Exploring writing "Tool servers" for AI with Babashka

A tool server is just a REST API that includes an OpenAPI specification, that the AI can use to navigate how to leverage the API.

Preferrably, the OpenAPI specification and the actual code should only be maintained using a single source of truth.

So far I've only found Reitit which seems to work when using vanilla Clojure: https://github.com/metosin/reitit/tree/master/examples/openapi

@jacobemcken
jacobemcken / optimize_img.clj
Last active May 23, 2024 19:18
Generate optimized and responsive images using TinyPNGs API
#!/usr/bin/env bb
(ns optimize-img
(:require [babashka.fs :as fs]
[babashka.http-client :as http]
[cheshire.core :as json]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.cli :as cli]))
(def cli-options
@jacobemcken
jacobemcken / upload_to_sharepoint.clj
Created April 7, 2024 15:51
Upload file to SharePoint with app-only principal using Babashka
#!/usr/bin/env bb
(ns upload-to-sharepoint
(:require [babashka.http-client :as http]
[cheshire.core :as json]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.cli :as cli])
(:import (java.net URLEncoder URLConnection)))
(def cli-options
@jacobemcken
jacobemcken / java.sh
Created December 21, 2023 18:49
Script helping to install newer Java versions on Netlify required by Shadow-cljs
#!/bin/bash
CACHE_DIR=$NETLIFY_BUILD_BASE/cache
rm -rf $HOME/.m2/
cp -a $NETLIFY_BUILD_BASE/cache/.m2/ $HOME/.m2/
JAVA_DOWNLOAD_URL="https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz"
JAVA_RELEASE=jdk-17.0.2 # Must match directory inside archive in JAVA_DOWNLOAD_URL
currentver="$(java -version 2>&1 |head -n1 | cut -d'"' -f2 |cut -d'.' -f1)"
@jacobemcken
jacobemcken / jwt.cljs
Last active January 15, 2024 16:23
Generate dummy JWT using ClojureScript in browser
(ns jwt
"Generate JTW using ClojureScript in browser.
**WARNING** Never store signing key / secret client side (in browser).
It isn't safe.
Play around with different tokens scenarios in a local environment,
without round-tripping 3. party services like Auth0 for every combination.
Implementation reference: https://jwt.io/introduction
Decode tokens in browser: https://jwt.io/"

Keybase proof

I hereby claim:

  • I am jacobemcken on github.
  • I am jacobemcken (https://keybase.io/jacobemcken) on keybase.
  • I have a public key ASCtFqvnYH8NCQckSRsSdM91ySGnEYOJtfXIY-17ErYNTgo

To claim this, I am signing this object:

@jacobemcken
jacobemcken / transit_format.cljs
Last active January 3, 2022 22:52
ClojureScript (cljs) Transit Day.js
(ns app.transit-format
(:require ["dayjs" :as dayjs]
["dayjs/plugin/duration" :as duration]
[cognitect.transit :as transit]
[haslett.format :as fmt]))
;; Extend Day.js with more functionality
(.extend dayjs duration)
(def duration-type
@jacobemcken
jacobemcken / gist:b78785bf862cb9c680b9
Created August 11, 2015 20:56
Stacktrace after updating cljx to version 0.5.0 (from 0.4.0 which didn't cause the issue)
22:49:19,353 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "vendix.clj" (runtime-name: "vendix.clj")
22:49:19,535 WARN [org.hornetq.journal] (MSC service thread 1-2) HQ142000: You have a native library with a different version than expected
22:49:19,541 WARN [org.jboss.as.messaging] (MSC service thread 1-2) JBAS011600: AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
22:49:22,475 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC00001: Failed to start service jboss.deployment.unit."vendix.clj".STRUCTURE: org.jboss.msc.service.StartException in service jboss.deployment.unit."vendix.clj".STRUCTURE: JBAS018733: Failed to process phase STRUCTURE of deployment "vendix.clj"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-7.2.x.slim.incremental.19.jar:7.2.x.slim.incremental.19]
a
@jacobemcken
jacobemcken / core.cljs
Last active August 29, 2015 14:12
Example thats triggers bug (?) in Weasel 0.5.0 upon namespace change
(ns rfgs.core
(:require [weasel.repl :as ws-repl]
[clojure.string :as string]))
(enable-console-print!)
(defonce game-state (atom {})) ; Atom to store the game state
(if-not (ws-repl/alive?)
(do (print "Open REPL")
@jacobemcken
jacobemcken / MyValidator.php
Last active August 29, 2015 14:10
Unit test for Laravel custom validator
<?php
use Illuminate\Validation\Validator;
class MyValidator extends Validator {
public function validateMutuallyExclusiveWith($attribute, $value, $parameters) {
$allEmpty = true;
foreach ($parameters as $key)