Doorgaan naar hoofdcontent

Posts

Posts uit 2021 tonen

Windows batch scripting god ( java runtime switch)

 I am a batch scripting god. After a lot of pain, I managed to create a script which allows me to switch jvm's easily. For posterity, and my own flex skills, the script: @echo off rem set your local path to all the JVM's here. set jvmdir=c:\code\apps\jvms if NOT EXIST %jvmdir% goto invaliddir rem a little bit of manipulation rem first we remove everything before the jvms dir call set __temp=%%path:*%jvmdir%\=%% rem then we determine everything that follows after the next slash set __lastbit=%__temp:*\=% rem then we remove that lastbit, leaving only the entire directory and a \ at the end. call set __currentpath=%%__temp:%__lastbit%=%% rem then we remove the \ at the end set __currentjvm=%__currentpath:\=% if "%~1"=="" goto missingarg if NOT EXIST %jvmdir%\%1 goto unknowndir set __currentpath=%jvmdir%\%__currentjvm% set __replacement=%jvmdir%\%1 call SET path=%%path:%__currentpath%=%__replacement%%% CALL SET JAVA_HOME=%%JAVA_HOME:%__currentpath%=%__replacemen...

Java sux with regexes

 Java supports regexes right? Nothing to it! that is so nice about it Only after 15 years, I find out that it does have performance problems. https://bugs.java.com/bugdatabase/view_bug.do?bug_id=5050507  Is a bug for regexes in java. Of course, they're rare. But how did I hit it? Well, doing stuff you shouldn't of course. In this case, parsing Json, by searching for a value of a certain key. That's straightforward, right? "key"\s:\s"([^"]+)" Well, it would be nice like that, but there's this tiny exception... the value can contain quotes as well. Okay, so we exclude them. Numerous posts tell you how to do it. The trick is to use an or, in essence saying: 'the string \" OR any character which is not a "`  We can see that in action  here All languages support it.   but.... not java. No, it has problems with these groups. It gives stack overflows. And it's a known fact. So, is this the end? I thought so. But then, I started diggi...