Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View beders's full-sized avatar

Jochen Bedersdorfer beders

View GitHub Profile
@beders
beders / gist:1cb3b3f8ddba12d697f7
Created April 17, 2015 05:16
Odd side effects using eval
// 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);
@beders
beders / RestyPostMultipart.java
Created January 17, 2012 06:42
POST multipart form data (application/multipart-formdata)
// 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 January 17, 2012 06:38
Getting the Google Developer calendar
// 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 September 29, 2015 15:48
Hello World! Complete example
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);