beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
2021-04-07T00:02:37.206200Z

I'd like to make a script to automatize my responses when my laptop battery is low. But I have no idea how can I calculate the battery, any ideas? (I don't know Java)

Rolfe Power 2021-04-07T00:11:06.206300Z

You can try https://github.com/oshi/oshi which could provide that capability

đź‘Ť 1
đź’Ż 1
zendevil 2021-04-07T05:10:05.208700Z

I’m making a multipart request to the server. Earlier the request was working, but now when I make the request, I get the following error:

2021-04-06 22:06:11,024 [manifold-pool-2-149] ERROR humboiserver.middleware - Stream ended unexpectedly 
org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
	at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:1033)
	at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:931)
	at java.io.InputStream.read(InputStream.java:101)
	at <http://clojure.java.io|clojure.java.io>$fn__11530.invokeStatic(io.clj:305)
	at <http://clojure.java.io|clojure.java.io>$fn__11530.invoke(io.clj:302)
	at clojure.lang.MultiFn.invoke(MultiFn.java:239)
	at <http://clojure.java.io|clojure.java.io>$fn__11534.invokeStatic(io.clj:321)
	at <http://clojure.java.io|clojure.java.io>$fn__11534.invoke(io.clj:319)
	at clojure.lang.MultiFn.invoke(MultiFn.java:239)
	at <http://clojure.java.io|clojure.java.io>$copy.invokeStatic(io.clj:406)
	at <http://clojure.java.io|clojure.java.io>$copy.doInvoke(io.clj:391)
	at clojure.lang.RestFn.invoke(RestFn.java:425)
	at ring.middleware.multipart_params.temp_file$temp_file_store$fn__39717.invoke(temp_file.clj:69)
	at ring.middleware.multipart_params$parse_file_item.invokeStatic(multipart_params.clj:84)
	at ring.middleware.multipart_params$parse_file_item.invoke(multipart_params.clj:76)
	at ring.middleware.multipart_params$parse_multipart_params$fn__9115.invoke(multipart_params.clj:94)
	at clojure.core$map$fn__5866.invoke(core.clj:2755)
	at clojure.lang.LazySeq.sval(LazySeq.java:42)
	at clojure.lang.LazySeq.seq(LazySeq.java:51)
	at clojure.lang.RT.seq(RT.java:535)
	at clojure.core$seq__5402.invokeStatic(core.clj:137)
	at clojure.core$filter$fn__5893.invoke(core.clj:2809)
	at clojure.lang.LazySeq.sval(LazySeq.java:42)
	at clojure.lang.LazySeq.seq(LazySeq.java:51)
	at clojure.lang.LazySeq.first(LazySeq.java:73)
	at clojure.lang.RT.first(RT.java:692)
	at clojure.core$first__5384.invokeStatic(core.clj:55)
	at clojure.core$first__5384.invoke(core.clj:55)
	at ring.middleware.multipart_params$parse_html5_charset.invokeStatic(multipart_params.clj:63)
	at ring.middleware.multipart_params$parse_html5_charset.invoke(multipart_params.clj:62)
	at ring.middleware.multipart_params$decode_string_values.invokeStatic(multipart_params.clj:67)
	at ring.middleware.multipart_params$decode_string_values.invoke(multipart_params.clj:66)
	at ring.middleware.multipart_params$parse_multipart_params.invokeStatic(multipart_params.clj:95)
	at ring.middleware.multipart_params$parse_multipart_params.invoke(multipart_params.clj:89)
	at ring.middleware.multipart_params$multipart_params_request.invokeStatic(multipart_params.clj:126)
	at ring.middleware.multipart_params$multipart_params_request.invoke(multipart_params.clj:111)
	at ring.middleware.multipart_params$wrap_multipart_params$fn__9126.invoke(multipart_params.clj:171)
	at ring.middleware.params$wrap_params$fn__9150.invoke(params.clj:67)
	at ring.middleware.cookies$wrap_cookies$fn__8841.invoke(cookies.clj:214)
	at ring.middleware.absolute_redirects$wrap_absolute_redirects$fn__9338.invoke(absolute_redirects.clj:47)
	at ring.middleware.resource$wrap_resource_prefer_resources$fn__9186.invoke(resource.clj:25)
	at ring.middleware.content_type$wrap_content_type$fn__9286.invoke(content_type.clj:34)
	at ring.middleware.default_charset$wrap_default_charset$fn__9310.invoke(default_charset.clj:31)
	at ring.middleware.not_modified$wrap_not_modified$fn__9252.invoke(not_modified.clj:61)
	at ring.middleware.x_headers$wrap_x_header$fn__8486.invoke(x_headers.clj:22)
	at ring.middleware.x_headers$wrap_x_header$fn__8486.invoke(x_headers.clj:22)
	at ring.middleware.x_headers$wrap_x_header$fn__8486.invoke(x_headers.clj:22)
	at humboiserver.middleware$wrap_internal_error$fn__9412.invoke(middleware.clj:17)
	at aleph.http.server$handle_request$fn__30032$f__25130__auto____30033.invoke(server.clj:158)
	at clojure.lang.AFn.run(AFn.java:22)
	at io.aleph.dirigiste.Executor$Worker$1.run(Executor.java:62)
	at manifold.executor$thread_factory$reify__25012$f__25013.invoke(executor.clj:44)
	at clojure.lang.AFn.run(AFn.java:22
It gives a stream-ended unexpectedly error, and I don’t know what’s causing it. I didn’t change a single line of code, and it was working before, but now it doesn’t. How to debug this?

phronmophobic 2021-04-07T05:33:03.209100Z

Some things to check: • Is the server running out of disk space? • Is it failing when uploading the same exact file or does it matter which file is being uploaded? • What size is the file? • What does the server do with the file that is uploaded? Is it being read immediately? • Are there any new intermediate proxies like nginx, a load balancer, cloudfront, etc? • What type of file is being uploaded? • Is compression being used? Have compression options changed?

phronmophobic 2021-04-07T05:36:00.209600Z

Another tool to help debugging is to use Google Chrome's network console to gather more information: • Does the upload fail immediately? • Does the upload hang? • Does the upload make some progress before failing? • What headers are used? • What HTTP method is being used?

NoahTheDuke 2021-04-07T15:03:09.212700Z

I want to assoc some stuff onto a map, but skip certain keys depending on some conditionals. what's the best method for doing that?

NoahTheDuke 2021-04-07T15:05:31.215Z

I want to avoid doing (-&gt; m (assoc :key1 (when conditional? :value1) :key2 (when conditional2? :value2)) (prune-nils)) (where prune-nils is a function that iterates over a map and dissoc's any key that has a nil value)

Darin Douglass 2021-04-07T15:12:05.216500Z

i've seen it as:

(merge m (when conditional? {:key1 :value1}) ...)
and
(cond-&gt; m
  conditional? (assoc :key1 :value1)
  ...)

NoahTheDuke 2021-04-07T15:12:37.217Z

cond-&gt; is exactly what I'm looking for, thank you! completely forgot about that one

đź‘Ť 1
1
raspasov 2021-04-07T15:18:13.217800Z

For the cases where there’s too many potential nils and you don’t want to check each one:

(defn clear-nils
 "Remove the keys from m for which the value is nil; O(N)"
 [m]
 (apply
  dissoc m
  (for [[k v] m :when (nil? v)] k)))
This solution specifically uses (dissoc …) so it should be a bit better in terms of perf than other solutions using (filter ...) et al; Still O(N), of course. Should not be used with large maps.

đź‘Ť 1
2021-04-07T15:19:47.219800Z

what am I doing wrong? trying to create a new deps.edn alias to start nREPL in an existing project. when running clojure -M:nREPL, I get the output about the remote debugger started (implying :jvm-opts was picked up correctly), but it fails with Could not locate nrepl/commandline__init.class, nrepl/commandline.clj or nrepl/commandline.cljc on classpath.

:aliases
 {:nREPL {:extra-paths ["test"]
          :jvm-opts    ["-Dclojure.compiler.disable-locals-clearing=true" "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=15325"]
          :extra-deps  {nrepl/nrepl {:mvn/version "0.8.3"}}
          :main-opts   ["-m" "nrepl.commandline" "-b" "0.0.0.0" -p "59173"]}}}

seancorfield 2021-04-07T15:22:15.220700Z

It’s nrepl.cmdline not nrepl.commandline

2021-04-07T15:23:50.221100Z

thank you! I have no idea where that substitution came from. probably my own addled brain

2021-04-07T16:59:52.222400Z

from "A History of Clojure" > As an application architect, working with databases taught me several important things about programming languages and their role in systems. The primary information model should not live in any application program. The more elaborate the type abstractions built up inside the programming language the less likely they would be shared by any other system participant, and the more involved and necessary marshaling would be to get in/out of the program’s model. what's Rich talking about here? having types in the application that aren't present - aren't formalized - in the persistence layer?

seancorfield 2021-04-07T17:05:00.224600Z

I took it as meaning “data should be the source of truth” (not code). So you want your primary information model to be something external to code, that all different parts of the system can read/interact with. That means very few types — only “universal” ones that all programs can read/manipulate.

đź‘Ť 1
1
seancorfield 2021-04-07T17:07:28.226600Z

(numbers — but maybe also integers and floating point separately, strings, booleans, vectors, hash maps… dates are not quite universal for all sorts of reasons but they are an important “type” that we all have to agree on and work with and that’s hard)

2021-04-07T19:54:49.228300Z

As an example, C++ or Java class inheritance details are things that are typically not represented in databases, as far as I understand. And if you do, and the details of how that works is different from one programming language to another, putting those specifics in the persistent data means that writing a program in other languages to access it will be an unnatural act.

🙌 2
alexmiller 2021-04-07T20:20:41.229400Z

They totally are represented in databases and people have whole schools of thought about how to do so :)

