Fork me on GitHub
#clojure
<
2020-03-20
>
kenny00:03:59

Does anyone know of a complete parser for the https://www.ietf.org/rfc/rfc3339.txt date format? There are so many caveats to the format and all the examples I've found online seem to fail.

kenny00:03:53

I got pretty close with "yyyy-MM-dd'T'HH:mm:ss[.SSS]ZZZZZ" pattern + parseBest but rfc3339 includes leap seconds which means seconds can go to 60 and causes it to fail 😞

hiredman00:03:29

Leap seconds are only valid at certain times, the end of June or December, have you been testing your parsering with date times where leap seconds are valid?

kenny00:03:22

Testing with 1990-12-31T15:59:60-08:00

kenny00:03:37

Execution error (DateTimeException) at java.time.temporal.ValueRange/checkValidIntValue (ValueRange.java:330).
Invalid value for SecondOfMinute (valid values 0 - 59): 60

kenny00:03:27

> java.time does support the parsing of a (valid) leap second.

kenny00:03:39

I think this works!

(.withResolverStyle
  (DateTimeFormatter/ofPattern "yyyy-MM-dd'T'HH:mm:ss[.SSS]ZZZZZ")
  ResolverStyle/LENIENT)

kenny00:03:23

For those interested, this is the final code that seems to work with all my examples

(def rfc-3339-formatter
  (.withResolverStyle
    (DateTimeFormatter/ofPattern "yyyy-MM-dd'T'HH:mm:ss[.SSS]ZZZZZ")
    ResolverStyle/LENIENT))

(defn parse-rfc-3339-to-instant
  [date-string]
  (-> (LocalDateTime/parse date-string rfc-3339-formatter)
      (.atZone (ZoneId/of "UTC"))
      (.toInstant)))

Eddie01:03:23

I'm trying to use cheshire to create a JSON lines dataset. I wrote a working function that I am reasonably happy with.

(defn write-jsonl
  [rows writer]
  (doseq [row rows]
    (ch/generate-stream row writer {:escape-non-ascii true})
    (.write writer "\n")))
Does anybody know if there is a cleaner way to get the newline rather than a separate call to .write ? Perhaps a cheshire option that I can't find in the docs?

Jessie R06:03:30

