Skip to content

Instantly share code, notes, and snippets.

View vivin's full-sized avatar

Vivin Paliath vivin

View GitHub Profile
@vivin
vivin / create-efi-keys.sh
Created September 26, 2018 00:54 — forked from Era-Dorta/create-efi-keys.sh
Sign kernel modules on Ubuntu, useful for Nvidia drivers in UEFI system
# VERY IMPORTANT! After each kernel update or dkms rebuild the modules must be signed again with the script
# ~/.ssl/sign-all-modules.sh
# Place all files in ~/.ssl folder
mkdir ~/.ssl
cd ~/.ssl
# Generate custom keys with openssl
openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -subj "/CN=Owner/"
diff -r 86ed55da74ab -r ccd2e1f96817 src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
--- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Thu Dec 24 16:52:06 2015 +0530
+++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Fri Dec 25 14:16:10 2015 -0700
@@ -695,7 +695,11 @@
}
final ScriptObject sobj = (ScriptObject)obj;
final Global global = (Global)homeGlobal;
- final ScriptObjectMirror mirror = new ScriptObjectMirror(sobj, global, jsonCompatible);
+ ScriptObjectMirror mirror = Context.getMirrorForScriptObject(sobj);
+ if(mirror == null) {
diff -r 86ed55da74ab src/jdk/nashorn/api/scripting/ScriptObjectMirror.java
--- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Thu Dec 24 16:52:06 2015 +0530
+++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Fri Dec 25 13:44:36 2015 -0700
@@ -695,10 +695,15 @@
}
final ScriptObject sobj = (ScriptObject)obj;
final Global global = (Global)homeGlobal;
- final ScriptObjectMirror mirror = new ScriptObjectMirror(sobj, global, jsonCompatible);
+ ScriptObjectMirror mirror = sobj.getMirror();
+ if(mirror == null) {
@vivin
vivin / raw-global.md
Created December 8, 2015 22:39
Accessing raw global objects in nashorn

Did this while I was figuring out how to share global objects across isolated contexts. Kinda works, but not really. Prototypes are broken because the internal Global object maintains the original instance. So even after overwriting, something like Object.getPrototypeOf({}) === Object.prototype returns false... which was what I was trying to get around originally, anyway. sigh

Map<String, Object> nativeJavaScriptObjects = new HashMap<>();
try {
    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("globals", (BiConsumer<String, Object>) (s, o) ->
        nativeJavaScriptObjects.put(s, ScriptUtils.unwrap(o))
    );
    engine.eval("Object.getOwnPropertyNames(this).forEach(function(n) { if(Object.getOwnPropertyDescriptor(this, n).writable && n !== 'globals' && n !== 'javax.script.filename') { globals(n, this[n]); } }, this)");
    engine.getBindings(ScriptContext.ENGINE_SCOPE).remove("globals");
@vivin
vivin / precompiled.md
Created December 4, 2015 23:55
Nashorn: Sharing a module that maintains state amongst custom scripts that share a single script-engine instance

Probably ill-conceived and I probably won't ever need this. But just noting this down somewhere if I ever do...

Let's say you have a module or script or something that maintains state, and you have a single script-engine instance. You want each custom script to get its own instance of this module (i.e., multiple scripts executing on the engine must not step over each other's state). How do you do this? You precompile then when it's time to execute your custom script, you first execute the precompiled script. Then you copy everything it exposes into your custom script's context. Snippet:

//Precompile the modules and put them in a map
private void compileModule(String name, String source) {
    try {
        this.engine.put(ScriptEngine.FILENAME, String.format("<%s>", name));
        this.compiledModules.put(name, ((Compilable) this.engine).compile(source));
import java.util.regex.*;
public class TestTypePerf {
public static String[] strs = {"44.1925956958102", "99", "T", "O", "75", "17.7747699189673", "3.43861289673129", "F", "6.39912778270002", "V", "26.6601956962901", "B", "72.6802220159072", "Z", "3", "8.9645758490569", "R", "N", "Q", "48.0695153483985", "43.5522445419224", "S", "54.4839551827764", "31.8343354598476", "R", "41.6520872409031", "83", "L", "81.5650587149719", "P", "K", "16", "90", "79.7439904639027", "6", "16.3558040397525", "9.65567571829524", "R", "D", "79", "92", "86.9899381753619", "0.617880093231804", "A", "Y", "77", "52.3386894116427", "22.2886909059007", "24", "40", "24.5588443830783", "97", "13", "97", "56", "72", "Q", "D", "52", "78", "73", "J", "91.9631873108031", "84.4294768652212", "84", "96", "90", "15", "83.3975671235066", "70", "42.6729780387419", "E", "O", "D", "96", "95", "C", "89.8910746595028", "93.0115059109838", "46", "18", "D", "P", "63", "55.3791732145669", "50", "Y", "68", "A", "D", "Z", "5", "O", "T", "Z", "26", "A
#!/bin/sh
PANCAKES_VERSION=1.1.6.10
if [ -z $1 ]; then
echo "Usage: $0 ARTIFACT_NAME" >&2
exit 1
fi
artifact=$1