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
@botic
botic / main.js
Created April 12, 2013 15:16
WDEI Scraper
addToClasspath("./jars/jsoup-1.7.2.jar");
var Jsoup = Packages.org.jsoup.Jsoup;
var fs = require("fs");
var system = require("system");
var log = require("ringo/logging").getLogger(module.id);
var baseURI = "http://www.parlament.gv.at/";
var uebersicht = "WWER/NR/index.shtml?R_WF=FR&WP=ALLE&FUNK=ALLE&requestId=F267233B6B&M=M&LISTE=&WK=ALLE&NRBR=NR&FR=ALLE&W=W&STEP=1000&listeId=2&GP=AKT&R_PBW=PLZ&pageNumber=&FBEZ=FW_002&PLZ=&xdocumentUri=%2FWWER%2FNR%2Findex.shtml&BL=ALLE";
@botic
botic / traducator.js
Last active December 23, 2015 12:29
This script loads an underscore.js template and compiles it into a file.
/**
* This script loads an underscore.js template and compiles it into a file.
*/
var fs = require("fs");
var log = require("ringo/logging").getLogger(module.id);
var _ = require("./underscore");
var source = system.args[1];
var destination = system.args[2];
function getRandomString() {
//must start with leading 1
var allowedChars="0123456789";
var result="1";
for(var i=0; i<9; ++i) {
result += allowedChars.charAt(Math.floor(Math.random() * allowedChars.length));
}
return result;
}
@botic
botic / console.md
Last active December 31, 2015 13:59
Force a deadlock in JS – Disclaimer: The programming model of Ringo prevents this situations! This is an extreme example just to show that Ringo is indeed multithreaded JavaScript. In production you avoid this with Workers / queues and don't use shared variables.

Deadlock in bar() looks like:

> ringo deadlock.js 
thread: true
thread: false

Deadlock in foo() looks like:

importPackage(com.google.appengine.api.datastore);
// Stick configuration
var {Application} = require("stick");
var app = exports.app = new Application();
app.configure("params", "mount", "route");
var response = require("ringo/jsgi/response");
app.get("/:id", function(req, id) {
Buildfile: /Users/philipp/Documents/ringojs-master/build.xml
init:
compile:
jar:
test-dates:
[java] Sat Dec 21 2013 12:37:18 GMT-0000 (UTC)
var img = javax.imageio.ImageIO.read(new java.io.File(system.args[1]));
var rgbFilter = new JavaAdapter(java.awt.image.RGBImageFilter, {
filterRGB: function (x, y, rgb) {
return ( (rgb & 0x00000000)
| (rgb & 0xffff0000)
| (rgb & 0x00000000));
}
});
@botic
botic / filetreewalker.js
Created January 19, 2014 14:17
How to use java.nio.file in JavaScript / RingoJS
importPackage(java.nio.file);
var createVisitor = function(files, positive, path) {
return new JavaAdapter(java.nio.file.SimpleFileVisitor, {
preVisitDirectory: function (dir, attrs) {
// Directories with "_positive_" in their names are positive instances,
// with "_negative_" are negative instances.
if (path.equals(dir) || dir.toString().toLowerCase().indexOf(positive ? "_positive_" : "_negative_") >= 0) {
return FileVisitResult.CONTINUE;
} else {
@botic
botic / matlab.js
Created January 26, 2014 12:44
A simple demo how to use MATLAB in RingoJS
// Add all MATLAB libraries to the classpath
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/activation.jar");
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/activationclient.jar");
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/appmanagement.jar");
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/bde.jar");
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/beans.jar");
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/common.jar");
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/comparisons.jar");
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/deactivation.jar");
addToClasspath("/Applications/MATLAB_R2013b.app/java/jar/desktop.jar");
@botic
botic / gist:8738933
Created January 31, 2014 18:08
Sharp MATLAB on Retina MacBooks
# For a sharp UI you have to download the latest JDK for Mac OS X from Oracle
# and then replace MATLAB's outdated built-in JRE with a symlink the current one
mbp-retina:philipp$ cd /Applications/MATLAB_R2013b.app/sys/java/jre/maci64/
mbp-retina:philipp$ mv jre/ jre.original
mbp-retina:philipp$ ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/ jre