This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-12
Channels
- # bangalore-clj (1)
- # beginners (28)
- # boot (33)
- # chestnut (3)
- # cider (35)
- # cljs-dev (64)
- # cljsrn (16)
- # clojure (95)
- # clojure-android (6)
- # clojure-austin (1)
- # clojure-italy (5)
- # clojure-korea (1)
- # clojure-russia (55)
- # clojure-sg (1)
- # clojure-spec (25)
- # clojure-uk (57)
- # clojurescript (120)
- # code-reviews (7)
- # community-development (2)
- # core-async (3)
- # cursive (6)
- # data-science (3)
- # datascript (10)
- # datomic (12)
- # devcards (1)
- # emacs (9)
- # gsoc (7)
- # hoplon (18)
- # lumo (2)
- # off-topic (10)
- # om (24)
- # onyx (17)
- # pedestal (46)
- # powderkeg (1)
- # protorepl (7)
- # re-frame (31)
- # ring-swagger (34)
- # spacemacs (10)
- # specter (9)
- # sql (39)
- # unrepl (9)
- # untangled (3)
- # utah-clojurians (1)
is there a json library for clojure that gives better error messages than clojure.data.json?
wiseman: Not sure about error messages specifically, but I like cheshire for speed and custom extensions https://github.com/dakrone/cheshire
ah, thanks, cheshire seems to do (somewhat) better in that respect:
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate Object entries
at [Source: java.io.StringReader@2abe9173; line: 4, column: 7]
e.g. it would be great to get something equivalent to
python -m json.tool config.json
Expecting , delimiter: line 4 column 6 (char 43
(with-open [os ( "../resources/public/data.js")]
(let [w ( os)]
(.write w (str "var my_data = "))))
do I need to put a flush somewhere to make this work ? right now, the output file data.js is emptyTry this:
(with-open [w ( ( "../resources/public/data.js"))]
(.write w (str "var my_data = ")))
It's a guess, but it may be that the the BufferedWriter constructed from the BufferedOutputStream isn't being flushed when the output stream is closed by with-open
I'm interleaving writing output-strea directly and using transit/writer to write out clj objects
It's possible that it's double buffering. Because
returns a BufferedWriter even when constructed with a BufferedOutputStream
Ok, so yeah with-open
is only closing the output-stream, not the writer, which doesn't flush a writer constructed from that
Produces no output in /tmp/test:
user> (def os ( "/tmp/test"))
nil
user> (def w ( os))
nil
user> (.write w "Hello")
nil
user> (.close os)
nil
user> (.close w)
IOException Stream Closed java.io.FileOutputStream.writeBytes (FileOutputStream.java:-2)
Produces "Hello" in /tmp/test:
user> (def os ( "/tmp/test"))
nil
user> (def w ( os))
nil
user> (.write w "Hello")
nil
user> (.close w)
nil
user> (.close os)
nil
lein.test
seems to always run tests alphabetically; in situations in which we spin up a single fixture for tests A
, B
, and C
, which are stateful, this can result in tests passing when they should be failing
E.g. A
passes when the state is initially empty, but would fail if it’s not. However, it always passes b/c A
always comes first, when the state is initially empty
in Java, is there a simple way to escape strings without using StringEscapeUtils (from apache)? I would prefer something that came directly with the JVM
@skylar yada 🙂
@skylar ... or yada ? 🙂 https://github.com/juxt/yada
https://github.com/juxt/yada - or try several ones and see which one suits your needs best. I like yada a lot 🙂
lol @val_waeselynck agreed
Thanks @kurt-o-sys and @val_waeselynck, I'll check it out. What's the main differences between the two others?
Perhaps just https://github.com/weavejester/compojure may be enough depending on what you want to do
well, to me, I pretty much like the idea of having all http methods (`GET`, POST
, ...) being part of one resource - meaning, they are methods on the same url, and the code is structured as such.
And there are other things as well: https://www.youtube.com/watch?v=tKFrqsFC1XM
there is fairly good OAuth2 support in yada, and it will be improved soon. There's a OAuth2 blog article for yada in the works too
it's a good idea to get to grips with yada from the examples and docs and gradually build up your understanding of the concepts before adding the OAuth2 parts, but it's very doable (we use yada-powered OAuth2 for our http://juxt.pro website)
@skylar My experiences with Yada so far: https://twitter.com/borkdude/status/847811757766823938 https://twitter.com/borkdude/status/857979807358910464
Quick question, is there a way of identifying when a dosync block fails and is retried? I would like to see that statistic for some testing I am performing.
after thinking carefully I think I found a way! so, because only refs are controlled by dosync atoms are perfect for this so just add (swap! sales-attempts inc) given that atoms offer atomic operations it should be safe "This is done in an atomic manner by swap! Internally, swap! reads the current value, applies the function to it, and attempts to compare-and-set! it in."
@oskar132 you can also use a volatile instead of an atom for efficiency, I think it's safe in this case
@val_waeselynck that's true. In this case I'll leave it at that given that I'm only testing for correctness
dosync calls do no locking, so a volatile would not be safe
Unless you mean the volatile would be a local captured by the dosync call and never shared between calls
@noisesmith yes that is what I meant
@robert-stuttaford and other, thanks for recommending Sentry, works like a charm
If I want to make a symbol from a Java classname symbol and a string how would I do it
I want Foo$Bar/baz from Foo$Bar and "baz"
@slightlycyborg wouldn’t that be (symbol “Foo$Bar” “baz”) ?
I'd like to learn about spec, but first need a 10-thousand foot overview. Is "spec" code written alongside your regular source code, or is it separate like test code? Is there a command you run at the command line to have Clojure run spec code against your source code, or is spec something that happens during code execution? How does spec work in practice?
@uvtc this is the best spec intro I’ve seen https://clojure.org/guides/spec
regarding with code or separate like tests, to quote that document:
spec provides a central registry for globally declaring reusable specs
Thanks, @noisesmith , I'm looking at that, but it immediately goes into (s/conform even? 1000)
...
if you want the 10000ft overview @uvtc start with the rationale+overview before the guide: https://clojure.org/about/spec
Heya. Why is this throwing a spec error?
(ns crawly.worker
(:require
[clojure.core.async :as async])
(:import [core.CrawlQueue]
[core.CrawlService]))
it thinks it saw refer-clojure :as ...
somewhere
perhaps the version of core.async you have does this?
that’s been fixed in latest core.async
in fact it says clojure/core/async.clj
Strange. It worked just a few hours ago and I haven’t updated anything in project.clj — I’m on clj 1.9.0-alpha15 and core.async 0.2.395
somehow I think you have older core.async
@wiseman Defn Podcast by @vijaykiran and @raymcdermott. Also Cognicast with various hosts.
I have an algo that looks like it Stack Overflows in a concat
portion, using a few orders of magnitude smaller of an input than I want...
How do I debug and fix this?
ERROR in () (LazySeq.java:40)
expected: (= coll j)
actual: java.lang.StackOverflowError: null
at clojure.lang.LazySeq.sval (LazySeq.java:40)
clojure.lang.LazySeq.seq (LazySeq.java:49)
clojure.lang.RT.seq (RT.java:521)
clojure.core$seq__4357.invokeStatic (core.clj:137)
clojure.core$concat$fn__4446.invoke (core.clj:706)
clojure.lang.LazySeq.sval (LazySeq.java:40)
clojure.lang.LazySeq.seq (LazySeq.java:49)
...
don’t call concat in an eager accumulator without realizing the lazy value it wraps
that’s the usual issue - something like reduce or loop where concat is being called at every step, which builds up a really high pile of thunks, and as soon as someone finally asks for the first element, there’s too many piled up lazy ops to evaluate them all without running out of stack
so pick one -either you are lazy, or you are eagerly consuming an input (usually - not knowing your code of course)
yes, it's concat
is in a loop
so I'm only passingly familiar with optimizing against laziness and building up big thunks
would doall
ing on the concat
help?
I tried that and while it doesn't SO, it's wayyy slower than I would expect
yes, if you run that on every step of the loop where it concats
even better is a way to build up your result without concat (may or may not make sense)
I don't suppose apply conj
is a good alternatice?
(well, depends on how you want order to turn out, and how many args)
waaaahhhhhhhhhhhhhh
thank you thank you thank you
I was seriously freaking out, but replacing concat with into let's me go way bigger on inputs
and no SO
tests pass
etc. Thanks so much!
also, into lets you use a transducer 😄
glad I could help
before 10k SO'd, now 1M works fine
sweet
oh yeah, I forgot to link to that post
thx, I'll look forward to reading that.