Skip to content

Instantly share code, notes, and snippets.

View botic's full-sized avatar
👔
working for @orfon and @diehauswirtschaft

Philipp Naderer-Puiu botic

👔
working for @orfon and @diehauswirtschaft
View GitHub Profile
var response = require("ringo/jsgi/response");
var {Application} = require("stick");
var app = exports.app = Application();
app.configure("params", "validation", "route");
app.get("/", function(req) {
req.validate("email").isEmail("No e-mail given.");
@botic
botic / setup.sh
Created April 2, 2014 12:22
How to use Codeship for RingoJS
# download ringo-master
wget https://github.com/ringo/ringojs/archive/master.zip
# unzips the archive to ./ringojs-master/
unzip ./master.zip
# download apache ivy
wget http://www.eu.apache.org/dist/ant/ivy/2.4.0-rc1/apache-ivy-2.4.0-rc1-bin-with-deps.zip
unzip ./apache-ivy-2.4.0-rc1-bin-with-deps.zip
@botic
botic / eu-parlament.js
Created April 18, 2014 15:50
Wir rendern das EU-Parlament ...
var $parliament = $("<ul>", { class: "parliament" });
_.forEach(this.distribution, function(group) {
$parliament.append($("<li>").attr({
"class": group.css,
"title": group.name
}).text(group.shortcut));
});
@botic
botic / insecure-https.js
Created September 1, 2014 11:57
Ignore invalid / self-signed certificates in Ringo
// Build a custom X509 Trust Manager to accept everything
var trustManager = new JavaAdapter(Packages.javax.net.ssl.X509TrustManager, {
getAcceptedIssuers: function () { return null; },
checkClientTrusted: function (certs, authType) { },
checkServerTrusted: function (certs, authType) { }
});
// Replace the default trust manager with our "very open minded" implementation
var sslCtx = Packages.javax.net.ssl.SSLContext.getInstance("SSL");
sslCtx.init(null, [trustManager], new java.security.SecureRandom());
@botic
botic / generator.js
Last active August 29, 2015 14:13
ScrambledZipfianGenerator
var gen = vars.getObject("ScrambledZipfianGenerator");
if (gen == null) {
gen = new Packages.com.yahoo.ycsb.generator.ScrambledZipfianGenerator(1000, 9999);
vars.putObject("ScrambledZipfianGenerator", gen);
log.info("ScrambledZipfianGenerator created.");
}
vars.put("nextInt", gen.nextInt());
@Entity
public class TxEntity {
@Id
private String id;
@Parent
private Ref<TxEntity> parent;
@Index
private String text;
@botic
botic / commandline.js
Created January 23, 2015 16:33
commandline
var system = require('system');
var term = require('ringo/term');
var shell = require('ringo/shell');
system.args.forEach(function(arg, i) {
term.writeln(term.YELLOW, term.ONBLUE, 'arg' + i + ': ' + arg);
});
term.writeln('');
@botic
botic / decoder-length.js
Last active August 29, 2015 14:15
RingoJS ringo/encoding examples
var {ByteArray} = require('binary');
var {Decoder} = require('ringo/encoding');
var ba = new ByteArray([0xF0,0x9F,0x98,0x98]);
var dec = new Decoder("UTF-8");
console.log(dec.decode(ba));
console.log(dec.length + " chars vs. " + ba.length + " bytes");
@botic
botic / ofyToObject.js
Created April 16, 2015 10:21
Objectify Entity to Plain JS Object in Rhino
const OBJECT_CLASS = (new java.lang.Object()).getClass();
var ofyToObject = exports.ofyToObject = function(ofyObject) {
let obj = {};
let beanInfo = java.beans.Introspector.getBeanInfo(ofyObject.getClass(), OBJECT_CLASS);
let properties = beanInfo.getPropertyDescriptors();
for (let i = 0; i < properties.length; i++) {
let pd = properties[i];
let getter = pd.getReadMethod();
@botic
botic / httpsconnection.js
Created July 9, 2015 08:02
TLS/SSL with Ringo's HTTP client
var {get, request} = require("ringo/httpclient");
// Using get
var exchange = get("https://www.washingtonpost.com/");
console.log(exchange.status);
// Using the more generic request function
exchange = request({
url: "https://www.washingtonpost.com/",
method: "GET"