View gist:1cb3b3f8ddba12d697f7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run with: curl -d 'console.log("hi");' http://localhost:8063; curl -d 'console.log("hi");' http://localhost:8063 | |
vertx.createHttpServer().requestHandler(function (req) { | |
req.bodyHandler(function (buffer) { | |
var code = buffer.toString("UTF-8"); | |
var result = eval('"use strict";' + code) || {}; | |
req.response().end(JSON.stringify(result)); | |
}); | |
}).listen(8063); |
View gist:7849cce449098d7e2de2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.saffrontech.ws.vertx.problem; | |
import io.vertx.core.AbstractVerticle; | |
import io.vertx.core.DeploymentOptions; | |
import io.vertx.core.Vertx; | |
import io.vertx.ext.apex.Router; | |
import io.vertx.ext.apex.handler.sockjs.BridgeOptions; | |
import io.vertx.ext.apex.handler.sockjs.SockJSHandler; | |
// curl http://localhost:8888/eventbus/info |
View EventBusBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.saffrontech.vertx; | |
import io.vertx.core.AsyncResult; | |
import io.vertx.core.Handler; | |
import io.vertx.core.MultiMap; | |
import io.vertx.core.Vertx; | |
import io.vertx.core.buffer.Buffer; | |
import io.vertx.core.eventbus.DeliveryOptions; | |
import io.vertx.core.eventbus.Message; | |
import io.vertx.core.http.WebSocket; |
View gist:a4229baac6464e1c7e51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bus.register(msg -> { System.out.println("I gots a message") }); | |
bus.register((msg,param) -> { System.out.println("I gots a message w/ params"); }); |
View gist:467a7fccfccb1744607e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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, |
View HelloResty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 RestyGDev.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
View RestyPostMultipart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
View nashorn-bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
View BetterBus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
*/ |
OlderNewer