beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
2021-03-02T02:45:20.040Z

I'm looking for a sample repo to setup a pretty straightforward static file web server using Graal as a learning exercise I found this, which seems good, but is httpkit still the way to go for a http server? I saw the project says it's unmaintained by the owner but maintained by community users. https://github.com/yogthos/graal-web-app-example

dharrigan 2021-03-02T07:26:49.040200Z

what a great idea! 🙂

Scott Starkey 2021-03-02T13:08:26.047100Z

Hi there, folks. I’ve been working on Code Academy “katas” like a good beginner, and I came across this bit of irritation: https://www.codewars.com/kata/5ce399e0047a45001c853c2b/train/clojure > Let us consider this example (array written in general format): > ls = [0, 1, 3, 6, 10] > Its following parts: > ls = [0, 1, 3, 6, 10] > ls = [1, 3, 6, 10] > ls = [3, 6, 10] > ls = [6, 10] > ls = [10] > ls = [] > The corresponding sums are (put together in a list): `[20, 20, 19, 16, 10, 0]` So, I whipped up the following bit of code, which I was rather proud of!

(defn parts-sums [ls]
  (if (empty? ls) '(0)
      (cons (reduce + ls) (parts-sums (rest ls)))))
Cue the sad trombone sounds. At the bottom of the exercise it mentions: “Take a look at performance: some lists have thousands of elements.” My solution works for smaller sets and all the test datasets, but does not work on the longer “Attempt” datasets. Grr. Thoughts on optimization?

2021-03-02T13:12:04.047600Z

What if you reverse the list first?

2021-03-02T13:13:41.048200Z

Trying to just give vague hints here so as not to give away spoilers. 🙂

Scott Starkey 2021-03-02T13:13:53.048600Z

thanks. I will look into it. 🙂

2021-03-02T13:14:13.049300Z

I'd also look at the function reductions

2021-03-02T13:14:17.049500Z

Or another question: what’s the most time-consuming part of the problem, and how can you minimize the time you spend doing that?

2021-03-02T13:16:17.050900Z

That’s a better approach to figuring out optimizations in general.

2021-03-02T13:16:36.051700Z

e.g.

(reductions + 0 [1 2 3 4 5])
=> (0 1 3 6 10 15)
Think that will help you here.

Scott Starkey 2021-03-02T13:16:55.052300Z

Hmmm… I’d never seen or tried to use the function reductions before. One of my attempts was trying to use reduce but that didn’t work.

2021-03-02T13:16:55.052400Z

It's like reduce, but returns you the intermediate values

2021-03-02T13:17:29.052800Z

Note that the correct solution to the problem given is The corresponding sums are (put together in a list): [20, 20, 19, 16, 10, 0]

Scott Starkey 2021-03-02T13:18:03.053500Z

YESSSSS, reductions! I just looked up that up. That’s exactly what I need here!

Scott Starkey 2021-03-02T13:18:12.053700Z

I’d never heard of it before!

2021-03-02T13:19:13.054800Z

Clojure has a bunch of useful things like that. See also frequencies, which isn’t relevant to this, but it’s also a cool function.

Scott Starkey 2021-03-02T13:20:01.055700Z

[heads off and fires up emacs]

❤️ 1
popeye 2021-03-02T13:49:01.057500Z

Team, I have service endpoint which has authentication, I am able to get the result in postman, I wanted to integrate same in my application using clojure, Which are the api I can use? I started with composure, But I did not get how to access endpoint via clojure

dharrigan 2021-03-02T13:50:26.058Z

As a client, there are several, for example <https://http-kit.github.io/> and <https://github.com/dakrone/clj-http> are two that immediately come to mind.

✅ 1
popeye 2021-03-03T08:00:00.108100Z

@robertfrederickwarner yeah I used :insecure? to false and it worked for me,

robertfw 2021-03-03T08:10:20.108600Z

set to false? I would have expected it to be set to true to allow insecure certs

popeye 2021-03-03T08:12:46.108800Z

