Fork me on GitHub
#clojure
<
2017-07-30
>
mjo324_5600:07:04

@noisesmith so is there a simple way of turning logging off? so that i wont waste hours of reading and understanding docs

darwin00:07:33

@mjo324_56 from what you wrote, you likely don’t want simple, you want easy 😉

mjo324_5600:07:57

i want copy-paste

mjo324_5600:07:15

i see no point on wasting to much time for stuff that i don;t need

darwin00:07:33

wrap your tool in a bash script and redirect/filter the output outside the process

darwin00:07:00

(and we are back to docker, if you want to do it the fancy way ;)

mjo324_5600:07:26

@darwin the problem is that my function is changing some global variables

mjo324_5600:07:46

it wont be able to do this in a seperate process

darwin00:07:00

I don’t see a problem, wrap your whole thing and redirect/filter the output on OS/shell/system level (outside your process)

mjo324_5600:07:48

it's not a point of easy/simple, clj-http is logging crap to stdout, i see no point on configuring it's logging facility since next time some other lib will use a different logging facility

mjo324_5600:07:27

@darwin mother_thread gives good output(my output), but calls thread2 which gives unwanted output

mjo324_5600:07:57

thread2 alters global variables

mjo324_5600:07:00

i can't wrap the whole stuff up since i loose output from mother_thread

darwin00:07:06

well, there is probably no easy way to do that, as I posted an hour ago, you could “hack” it via System/setOut, but then you would have to the filtering on your own, because that would capture all java (and clojure) outputs from all threads

darwin00:07:02

I’m pretty sure this is doable, you would need to filter the stream and reject unwanted lines with some regex

darwin00:07:57

for inspiration, you can look here, recently I wrote something similar: https://github.com/cljs-oss/canary/blob/master/runner/src/canary/runner/output.clj#L16

darwin00:07:18

the printer would inspect individual lines and decide to print them out or not

darwin00:07:42

stream would be something you would construct in java land and set into System/setOut (theory)

mjo324_5600:07:18

i even tried to suppress sysem.out, which also did not work. I think the logging libraries redirect it again,

darwin00:07:28

well, I’m not a java guy, but I can imagine there might be even lower-level layer, which logging library could be using - something like logging into files which happens to be stdout by some lower-level means

darwin00:07:51

I mean writing into something like /dev/stdout unix-y way, effectively bypassing even System/out

mjo324_5600:07:02

i leave this crappy output where it is

mjo324_5600:07:12

and put my wanted output somewhere else

mjo324_5600:07:26

and hide stdout alltogether

mjo324_5600:07:42

i am deifentekly to stupid to configure clj-http's logging

mjo324_5600:07:57

topic closed

mjo324_5600:07:06

may the force be with you!

mjo324_5600:07:57

easy&simple is always the preferred way 😉

matan08:07:48

judging from past releases, any idea when 1.9 will be out? right now it is alpha something..

qqq09:07:40

how bad is it to mix code that camelCase and dash-case in the same project ?

qqq09:07:00

I'm designing some database field column names, and camelCase somehow seems more appropriate than the dash-case

dominicm12:07:23

Is there a new api for http://clojuredocs.org? The current one seems to be timing out. I'm guessing it is gone.

andrewtropin12:07:23

@qqq you can convert database column names to dash-case if you want.

andrewtropin12:07:57

(jdbc/query *db* sql {:identifiers to-kebab-case})

sekao13:07:27

i'm using transit with sente, and i noticed there are +s and -s in the beginning of the encoded messages, such as +[["~:chsk/ws-ping"]]. why are they there? it is not appear to be valid json.

sekao13:07:02

i'm a transit newbie so forgive me if i'm missing something obvious

sekao13:07:51

ah, i think this is intentional behavior by sente, based on my reading of the source code

camdez15:07:24

@sekao I believe you’re right. Looks like the + just indicates that the payload contains a callback, and this appears to be above the level of the particular “packer” (read: encoding). https://github.com/ptaoussanis/sente/blob/e3d417334214df3b9f9b0514c8ddd8c71b6d49b0/src/taoensso/sente.cljc#L217-L231