Hi, I am looking at spec-ing some code and I wanted to make a set extensible; (s/def ::type #{:local-file :s3}) such that in another file, I could add on another type e.g. :sftp

Jessie R06:03:37

Is there a way to do this?

souenzzo13:03:43

Just use keyword?

miro09:03:01

Hello everyone! Just trying my luck here: has anybody successfully enabled OS X clojure build via Travis CI/CD? Seems like they only support linux and win out of the box... Edit: made it work if anyone is interested - just needed to add leiningen into addons: seems quite simple, so I am not sure why Travis states: "Clojure builds are not available on the macOS environment."

language: clojure
  
matrix:
  include:
    - os: osx
      jdk: openjdk11
      addons:
        homebrew:
          packages:
          - leiningen
          update: true

grzm13:03:28

I have a project which has a deps.edn dependency to a private http://github.com repo, Clojure deps is failing to pull the dependency with:

Cloning: [email protected]:grzm/psycho-roll.git
Error building classpath. [email protected]:grzm/private-repo.git: invalid privatekey: [B@1653b84e
org.eclipse.jgit.api.errors.TransportException: [email protected]:grzm/private-repo.git: invalid privatekey: [B@1653b84e
Seems like it’s an issue with my SSH keys, but I’m a bit puzzled as I can clone this same dependency from http://github.com from the command line with git clone without any problem, and the necessary keys show up when using ssh-add -l. Hints on what I might be doing wrong?

souenzzo13:03:42

Try #tools-deps channel But i know that by design, all auth settings are on git.

grzm14:03:02

Thanks for the pointer to the #tools-deps channel 🙂

Eduardo Mata13:03:47

I have a vector of one or two map elements [{:x 'x} {:y y}] and I would like to create a replica of those two maps and append them to an accumulator vector. I primarily iterate to each one of them and append it to the acc-vector such as (map #(swap! acc-vector conj (do-something %)) original-vector). Is there an actual function for this? if not then I keep this approach

vlaaad14:03:46

you are mixing lazy sequences (map) with side effects (swap!), this is very very bad

vlaaad14:03:28

use run! instead of map

Eduardo Mata14:03:56

great recommendation

Eduardo Mata14:03:05

Because we are talking about this, I am using async and I use map. Should I use run! instead for the following example?

(defn upsert-legs!
  [legs]
  (let [leg-chan (chan 1024)
        match-chan (chan 1024)
        upsert-chan (chan 1024)]
    (onto-chan leg-chan legs)
    (pipeline-blocking 16 match-chan (map match-leg) leg-chan)
    (pipeline-blocking 16 upsert-chan (map upsert-leg!) match-chan)))

vlaaad14:03:48

ah, thats not lazy sequences, thats transducers

keymone15:03:04

hey folks, i get this reflection error when trying to call static method like this: (Cls/foo ...), any way i can unconfuse reflection machinery to see that it's Cls being called, not xyz.core$eval6024? Cls is gen-classed in another namespace if that matters

darwin15:03:10

I’m writing a simple transpiler, in first step I parse original source into clojure datastructures and then in second step I take that data and emit output text. The problem is that my data is a deeply nested structure containing lazy sequences (produced by map, etc.) and when the structure is realized during emit I might get some errors/exceptions. And for that I would need some context info to print meaningful error messages. I didn’t want to pass context explicitely down through all the calls. I wanted to use something like binding to set some context at the top level and use it later when I hit exceptional state. Any ideas how to do that?

darwin15:03:27

currently I opted in forcing recursive realization of the datastructure (using doall) at some well defined points and with dynamic binding to set current context info, but that has some issues

borkdude15:03:46

What is a way to read transit from stdin while only relying on core or standard Java features?

$ echo "{:a 1}" | jet --to transit | ./bb '(transit/read (transit/reader ... :json))'

darwin15:03:12

System/in is InputStream, you should be able to use it for reading

borkdude15:03:38

yay, that worked!

$ echo "{:a 1}" | jet --to transit | ./bb '(transit/read (transit/reader System/in :json))'
{:a 1}

borkdude15:03:08

thanks. that's good to know

jjttjj16:03:44

anyone have a good reference handy for a macro that is a def-function-like? Ie parsing dosctring and arities

borkdude16:03:34

clojure.core/defn?

borkdude16:03:24

not sure what you need, but if you're looking for code that parses an expression like defn does, it might be good at the code for defn

jjttjj16:03:35

good point actually there's a lot in clojure.core, I'll check out sci next, thanks!

jjttjj16:03:05

(I just stole the destructure implementation in sci for something else actually) 🙂

borkdude16:03:26

that implementation was stolen from clojure.core in the first place

jjttjj16:03:59

yeah I figured

borkdude16:03:15

a combination of clojure.core and cljs.core actually. sometimes I find the code in cljs.core a little bit clearer

jjttjj16:03:21

I didn't actually look how close they were. Just needed it to work on pure cljs

borkdude16:03:46

then you might as well copy it from clojurescript

keymone17:03:59

Any ideas about the reflection issue above?

mjw17:03:04

If you import the relevant Java class (e.g., ExpectedFooClass), you can provide a hint to your function call: (CIs/foo ^ExpectedFooClass foo)

mjw17:03:13

Alternatively, if foo is being passed in as an argument, you can provide the hint there:

(defn foo-wrapper [^ExpectedFooClass foo]
  (CIs/foo foo))

keymone17:03:56

the problem is somehow in Cls/foo itself. it's static method inherited from ClsSuper/foo and it's looking up the caller stack to make sure Cls extends ClsSuper but somehow fails that check. clojure uses invokeStatic to call Cls/foo and that makes it not be in the stacktrace somehow? i don't know..

keymone17:03:12

at com.almasb.fxgl.app.GameApplication.launch(GameApplication.java:62) at xyz$eval6024.invokeStatic(form-init1514362494284450037.clj:19) supposedly there should be a line with Cls.launch in between here, right?

keymone17:03:36

GameApplication is the "ClsSuper" here

keymone17:03:40

no of course there shouldn't be, i don't override .launch

noisesmith18:03:51

I strongly suspect that if the lib relies on implementation details of how java implements inheritance and superclass method invocation, the simplest and least error prone thing is to write a java stub that invokes clojure functions in all its method bodies

noisesmith18:03:47

each method would use clojure.java.api.Clojure to look up an ns and call a function https://clojure.org/reference/java_interop#_calling_clojure_from_java

noisesmith18:03:00

or just write it all in java if that's easier

keymone12:03:11

just in case anybody else stumbles across this, the problem was in implicit assumption that caller of .launch is a class that extends a certain super, which it is not if .launch is invoked directly from clojure code

👍 4
Nico17:03:30

hello! What is the current state of clojure development for android?

adamfeldman17:03:03

If you’re looking for UI-building tools, these are the two I’m aware of : https://github.com/fulcrologic/fulcro-native, https://github.com/drapanjanas/re-natal

adamfeldman17:03:22

(both based on React Native)

Nico17:03:50

so it's cljs/react rather than clj/java?

Nico17:03:35

how different is it to work with as somebody only used to desktop java clojure?

mruzekw18:03:44

I’d assume very. But I’m assuming desktop java clojure involves a lot of imperative code. Do you use a particular library or framework for desktop java/clojure UI dev?

Nico18:03:56

well, I mostly write CLI apps on the desktop, but I've used seesaw for UI in the past

Nico18:03:57

I'm mostly thinking in terms of actual language differences/workflow

lilactown18:03:20

react native is pretty different in terms of work flow

lilactown18:03:11

there’s a whole other React Native toolchain you use, along with the ClojureScript toolchain

lilactown18:03:14

that being said, it’s pretty useful to know. you can currently build UIs for windows, macOS, iOS and Android with React Native, and it gets more feature complete and advanced as time goes on

Nico18:03:46

is cljs + react native the current best way to build clojure apps for android then?

lilactown18:03:26

yes, i would say so

lilactown18:03:04

fundamentally, getting clojure to run on android is difficult; there are differences between mainstream JVMs and the android runtime. and the Clojure startup time is a big UX problem on smaller devices

Nico18:03:03

alright, thanls

fricze11:03:56

If you only worked with Java, adjusting to JavaScript as host might require some learning. That being said React Native + shadow.cljs is becoming really nice app-development platform. Resulting applications also work quite nice, and there’s more and more useful bridges to native code. The biggest problem, probably, is that you’re gonna have to read documentations and issues of JavaScript tools, you might not be familiar with