This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-27
Channels
- # announcements (2)
- # babashka (60)
- # beginners (73)
- # calva (23)
- # cider (2)
- # clj-kondo (19)
- # cljs-dev (31)
- # clojure (29)
- # clojure-berlin (1)
- # clojure-europe (6)
- # clojure-nl (17)
- # clojure-spec (21)
- # clojure-uk (15)
- # clojurescript (54)
- # core-async (48)
- # cursive (35)
- # datomic (12)
- # emacs (12)
- # fulcro (66)
- # graalvm (3)
- # graphql (16)
- # jackdaw (1)
- # malli (1)
- # off-topic (11)
- # pedestal (4)
- # re-frame (10)
- # reitit (1)
- # rewrite-clj (8)
- # ring-swagger (8)
- # shadow-cljs (14)
- # spacemacs (2)
- # vim (5)
@holyjak I'm looking at your nio example now:
(do
(.createNewFile (io/file "/tmp/f1"))
(let [p (.toPath (io/file "/tmp/f1"))
p' (.resolveSibling p "f2")]
#_(try
(java.nio.file.Files/move p p' (into-array java.nio.file.CopyOption []))
(println "Target file did not exist and move succeeded")
(catch java.nio.file.FileAlreadyExistsException _
(println "Target file already exists, going to force it...")
(java.nio.file.Files/move p p' (into-array [java.nio.file.StandardCopyOption/REPLACE_EXISTING]))))))
This works:
$ lein bb /tmp/nio.clj
But for the native one I get:
$ ./bb /tmp/nio.clj
Can't call public method of non-public class: public final java.nio.file.Path sun.nio.fs.AbstractPath.resolveSibling(java.lang.String) [at line 4, column 12]
so the class only wasn't public b/c it wasn't exposed by SCI, not per-se?
well, I had to add a config for:
{
"name":"java.nio.file.Path",
"allPublicMethods":true
}
right now I'm adding stuff to reflection.json manually, but I think I will move to a generation script at some point, because JSON...
@holyjak your script now runs!
$ ./bb /tmp/nio.clj
Target file already exists, going to force it...
#object[sun.nio.fs.UnixPath 0x636d3fb7 "/tmp/f2"]
linux: https://1968-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.36-SNAPSHOT-linux-amd64.zip mac: https://1967-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.36-SNAPSHOT-macos-amd64.zip test script:
(do
(.createNewFile (io/file "/tmp/f1"))
(let [p (.toPath (io/file "/tmp/f1"))
p' (.resolveSibling p "f2")]
(try
(java.nio.file.Files/move p p' (into-array java.nio.file.CopyOption []))
(println "Target file did not exist and move succeeded")
(catch java.nio.file.FileAlreadyExistsException _
(println "Target file already exists, going to force it...")
(java.nio.file.Files/move p p' (into-array [java.nio.file.StandardCopyOption/REPLACE_EXISTING]))))))
works indeed!
New mac version, (dotimes was broken in sci): https://1971-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.36-SNAPSHOT-macos-amd64.zip Test script:
(let [f (.File/createTempFile "foo" "bar")
p (.toPath (io/file f))
p' (.resolveSibling p "f2")]
(.delete (.toFile p'))
(dotimes [_ 2]
(try
(java.nio.file.Files/copy p p' (into-array java.nio.file.CopyOption []))
(println "Target file did not exist and move succeeded")
(catch java.nio.file.FileAlreadyExistsException _
(println "Target file already exists, going to force it...")
(java.nio.file.Files/copy p p' (into-array [java.nio.file.StandardCopyOption/REPLACE_EXISTING]))))))
$ ./bb /tmp/nio.clj
Target file did not exist and move succeeded
Target file already exists, going to force it...
@holyjak Added to master.
If you need support for more classes like LinkOption
or whatever, feel free to add PRs.
You can take this commit as an example: https://github.com/borkdude/babashka/commit/1885c452551a57ee1cffa88701a0500d427db365
bb v0.0.38 now also released, adds clojure.walk and an example of a portable tree command: https://github.com/borkdude/babashka/blob/master/README.md#portable-tree-command
@borkdude would you be amenable to the addition of clj-time to babashka? I have some millis in my data that could use a human format. I'd be willing to do the work for addition, just curious if it "fits"
that would be interesting, although I've been told that the new java time API pretty much replaces the need for it, so it might be better to add support for that instead?
Oh yes. That's what I mean. https://github.com/dm3/clojure.java-time
I'll take a look, have to make dinner now, but I like the idea, so feel free to experiment
Aggregate size of dir:
#!/usr/bin/env bb
(as-> (io/file (or (first *command-line-args*) ".")) $
(file-seq $)
(map #(.length %) $)
(reduce + $)
(/ $ (* 1024 1024))
(println (int $) "mb"))
$ dir-size
130 mb
$ dir-size ~/Dropbox/bin
233 mb
@sogaiu I guess it could, maybe using puget which uses fipp and jet also uses fipp. PR experiment welcome. Not sure how to deal with JSON coloring
may be there's a nice way to use jet from inside emacs to get some nice history ability plus possibly some coloring
like you two, I don't miss color for jet, --pretty to file then open in editor is fine by me.
puget is used by koacha's deep-diff, makes sense there for highlighting expected vs actual
i think color is nice when you're looking at things in a flat view -- e.g. editors, but if you are using something like rebl, may be it's not so important?
it turns out there is this undocumented feature in rebl (unsupported as well i guess), where you can get it to effectively receive certain sorts of things over the network -- so if the data in question is edn, we can send stuff from jet to rebl for viewing
I was confronted with this because https://github.com/borkdude/cljtree-graalvm had a colorize option. When I ported the script to babashka, it didn't support it 🙂 https://github.com/borkdude/babashka/blob/master/README.md#portable-tree-command
yes, color and pprint were the two missing things. I will go for fipp for pprinting since I still can't get clojure.pprint to play nice with graalvm
it's not even the locking: https://github.com/lread/clj-graal-docs/issues/19
hmm, when i tested lvh's statement the other day about not needing to patch clojure with the latest native-image, it was pprint that set off the monitor stuff