This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-06
Channels
- # babashka (60)
- # beginners (36)
- # clj-kondo (29)
- # clojure (91)
- # clojure-dev (18)
- # clojure-europe (12)
- # clojure-nl (1)
- # clojure-norway (11)
- # clojure-uk (5)
- # clojuredesign-podcast (8)
- # clojurescript (40)
- # core-typed (74)
- # data-science (8)
- # datomic (9)
- # emacs (22)
- # events (5)
- # fulcro (56)
- # gratitude (3)
- # hyperfiddle (11)
- # lsp (6)
- # malli (36)
- # meander (23)
- # off-topic (50)
- # polylith (4)
- # portal (10)
- # reitit (4)
- # schema (1)
- # shadow-cljs (66)
- # squint (3)
- # tools-deps (16)
Hi! I am trying to find an easy way to decode the following "<DESCRIPTION><p>There are errors logged in the Gateway</DESCRIPTION>"
where <
is <
and etc. I can remap characters and go over them one by one but there is a chance that I will miss some. Any tips?
Those are called "HTML entities", you can use any Java solution for it.
Don't go one by one because the list is big if you need to support full Unicode and entity composition, like e.g. "ô"
producing "ô"
.
So you are trying to decode HTML entities?
@U06M77WEDA8 Please don't check the "Also send to" checkbox unnecessarily.
Regarding the code - what is the str
alias? The clojure.string
namespace doesn't have unescape-html
.
You are correct that there is no unescape-html
function in the clojure.string
namespace in Clojure.
On a more serious note, we are happy to have you here learning and answering questions. We have no interest in a bot that just relays (wrong) information from an LLM
I'm not sure there is any utility in the JDK for this these days, but certainly you can use StringEscapeUtils in org.apache.commons:commons-text
Its been deprecated though. I made it work by nesting the string in xml and used clojure.data.xml/parse-str
then extracted the transformed string from the resulting data structure. But this seems like a dirty hack to me not a proper solution
why do you say it's been deprecated?
latest https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringEscapeUtils.html#unescapeHtml4(java.lang.String) does not say that
I opened https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringEscapeUtils.html by mistake
According to the *<https://clojuredocs.org/clojure.core/*data-readers*|data-readers>* documentation... > _“Default reader tags ... may be overridden in data_readers.clj, data_readers.cljc, or by rebinding this Var.”_ Is there a way to tell Clojure to use a separate file other that `data_readers.clj`?
you could load a different file and rebind I suppose
Lol, I thought not! And yes, that’s the fallback solution that we’re looking at ☝️:skin-tone-6:
I found this amazing way to find an element in a vector here (https://stackoverflow.com/questions/10192602/return-first-item-in-a-map-list-sequence-that-satisfies-a-predicate)
(some #{1} [1 2 3 4])
Can this method can be applied to something like below?
[{:a 1 :b 2}
{:a 3 :b 4}
{:a 5 :b 6}]
something like below seems to work, but it seems ugly. so, yes, first
and filter
combo may be the best option.
(some #(when (= (:a %) 3) %) [{:a 1 :b 2}
{:a 3 :b 4}
{:a 5 :b 6}]))
(some (comp #{3} :a) [{:a 1 :b 2} {:a 3 :b 4} {:a 5 :b 6}])
is another way to write that as well
Err thats not quite right, yeah you would want to use first
and filter
with that strategy
OK, got it, yes I tried it and got:
; eval (current-form): (some (comp #{3} :a) [{:a 1 :b 2} {:a 3 :b 4} {:a 5 :b 6}])
3
Java / JNI interop problem. I'm running (new X11$XWindowAttributes)
but get the response Attempting to retrieve VisualID from a null Visual
.
jshell --class-path ~/.m2/repository/net/java/dev/jna/jna-platform/5.9.0/jna-platform-5.9.0.jar:~/.m2/repository/net/java/dev/jna/jna/5.9.0/jna-5.9.0.jar
jshell> X11.XWindowAttributes xwa = new X11.XWindowAttributes();
xwa ==>
project.clj contains:
:dependencies [[org.clojure/clojure "1.10.3"]
[net.java.dev.jna/jna "5.9.0"]
[net.java.dev.jna/jna-platform "5.9.0"]]
Most of the other functions work fine. For example
(def dpy (.XOpenDisplay x ":1"))
;#object[com.sun.jna.platform.unix.X11$Display 0x594886ab "native@0x7f47980c0df0 (com.sun.jna.platform.unix.X11$Display@980c8d37)"]
I would check to see if it's because the repl isn't running on the main thread
or the context where it's not working
You can get the current thread with (Thread/currentThread)
I don't have a linux repl handy, but you can check it's (.name (Thread/currentThread)) or .id
or maybe just calling .toString on the thread will give you some indication
(.getName (Thread/currentThread)) => "nREPL-session-9a7c37db-a933-4032-82f3-621866db77c4"
I know swing has a way to run code on the main thread. not sure about AWT directly?
I think I've suggested that mucking around with AWT internals lies madness, but it seems like you're committed, so I won't to try to convince you otherwise.
I don't remember your exact project, but you might also be interested in https://github.com/HumbleUI/JWM/
wait, JNA or JNI?
for JNA, you don't use the constructor, you use Structure/newInstance
@U0NCTKEV8 here's the entire thing:
; eval (current-form): (new X11$XWindowAttributes)
; (err) Error printing return value (IllegalStateException) at com.sun.jna.platform.unix.X11$Visual/getVisualID (X11.java:274).
; (err) Attempting to retrieve VisualID from a null Visual
not much more thereFrom the repl prompt:
clj-x11.work=> (new X11$XWindowAttributes )
Error printing return value (IllegalStateException) at com.sun.jna.platform.unix.X11$Visual/getVisualID (X11.java:274).
Attempting to retrieve VisualID from a null Visual
How would I get more info out?oh, I would still consider that to be mucking around with AWT internals. I thought you might be using JNA to make your own interface to X11
@U7RJTCH6J JNA. I'll check out that project!
#error {
:cause "Attempting to retrieve VisualID from a null Visual"
:via
[{:type clojure.lang.ExceptionInfo
:message nil
:data #:clojure.error{:phase :print-eval-result}
:at [clojure.main$repl$read_eval_print__9110 invoke "main.clj" 442]}
{:type java.lang.IllegalStateException
:message "Attempting to retrieve VisualID from a null Visual"
:at [com.sun.jna.platform.unix.X11$Visual getVisualID "X11.java" 274]}]
:trace
[[com.sun.jna.platform.unix.X11$Visual getVisualID "X11.java" 274]
[com.sun.jna.platform.unix.X11$Visual toString "X11.java" 278]
[java.lang.String valueOf "String.java" 4225]
[com.sun.jna.Structure toString "Structure.java" 1607]
[com.sun.jna.Structure toString "Structure.java" 1555]
[com.sun.jna.Structure toString "Structure.java" 1546]
[clojure.core$str invokeStatic "core.clj" 555]
[clojure.core$print_object invokeStatic "core_print.clj" 117]
[clojure.core$fn__7297 invokeStatic "core_print.clj" 120]
[clojure.core$fn__7297 invoke "core_print.clj" 120]
[clojure.lang.MultiFn invoke "MultiFn.java" 234]
[nrepl.middleware.print$pr_on invokeStatic "print.clj" 21]
[nrepl.middleware.print$pr_on invoke "print.clj" 17]
[nrepl.middleware.print$send_nonstreamed$print_key__1169$fn__1170 invoke "print.clj" 148]
[nrepl.middleware.print$send_nonstreamed$print_key__1169 invoke "print.clj" 147]
[clojure.core$map$fn__5880$fn__5881 invoke "core.clj" 2746]
[clojure.core.protocols$iter_reduce invokeStatic "protocols.clj" 49]
[clojure.core.protocols$fn__8162 invokeStatic "protocols.clj" 75]
[clojure.core.protocols$fn__8162 invoke "protocols.clj" 75]
[clojure.core.protocols$fn__8110$G__8105__8123 invoke "protocols.clj" 13]
[clojure.core$transduce invokeStatic "core.clj" 6886]
[clojure.core$transduce invoke "core.clj" 6872]
[nrepl.middleware.print$send_nonstreamed invokeStatic "print.clj" 156]
[nrepl.middleware.print$send_nonstreamed invoke "print.clj" 138]
[nrepl.middleware.print$printing_transport$reify__1186 send "print.clj" 174]
[nrepl.middleware.caught$caught_transport$reify__1221 send "caught.clj" 58]
[nrepl.middleware.interruptible_eval$evaluate$fn__1287 invoke "interruptible_eval.clj" 123]
[clojure.main$repl$read_eval_print__9110 invoke "main.clj" 442]
[clojure.main$repl$fn__9119 invoke "main.clj" 458]
[clojure.main$repl invokeStatic "main.clj" 458]
[clojure.main$repl doInvoke "main.clj" 368]
[clojure.lang.RestFn invoke "RestFn.java" 1523]
[nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 84]
[nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 56]
[nrepl.middleware.interruptible_eval$interruptible_eval$fn__1297$fn__1301 invoke "interruptible_eval.clj" 152]
[clojure.lang.AFn run "AFn.java" 22]
[nrepl.middleware.session$session_exec$main_loop__1367$fn__1371 invoke "session.clj" 218]
[nrepl.middleware.session$session_exec$main_loop__1367 invoke "session.clj" 217]
[clojure.lang.AFn run "AFn.java" 22]
[java.lang.Thread run "Thread.java" 1589]]}
@U7RJTCH6J That's what I'm trying to do. Bypass AWT.
Ok, maybe I will try to convince against this. Using the internal APIs from the JDK is a walking into a den of footguns: • it's very undocumented • there will be lots of rough edges which will randomly break without any clear indication as to why • if you do manage to get it working, it's likely coupled to a specific version of the JVM and will break even with minor version changes.
@U0NCTKEV8 thanks a million. Those will be some helpful tools going forward.
I hope I'm not using internals. I haven't bypassed anything. This is just the public JNA interface.
@U7RJTCH6J is likely reacting to the package prefix of com.sun which is often used for internal stuff on the jvm
do you have a link to the library you're using?
https://github.com/java-native-access/jna is I think where both of those jna artifacts come from
Looking directly at https://github.com/java-native-access/jna/blob/83f2fc875e736308f418e8e99ff714ec054d8af4/contrib/platform/src/com/sun/jna/platform/unix/X11.java
yea, my guess is that you're probably not supposed to instantiate an X11WindowsAttribute directly , but are supposed to use some method to either create one or get the current one.
From other X11 code, you'd create an empty XWA, then call a function to populate it. Very C-style.
it is because printing the structure calls toString on it, which calls toString on all its fields, and calling toString on the visual id field doesn't like it that the visual id field is null
If I can get any Java-friendly image format into an X11 pixmap, that'll be just about everything I need to get going.
oh, I guess you can instantiate it. It's likely what @U0NCTKEV8 said, https://github.com/Chrriis/DJ-Native-Swing/blob/99666a095df1bd51211dc06879c394aee6aa48cf/DJNativeSwing/src/chrriis/dj/nativeswing/jna/platform/WindowUtils.java#L1424C1-L1424C20
I would heavily lean on http://grep.app to help find examples, https://grep.app/search?current=2&q=XWindowAttributes&filter[lang][0]=Java
I hadn't seen http://grep.app before. That's fantastic!
I have a working example here: https://github.com/java-native-access/jna/blob/83f2fc875e736308f418e8e99ff714ec054d8af4/contrib/platform/src/com/sun/jna/platform/WindowUtils.java#L1808
🤯 I drew my avatar's .png to a foreign window! I'm over the moon! That's the proof of concept! The rest is just normal work 😆
I felt like if Python can do it, surely Clojure/Java can https://alvinalexander.com/python/python-screensaver-xscreensaver-linux/