2021-04-07T20:33:00.231300Z

I've actually seen at least one kind of inheritance postgres supports used in production (https://www.postgresql.org/docs/9.1/ddl-inherit.html)

alexmiller 2021-04-07T20:36:01.231700Z

Hibernate has a family of strategies for this iirc

2021-04-07T21:13:45.232500Z

Yeah, Rails and Django (the webframeworks) have all sorts of ideas about this too in their ORMs

marciol 2021-04-07T21:31:53.235800Z

STI or Single Table Inheritance

phronmophobic 2021-04-07T21:32:12.236100Z

speaking of using language specific types leading to extra cruft and boilerplate, https://clojureverse.org/t/modern-js-with-cljs-class-and-template-literals/7450 It’s awesome that the work is being done to make cljs work great, but it would be nice if js wasn’t manufacturing extra work.

2021-04-07T22:31:08.240Z

Wow, I stand corrected. I wish I didn't stand corrected 🙂

2021-04-07T22:31:58.240200Z

Would you say that these schools of thought somehow avoid unnatural acts across different programming languages trying to access the same database, if those programming languages have too-different OO language features?

alexmiller 2021-04-07T22:32:45.240800Z

Oh, it’s all unnatural

seancorfield 2021-04-07T23:09:19.241700Z

Keeping this to a thread since it’s OT for beginners: Anyone remember the POET database? (or any other similar monstrosities?) 🙂