kaosko19:07:53

anybody using transit? is there an easy way to customize the precision of floats for the writer? i.e. if I just want to save some on length, round up all floats to 2 decimals only?

Garrett Hopper21:07:42

What's a quick way of doing checking on a value with an arbitrary function to return a default value. Like the following without the let:

(let [val (expression arg)]
  (if (function val) default val))

Garrett Hopper21:07:02

Basically, if a function returns true, then return nil, otherwise return the original value. So, kinda nil checking.

sundarj21:07:22

write a macro?

Garrett Hopper21:07:53

I suppose that's probably the solution. I just thought there might be something in core that'd do this. The real problem is parsing a float then NaN checking it.

sundarj21:07:43

yeah, i'm not aware of anything in core for this, but someone else might be

camdez21:07:30

Neither of those is quite right. cond-> doesn’t pass val to function, and some-> just bails if the value becomes nil.

Garrett Hopper21:07:14

Yeah, I'd looked at those, but not quite right.

camdez21:07:09

You don’t really need to jump straight to a macro unless you’re worried about default getting evaluated ahead of time.

Garrett Hopper21:07:49

I've settled on consecutive entries in a let with the same name.

camdez21:07:29

Cool. But it could be as simple as:

(defn default-if [x pred default]
  (if (pred x) default x))
It even reads fairly well in a threading macro:
(-> (+ 2 1)
    (default-if even? "even")
    (default-if neg? "negative"))

camdez21:07:47

¯\(ツ)

Garrett Hopper21:07:30

That'd be pretty good. I tend to like to rely on core as must as possible without small helper function like that. Maybe that's just a bad philosophy on my part though.

camdez21:07:26

@U5JUDH2UE I’d say I usually do the same, but I think this can be understood at a glance, which means to me that it’s not going to affect readability negatively by requiring the reader to be familiar with what you’ve introduced.

Garrett Hopper21:07:38

That's true, and it's arguably more readable than the alternative anyways. Thanks!

camdez21:07:27

Ah, small issue with what I posted above though…if the first default-if returns a "even" then it calls neg? on that and fails.

camdez21:07:38

So you’ll need a macro if you actually want to stack them like that. Anyway, have a good one. 🙂

Garrett Hopper21:07:57

Thanks, you too. 🙂

camdez21:07:26

Oh, and if you want to do something truly godawful, here’s a way to do it with core:

(condp #(%1 %2) (+ 2 2)
  even? "even"
  neg? "negative"
  identity :>> identity)
🙃

camdez21:07:06

@kaosko I think it can’t be too trivial because there are a few SNAFUs around infinity and NaN, but I think this will get you on the right track: https://gist.github.com/camdez/108968382449b7c3a957daecb1aa500a

lwhorton22:07:34

holy canoli… my java/clojure interop knowledge has some gaping holes. how does one invoke a java api that uses anon inner classes? for example, selenium:

new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        }
1) do you need to provide a return type for a class? provide some sort of complier hint? ExpectedCondition<Type> 2) I know from the clojure guide (and java spec) you can reference anon inner classes as Class$InnerClass, but that’ doesn’t really apply here. how does one construct an anon inner class and provide method implementations? perhaps I just don’t know enough of the right verbs/nouns in java-land to properly ask dr. google, but I wasn’t able to find much

lwhorton22:07:57

In that above example the expectedcondition derives apply from goog.common.base.Function… i guess i’m not sure if that means i need to extend an existing base class (proxy) or not (reify)?

kaosko22:07:08

perfect, thanks @camdez!

noisesmith23:07:17

@lwhorton <Foo> is a fiction, only the java compiler needs it, it doesn't exist in a true sense in the byte code.

noisesmith23:07:29

to make an anonymous class, use reify or proxy

noisesmith23:07:39

*instance of an anonymous class

noisesmith23:07:12

docs say it's an interface, which means you can use reify, you only need proxy to extend concrete classes