This file contains hidden or 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
| 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."); |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| var $parliament = $("<ul>", { class: "parliament" }); | |
| _.forEach(this.distribution, function(group) { | |
| $parliament.append($("<li>").attr({ | |
| "class": group.css, | |
| "title": group.name | |
| }).text(group.shortcut)); | |
| }); |
This file contains hidden or 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
| // 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()); |
This file contains hidden or 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
| 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()); |
This file contains hidden or 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
| @Entity | |
| public class TxEntity { | |
| @Id | |
| private String id; | |
| @Parent | |
| private Ref<TxEntity> parent; | |
| @Index | |
| private String text; |
This file contains hidden or 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
| 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(''); |
This file contains hidden or 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
| 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"); |
This file contains hidden or 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
| 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(); |
This file contains hidden or 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
| 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" |