Skip to content

Instantly share code, notes, and snippets.

View beders's full-sized avatar

Jochen Bedersdorfer beders

View GitHub Profile
@beders
beders / nashorn-bash
Last active December 8, 2015 13:34
A bash script that is also a nashorn script.
#!/usr/bin/env bash
JJS=$(type -p $JDK_HOME/bin/jjs || type -p jjs)
if [ -z $JJS ]; then
echo "I can't find jjs. Please install JDK 8 or set JDK_HOME."; exit 1
fi
JS=$(mktemp $(basename "$0").XXXXXX)
tail -n+12 "$0" > $JS
$JJS -scripting $JS -- "$@"
rm $JS
exit 0;
@beders
beders / QuickstartSample.java
Created May 10, 2017 00:51
Alternative Pubsub API design
// TODO add imports
public class QuickstartSample {
public static void main(String... args) throws Exception {
Topic t = TopicAdmin.getDefault().createTopic("my-new-topic");
System.out.printf("Topic %s:%s created.\n", topic.getProject(), topic.getName());
}
}
@beders
beders / ForceHostnameVerificationSSLContext.java
Created October 16, 2017 23:47
Glorious hack to use Java 9 HttpClient with servers enforcing SNI
package us.monoid.resty.hack;
import javax.net.ssl.*;
import java.security.*;
import java.util.List;
/** Glorious hack to always create an SSL Engine with a hostname and port.
* engineGetServerSessionContext and engineGetClientSessionContext can't be implemented without violating class/module loading constraints,
* but for some reason, they are not being called.
* */
@beders
beders / mini-promise.cljc
Last active January 26, 2022 22:18
Super minimal macro to simplify dealing with promise/async/await code in ClojureScript
(defn create-function-call [param expr]
"Create an sexp for calling expr with a first argument provided by a promise.
If expr is a list (already in form suitable for a function call), insert the first argument at second position,
otherwise turn expr into a function call expression, unless the function is an fn, which is simply returned.
println -> (fn [param] (println param))
(* 2) -> (fn [param] (* param 2))