Fork me on GitHub
#beginners
<
2021-04-07
>
Jimmysit000:04:37

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 Power00:04:06

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

👍 3
💯 3
zendevil05:04:05

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 $fn__11530.invokeStatic(io.clj:305)
	at $fn__11530.invoke(io.clj:302)
	at clojure.lang.MultiFn.invoke(MultiFn.java:239)
	at $fn__11534.invokeStatic(io.clj:321)
	at $fn__11534.invoke(io.clj:319)
	at clojure.lang.MultiFn.invoke(MultiFn.java:239)
	at $copy.invokeStatic(io.clj:406)
	at $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?

phronmophobic05:04:03

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?

phronmophobic05:04:00

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?

NoahTheDuke15:04:09

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?

NoahTheDuke15:04:31

I want to avoid doing (-> 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 Douglass15:04:05

i've seen it as:

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

NoahTheDuke15:04:37

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

👍 3
3
raspasov15:04:13

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.

👍 3
Jeff Evans15:04:47

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"]}}}

seancorfield15:04:15

It’s nrepl.cmdline not nrepl.commandline

Jeff Evans15:04:50

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

Michael Stokley16:04:52

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?

seancorfield17:04:00

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.

👍 3
3
seancorfield17:04:28

(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)

andy.fingerhut19:04:49

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.

🙌 6
alexmiller20:04:41

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

andy.fingerhut22:04:08

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

andy.fingerhut22:04:58

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?

alexmiller22:04:45

Oh, it’s all unnatural

seancorfield23:04:19

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

andy.fingerhut00:04:53

The article has a lot of nice things to say about it 🙂

seancorfield00:04:41

“Object-oriented database management systems (also known as OODBMSs) are better suited than relational databases (such as SQL Server) for many of today’s new information types.” — but not for long 🙂

hiredman20:04:00

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)

alexmiller20:04:01

Hibernate has a family of strategies for this iirc

Lennart Buit21:04:45

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

marciol21:04:53

STI or Single Table Inheritance

phronmophobic21:04:12

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.