ya sorry, I rechecked it ..i set it to true

robertfw 2021-03-03T08:16:15.109Z

Groovy. Glad that got you off the ground. Just be wary of that :insecure? setting - it does what it says on the tin, and makes things less secure. Fine for development but if you are putting things into production I'd recommend either getting a properly signed cert, or looking into the :keystore options

popeye 2021-03-03T08:16:45.109200Z

yes

popeye 2021-03-02T13:54:26.058200Z

So we need to use ring in this?

dharrigan 2021-03-02T13:55:04.058400Z

No. If I read you correctly, you want to invoke an external 3rd party API that is secured by some type of authentication, in order to retrieve data (most likely JSON)?

popeye 2021-03-02T14:22:30.058900Z

Execution error (SunCertPathBuilderException) at sun.security.provider.certpath.SunCertPathBuilder/build (SunCertPathBuilder.java:141). unable to find valid certification path to requested target

popeye 2021-03-02T14:22:48.059100Z

@dharrigan ^^

pavlosmelissinos 2021-03-02T15:41:15.065300Z

So in order to set a custom read timeout in a google analytics api request, I had to write https://developers.google.com/api-client-library/java/google-api-java-client/errors in clojure with java interop. I ended up using reify:

(defn set-http-timeout [request-initializer]
  (reify HttpRequestInitializer
    (initialize [_ http-request]
      (.initialize request-initializer http-request)
      (.setReadTimeout http-request (* 3 60000)))))
However, according to the well-known "https://raw.githubusercontent.com/cemerick/clojure-type-selection-flowchart/master/choosingtypeforms.png?" flowchart, when you want to extend an existing class, you need to use proxy. Is the flowchart outdated or could proxy really have some edge over reify in this particular case?

2021-03-02T15:57:21.066200Z

That's an interface not a class

1
pavlosmelissinos 2021-03-02T16:04:16.066400Z

(Yup, it's official, I'm an idiot 😅) Thanks!

Audrius 2021-03-02T16:17:55.069600Z

Hi, can I ask for some support? I have a Leiningen project that does not work for some reason but I don't know why. https://github.com/audriu/gorilla-rpl-try I run lein gorilla` as shown in this example http://gorilla-repl.org/start.html I just need to find out if this is problem with my setup or I am doing something stupid. The exception is here: https://pastebin.com/9B2QDtrr

Audrius 2021-03-02T16:21:59.070100Z

The project was created with lein new app name and just added :plugins [[lein-gorilla "0.4.0"]] to project.clj

sb 2021-03-02T16:39:21.072600Z

