This file contains 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
// nudge4j - bootstrap | |
try { | |
new javax.script.ScriptEngineManager() | |
.getEngineByName("JavaScript") | |
.eval("load('http://lorenzoongithub.github.io/nudge4j/twigs/n4j.boot.js')"); | |
} catch (javax.script.ScriptException e) { | |
throw new RuntimeException(e); | |
} |
This file contains 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
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. | |
* |
This file contains 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
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); |
This file contains 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
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"); | |
// |
This file contains 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
// | |
// 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'); |
This file contains 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 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>'; |
This file contains 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
// | |
// 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'+ |
This file contains 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
// | |
// 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; |
This file contains 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
// | |
// 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); |
This file contains 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
// | |
// 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; |
NewerOlder