Hi, I have the following ClojureScript code to get the set of all loaded fonts:
(->> js/document .-fonts .entries (map #(.-family (first %))) set)
.entries returns JS iterator object.
It works perfectly fine in Chrome, but I am getting the following error on iOS Safari:
Execution error (Error) at (<cljs repl>:1).
[object FontFace] is not ISeqable
Of course I can rewrite it directly using JS interop. But is this a bug in ClojureScript compiler? Or is there some other idiomatic way to write this code?I’d look at documentation and the stack trace. My guess is that family is returning a single fontface either due to differences in how the browser works or different fonts loaded in the browsers
ok, so I checked further and the error is unrelated to JS iterator object
for whatever reason Chrome returns an array with two FontFace (hence using first), but Safari returns just a single FontFace
From which call? Fonts or family?
each value returned by iterator is array of two font-faces
in the end, I tested the map solution and it does not work in FF, screw this browser stuff ...
but I ended up with this code which seems to work everywhere
(defn- find-all-loaded-fonts
"Iterates through all loaded fonts and construct a set of their font families."
[]
(reduce (fn [[fonts it] _]
(let [next (.next it)]
(if (.-done next)
(reduced fonts)
(let [next-value (.-value next)
next-font (if (instance? js/FontFace next-value)
(.-family next-value) ; For Safari
(-> next-value first .-family))] ; For Chrome
[(conj fonts next-font) it]))))
[#{} (->> js/document .-fonts .entries)] (range)))
I’m in the process of switching over to CircleCI for deploying my site to my raspberry pi.
I’m using it as it seems to be a tad more flexible than gitlab CI. The trouble I’m having is getting ssh to work.
Now usually I would do something like ssh-copy-id
on my main machine so I can log in. Now CircleCI instructs to take the private key and add it via project settings -> SSH Keys -> Additional SSH Keys -> Add SSH Key
. Then in the yaml put add_ssh_keys
as one of the steps in my deployment job.
Great in theory, but it doesn’t work. Am I missing something important?
Maybe another helpful detail is, I’ll ultimately use rsync to transfer over the files over SSH. I did some searching and apparently there are problems with scp, which I used before.
I tested rsync from my laptop, and it seems to transfer everything over just fine.
how can I add additional dependencies when using cloure -M:…
? I am habitually trying out libraries using a nice repl (i.e. rebel-readline), for which i have the following alias defined:
{:rebel
{:extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}}
:main-opts ["-m" "rebel-readline.main"]}}
This lets me try out datahike for example via clojure -A:rebel -Sdeps '{:deps {io.replikativ/datahike {:mvn/version "0.3.6"}}}'
. However, there's a deprecation warning that :main-opts
shouldn't be used with clojure -A
, clojure -M
should be used instead. When using clojure -M:rebel
, rebel-readline gets started lilke before, but (require '[datahike.api :as d])
fails because it can't find the dependencyThe latter should be correct, but you need to make sure to put -Sdeps before -M
Otherwise it becomes args to main
I have output string below
{\"email\":\"<mailto:popeye@gmail.com|popeye@gmail.com>\",\"user\":\"popeye\",\"domain\":\"<http://gmail.com|gmail.com><mailto:popeye@gmail.com|popeye@gmail.com>\",\"user\":\"popeye\",\"domain\":\"<http://gmail.com|gmail.com>\",\"status\":\"valid\",\"reason\":\"The email address is valid.\",\"disposable\":false}
how can i get the values from email
and status
How should the result look like?
Use Clojure data json
(Json/read-str “{\”a”\”:1,\”b\”:2} Output would be like —> {“a” 1, ”b” 2}
(get map key)
@delaguardo like below
{"email":"<mailto:name@example.com|name@example.com>" "user":"name" "domain":"http://example.com" "status":"invalid" "reason":"No mail server for <mailto:name@example.com|name@example.com>" "disposable":false }
then just read that string using any json reader. most likely they will return a map like you just describe
will try
clojure data.json I guess should be the first one to try
So I’m going through Clojure for the Brave and True, and I was wondering if there was some way that I could use the REPL to see what the value is of each of the symbols when I run it? Sometimes it’s hard to understand what’s going on, but I think it would be easier if I could tell what each “part” and “remaining” is and see how it’s executed.
Thank you! This is all super helpful
I’ll play around with these
you might look at the Scope Capture tool: https://github.com/vvvvalvalval/scope-capture
you could also step through it with a debugger
A simple way would be to declare an atom outside the function scope and store the intermediate values there.
there's also tap>
. and also inline def
(although that will get stomped on successive executions)
or! just println
tap>
is good for that
Hi. Does anyone know where you are supposed to point the javascript line in index.html
for a webapp if you are using a build tool that has multiple kinds of output?
Maybe the multiple possible build targets (I'm most concerned with dev vs production for now, but mobile later) are supposed to have the same target folder for their JS output?
I am trying to get a bare minimum webapp built with shadow-cljs (on WSL2 Ubuntu 20.04 if that matters).
So far I installed ClojureScript and npm and shadow-cljs, and I have created a project folder and in it run
npx create-cljs-project my-project
(as mentioned in https://shadow-cljs.github.io/docs/UsersGuide.html#_standalone_via_code_npm_code ).
I'm having real trouble trying to follow the shadow-cljs User Guide beyond that, but I did, after poring through the giant file structure the command above creates, find out none of that contains the absolute basics of a webapp (index.html and maybe some CSS), so I manually created a 'public' folder with index.html in it, and 'css' and 'js' subfolders.A desk top app? I think you should have an idea of how you want to produce it first e.g are you doing to use electron?
Most web development targets the browser, so that's what I assumed you were doing
I am targetting the browser at first, to try to get something together (I think Reagent+Hiccup are called for for that but I just want to do some hot reload magic first). ...then I would like to try getting the same app runing stand-alone on desktop (not sure if I should look into cljc files (and branching with some Clojure code) or just node (shadow-cljs with a different target?)). ...and later also mobile (Reagent needed? and an extra piece ReactNative? Alternatively I've heard of NativeScript but that was a long while ago).
Is there a more idiomatic way to write (if f (f x) nil)
?
(when f (f x))
?
(if f (f x))
From the quick start docs https://github.com/thheller/shadow-cljs#quick-start Given a shadow-cljs.edn with the following data:
{...
:builds
{:frontend
{:target :browser
:modules {:main {:init-fn <http://acme.frontend.app/init|acme.frontend.app/init>}}
}}}
> This config tells the compiler to call `(http://acme.frontend.app/init)` when the generated JS code is loaded. Since no `:output-dir` is configured the default `public/js` is used.
So in your root directory, when you run npx shadow-cljs watch frontend
it will target
the browser
and create a js code bundle based on the keyword you supply to the module
hashmap. In this case :main
becomes main.js (or thats what i recall) so you should have a public/js/main.js
Now thats a development built (not minified, optimized, etc..) so likely you want to create a production build to.
That and more is covered here in official guide: https://shadow-cljs.github.io/docs/UsersGuide.html#releaseerr also try #shadow-cljs for other shadow-cljs related questions.
@drewverlee Thanks. I'll re-read that tonight when I get at this again. 🙂 I thought of posting my question in the shadow-cljs channel, by the way, but I thought it might be more of a general question.