View xr.js
function xr(oj, name) {
var arrayLength = java.lang.reflect.Array.getLength;
var isStaticField = function(field) {
return java.lang.reflect.Modifier.isStatic(field.getModifiers());
}
/**
* Returns true if the input appears to represent a Class, false otherwise.
*
View toString.js
function toString(oj) {
if (oj == null) return 'null';
if (Java.isJavaObject(oj)==false) return 'Error: not a Java Object';
try {
java.lang.Class.forName('org.apache.commons.lang3.builder.ReflectionToStringBuilder');
} catch (e) {
var url = new java.net.URL('http://central.maven.org/maven2/org/apache/commons/commons-lang3/3.0/commons-lang3-3.0.jar');
var ucl = java.lang.Class.forName('java.net.URLClassLoader');
var addURL = ucl.getDeclaredMethod("addURL", [ url.getClass() ]);
addURL.setAccessible(true);
View DemoNudge4J.java
package test;
/**
* nudge4j's demo: A stand alone Java 8 program that you can just run.
**/
public class DemoNudge4j {
public static void main(String args[]) {
System.out.println("Demo nudge4j");
//
View nudge4j.PNGEncoder.java
//
// PNG Encoder. This script requires okio.jar
//
var URL = Java.type('java.net.URL');
var ByteString = Java.type('okio.ByteString');
var Okio = Java.type('okio.Okio');
var Buffer = Java.type('okio.Buffer');
var url = new URL('http://i936.photobucket.com/albums/ad204/0_Marathon_0/Abstract.png');
View nudge4j.memory.java
var mem = java.lang.management.ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
var usd = Math.round( mem.getUsed() / 1048576 )
var cmt = Math.round( mem.getCommitted() / 1048576 )
var max = Math.round( mem.getMax() / 1048576 )
'<div style="font-family:monospace;margin:2%;border-bottom:1px solid #333; border-left:1px solid #333; border-right:1px solid #333">'+
'<div style="border-top:1px solid #333"><div style="width:'+(usd*100/max)+'%;background-color:#dcd;">used:'+usd+'MB</div></div>'+
'<div style="border-top:1px solid #333"><div style="width:'+(cmt*100/max)+'%;background-color:#ddd;">committed:'+cmt+'MB</div></div>'+
'<div style="border-top:1px solid #333"><div style="width:100%; background-color:#ddd;">max:'+max+'MB</div></div></div>';
View nudge4j.lambda.in.java.8.java
//
// Using Lambda in java 8
// Inspired by https://blogs.oracle.com/nashorn/entry/nashorn_and_lambda_what_the
//
var copyright =
'/* \n'+
' * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. \n'+
' * \n'+
' * Redistribution and use in source and binary forms, with or without \n'+
View nudge4j.threads.java
//
// Prints all threads
//
var threads = java.lang.Thread.getAllStackTraces().keySet().toArray();
var str ='';
for (var i=0;i<threads.length;i++) {
str+=threads[i]+' - '+threads[i].getState()+'\n';
}
str;
View nudge4j.localdate.java
//
// An example of java 8 new Date/Time API.
//
var LocalDate = Java.type('java.time.LocalDate');
var Month = Java.type('java.time.Month');
var ChronoUnit = Java.type('java.time.temporal.ChronoUnit');
var today = LocalDate.now();
var firstDayThisYear = LocalDate.of(today.getYear(), Month.JANUARY, 1);
View mailcheck.js
//
// https://github.com/mailcheck/mailcheck
//
load('https://cdn.jsdelivr.net/mailcheck/1.1/mailcheck.min.js');
Kicksend.mailcheck.run({email:'lo@hotmail.cmo',suggested:function(oj) { x = oj; }});
x;
View numeric.js
//
// http://www.numericjs.com/
//
load('http://www.numericjs.com/lib/numeric-1.2.6.min.js');
a = [[1,2,3],
[4,5,6],
[7,3,9]];