When I publish a Clojure library to Clojars, I see allow just for “org.clojars.baader/*” to submit something, but how could I create eg [baader/library-name “0.1.0"], without org.clojars? Just I don’t understand others.. how could setup this.

2021-03-02T16:47:06.076Z

Clojars policies have changed over time

2021-03-02T16:48:31.077900Z

There were some recent changes to prevent people from using group I'd names that they don't "own" in some sense

2021-03-02T16:50:19.078200Z

https://groups.google.com/g/clojure/c/cWG-V_4uv90

👍 1
phoenixjj 2021-03-02T17:27:31.079100Z

https://github.com/JonyEpsilon/gorilla-repl/issues/291ou are hitting this issue.

phoenixjj 2021-03-02T17:27:32.079300Z

https://github.com/JonyEpsilon/gorilla-repl/issues/291

phoenixjj 2021-03-02T17:32:39.079800Z

change reps in plugins section as mentioned in the comment to [org.clojars.benfb/lein-gorilla "0.6.0"]

✔️ 1
Audrius 2021-03-02T17:39:24.080100Z

thank you so mutch

seancorfield 2021-03-02T17:44:54.081300Z

@sb Both clj-new and depstar will be getting updates this week to "strongly encourage" folks to use group IDs that comply with the new security policy that Clojars is rolling out.

seancorfield 2021-03-02T17:46:30.082900Z

If you own <http://baader.com|baader.com> (or .net or .org) you should probably use com.baader as your group name (or net.baader or org.baader) so that ownership can be verified. Or com.github.baader if your library lives on GitHub.

👍 2
sb 2021-03-02T17:48:01.083700Z

I use Hungarian domain (my company domain), in this case hu.baader ok, btw during this time somebody approved to use baader name (thanks!)

seancorfield 2021-03-02T17:49:26.084300Z

hu.baader/library-name would be nice for you to use (and make sure you don't conflict with any other baader out there 🙂 )

👍 1
🍻 1
sb 2021-03-02T17:49:56.084500Z

ok 🙂 I can do it. Np for me 🙂

sb 2021-03-02T17:53:43.084800Z

works fine, thanks!!

robertfw 2021-03-02T18:49:46.085600Z

What kind of authentication are you using?

robertfw 2021-03-02T18:50:42.085800Z

My guess from the error is that you are using a self-signed certificate?

robertfw 2021-03-02T18:54:20.086Z

@popeyepwr If you are using clj-http, you should look at the :insecure? or :keystore options. http-kit has the :insecure? option but I'm not sure how it handles :keystore

2021-03-02T19:11:40.086600Z

Good afternoon everybody, I'm back at it with more livestreaming today. We're starting in about 10 minutes if you'd like to join. Stream link here: https://www.twitch.tv/a_fry_ Per usual, I'm mostly going to be live-coding the development of this app: https://startupinamonth.net/pic-story-pitch/ But first I'm starting with a coding exercise warmup, so if you're new to the language, are trying to learn new techniques, or just curious, then feel free to join for the exercise portion! We're doing this coding challenge from the Eric Normand newsletter today, averaging RGB colors: https://purelyfunctional.tv/issues/purelyfunctional-tv-newsletter-400-is-software-design-worthless/ Hope to see you there :man-bowing:

😮 1
sova-soars-the-sora 2021-03-02T19:37:58.087300Z

is there a way to change the ring anti forgery token error page?

Todd 2021-03-02T20:29:45.089400Z

Watching REPL Driven Development on http://clojure.tv to learn different programming flow with Clojure. Any other suggestions? I’m currently using Cursive since I’m most comfortable there. Any good resources for RDD in Cursive would be awesome!

seancorfield 2021-03-02T20:40:28.091700Z

@twcrone I don't know of any that use Cursive (maybe ask in #cursive?). I have a couple of videos on my YouTube channel that show my RDD workflow (with Atom/Chlorine and Cognitect's REBL) https://www.youtube.com/c/SeanCorfield_A and I did a couple of meetup talks/live coding recently with VS Code/Clover and Reveal https://www.youtube.com/watch?v=gIoadGfm5T8 (London: an hour and fifteen) and https://www.youtube.com/watch?v=skEXGSp10Xs&amp;t=837s (Provo: the talk starts 14 minutes in and runs 2 1/2 hours).

seancorfield 2021-03-02T20:41:23.092700Z

I love Eric Normand's RDD course on http://PurelyFunctional.tv but that's a subscription service ($49/month).

seancorfield 2021-03-02T20:42:02.093500Z

There's also this from Practicalli: https://practicalli.github.io/clojure/repl-driven-devlopment.html

Todd 2021-03-02T20:42:04.093700Z

can’t subscribe anymore…need to pay per video although they are downloadable for free it appears

Todd 2021-03-02T20:42:12.093900Z

yes, saw that too

seancorfield 2021-03-02T20:50:01.095900Z

I've pinged Eric about the subscription stuff -- he still links to it in his weekly newsletter, saying subscriptions are available. I know he closed them down for a while, then opened them back up.

Todd 2021-03-02T21:16:11.096900Z

ok, I seem to remember seeing subscriptions were available recently, then last couple days could not get one.

2021-03-02T22:47:29.097Z

If anybody would like to check out my solution, here it is: https://github.com/andyfry01/clojure-coding-challenges/blob/master/src/main/color-averaging.clj You should be able to copy/paste this into any old REPL and just run it. Enjoy!