Skip to content

Instantly share code, notes, and snippets.

View jacobemcken's full-sized avatar

Jacob Emcken jacobemcken

View GitHub Profile
@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)
@jacobemcken
jacobemcken / hello.cljs
Last active August 29, 2015 14:04
Example to trigger compile warning
(ns example.hello)
;; This function will cause compilation got give the following warning:
;; WARNING: cljs.core/<, all arguments must be numbers, got [js/Date js/Date] instead.
(defn test-lt-operator
[^js/Date t]
(< t (js/Date.)))
@jacobemcken
jacobemcken / init.clj
Last active December 23, 2015 17:49
The following tested using Immutant 1.x.incremental.1009 (PuntoBueno)
(ns immutant.init
(:require [clj-time.core :as dt]
[immutant.messaging :as msg]))
(msg/start "/queue/a-queue")
(msg/listen "/queue/a-queue" #(println "received: " %))
(msg/publish "/queue/a-queue" {:created (dt/now)}) ; gives a stacktrace