Skip to content

Instantly share code, notes, and snippets.

Jochen Bedersdorfer beders

Block or report user

Report or block beders

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@beders
beders / mini-promise.cljc
Last active Nov 23, 2019
Super minimal macro to simplify dealing with promise/async/await code in ClojureScript
View mini-promise.cljc
(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))
@beders
beders / ForceHostnameVerificationSSLContext.java
Created Oct 16, 2017
Glorious hack to use Java 9 HttpClient with servers enforcing SNI
View ForceHostnameVerificationSSLContext.java
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 / QuickstartSample.java
Created May 10, 2017
Alternative Pubsub API design
View QuickstartSample.java
// 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 / jps.js
Created Jun 21, 2015
List of currently running Java processes, color coded using Nashorn
View jps.js
// List running Java Processes
// ansicolors
var a = { reset : "\u001B[0m", black: "\u001B[30m", red: "\u001B[31m", green: "\u001B[32m",
yellow: "\u001B[33m", blue: "\u001B[34m", purple: "\u001B[35m", cyan: "\u001B[36m",
white: "\u001B[37m"
};
var jps = `jps -vl`.split('\n').slice(0,-1);
var ownPID = java.lang.management.ManagementFactory.getRuntimeMXBean().getName().split('@')[0];
@beders
beders / BetterBus.java
Last active Dec 8, 2015
Examples for optional lambda parameters and polymorphism with default methods
View BetterBus.java
package example;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
/**
* Created by beders on 7/7/15.
*/
@beders
beders / nashorn-bash
Last active Dec 8, 2015
A bash script that is also a nashorn script.
View nashorn-bash
#!/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 / RestyPostMultipart.java
Created Jan 17, 2012
POST multipart form data (application/multipart-formdata)
View RestyPostMultipart.java
// POST multipart form data (application/multipart-formdata)
Resty r = new Resty();
String firstResult = r.xml("http://api.search.yahoo.com/WebSearchService/V1/webSearch",
form(data("appid","YahooDemo"),data("query", "Resty+java"), data("results", "10")))
.get("/ResultSet/Result[1]/Title",String.class);
@beders
beders / RestyGDev.java
Created Jan 17, 2012
Getting the Google Developer calendar
View RestyGDev.java
// Getting the Google Developer calendar
// getting a link from JSON to an XML description of an entry, parsing the text out with XPath
Resty r = new Resty();
String title =
r.json("http://www.google.com/calendar/feeds/developer-calendar@google.com/public/full?alt=json")
.xml(path("feed.entry[0].id.$t")).get("entry/title/text()", String.class);
@beders
beders / HelloResty.java
Last active Sep 29, 2015
Hello World! Complete example
View HelloResty.java
import us.monoid.web.Resty;
import java.io.IOException;
public class HelloResty {
// Hello World!
public static void main(String... args) throws IOException {
Resty r = new Resty();
// Get the content of the URL as text and print it
String hello = r.text("http://www.helloworld.org/data/helloworld.java").toString();
System.out.println(hello);
View gist:467a7fccfccb1744607e
(function(){
var json = JSON.parse(document.getElementsByTagName('pre')[0].innerText);
var result = JSON.parse(json.result);
document.getElementsByTagName('BODY')[0].appendChild(document.createTextNode("Result to convert: " + JSON.stringify(result, null, 2)));
// mock data
result = {
"result":[
{
"receiver_rank":1,
You can’t perform that action at this time.