Fork me on GitHub
#beginners
<
2019-11-24
>
Artur Aralin09:11:22

Hi all. What the function can do this?

(fn "ADEF" "BC" 1) ; => "ABCDEF"

first arg soruce string
second substring
third index in source string

Csaba Endre Simon09:11:05

I don’t know for (fn “ADEF” “CD” 1) but for (fn “ADEF” “BC” 1) the following function will do:

(defn fn [s c i] (str (subs s 0 i) c (subs s i)))

Artur Aralin09:11:55

I made this. More common solution

(defn insert-between [src-val start-idx val]
  (let [[before after] (split-at start-idx src-val)]
    (concat before val after)))

Csaba Endre Simon09:11:45

user=> (insert-between "ADEF" 1 "BC")
(\A \B \C \D \E \F)

tdantas10:11:48

hey guys, awesome sunday me and @mping were inspired by a layerCI article and we started coding PostgreSQL queue relying on NOTIFY postgres feature. the code is too small ( https://github.com/clj-lx/clj-pgqueue/blob/protocol-based-queue/src/clj_lx/impl/pgqueue.clj ) 60 lines could someone give some feedbacks/code-review the code ( it will be open source ) ? https://github.com/clj-lx/clj-pgqueue/tree/protocol-based-queue thx in advance

Daouda14:11:49

Hey folks, libs suggestion for password encryption in clojure?

Johan Basson15:11:34

Hi, is there an example for a basic rest api with the latest versions of httpkit, composure, ring, json? I'm struggling to find an example on how to start building a rest api using clojure which is fairly recent.

👍 4
sova-soars-the-sora15:11:11

Your best bet might be to start with the sente example project for real-time web comms and slim it down to suit your needs. You can choose HTTP-Kit as a server

practicalli-johnny12:11:22

@UKEAR38ES feel free to ask me any questions about the videos. httpkit and ring both use the ring approach, so most things will work with either library.

👍 4
sova-soars-the-sora15:11:12

I was sending plain maps over the wire {:map val} but now i'm sending a vector of maps [{m} {m2} {m3}] but i'm not sure how to digest that on the clojurescript side.

andy.fingerhut15:11:32

How were you digesting maps before? e.g. via a call to read or read-string, or something else?

sova-soars-the-sora15:11:23

(cljs.reader/read-string response) and then cramming the response into an atom

andy.fingerhut15:11:27

read-string should work fine to read a vector of maps, just as well as it can read a single map.

andy.fingerhut15:11:10

not sure if that is what you were concerned about -- perhaps you are concerned about how to deal with the difference between a map and a vector of maps after successfully reading it?

sova-soars-the-sora15:11:01

Okay, I think the problem is actually on the server side

andy.fingerhut15:11:29

One way would be to change your application on both sides so that it always sends and receives a vector of maps, if that is reasonable for your application.

andy.fingerhut15:11:57

If you really want it to sometimes transmit a map, and sometimes a vector of maps, and there is no ambiguity there, you can distinguish those cases on the receiver by a call to map? or vector?

sova-soars-the-sora15:11:23

Ah, thank you, that's a great idea...

sova-soars-the-sora15:11:38

I think the clientside might not care but the serverside has stopped producing a valid response for the client ;/

andy.fingerhut15:11:18

I know some people would recommend the "always send a vector of maps" approach first, where you send a vector of one map in every case that now you send a single map.

andy.fingerhut15:11:05

If the sending of a vector of maps is a bug on one side of your code, and it should only ever send a map, then yeah, fix the bug 🙂

sova-soars-the-sora15:11:26

well the serverside gets a result, prints it in the console, i want to send it to the client as a response from a POST, the client prints out null ;x

sova-soars-the-sora15:11:59

programming is amazing, incremental rocket construction

sova-soars-the-sora15:11:12

how to survive without a repl?

sova-soars-the-sora15:11:09

is there a way to print out any special characters i might be missing in the console?

sova-soars-the-sora15:11:33

-_- there's a space after the e-mail address

andy.fingerhut15:11:49

It can be tedious to look through, but if you have any string my-string, you can look at the sequence of numeric code points of all of its characters using an expression like (map int mystring)`

andy.fingerhut15:11:43

If you want to look for non-ASCII characters in a string, you can use filter on the resulting sequence to remove all character codes in any range you want, that you consider "normal", leaving only the "abnormal" ones

sova-soars-the-sora15:11:59

Ah, that's a cool trick

andy.fingerhut15:11:13

You can also use map-indexed instead of map to get the index of each character code, which might be helpful if you want to find out where those characters occur in the original string.

sova-soars-the-sora15:11:19

my (return-stuff) function was only printing things out

sova-soars-the-sora15:11:22

not actually returning values lol

sova-soars-the-sora15:11:49

my brain had an awesome WTF moment there 😃

sova-soars-the-sora16:11:36

So the clientside gets a vector of maps over the wire, but only grabs the first map.

sova-soars-the-sora16:11:37

forgot to encode as (str) before passing over the wire

Jacques Desmarais16:11:48

Following this announcement https://clojurians.slack.com/archives/C06MAR553/p1574608998245600, I get this error when running the tool:

$ clj -A:graph
Error building classpath. Unknown alias key: :deps
Help, someone?

sova-soars-the-sora16:11:26

@desm is there a stray key named :deps in one of the config files? sorry i can't be more specific.

Jacques Desmarais16:11:49

Thanks for trying to help. Is there a way to list the config files that get involved when I run that command?

sova-soars-the-sora16:11:18

hmm I wonder. Probably?

sova-soars-the-sora16:11:52

You may have to do that first

Jacques Desmarais16:11:59

Thanks sova, looks like I need to make sure I have a newer version of the clj command.

Jacques Desmarais16:11:11

Not tried it yet though

Alex Miller (Clojure team)16:11:38

Yes, you need newer clj

Jacques Desmarais20:11:15

yup, updating to a newer clj did the trick, thanks

ghadi16:11:18

@desm I think you need your clojure command line tools to be fresher

ghadi16:11:34

:deps is a recently added key

Jacques Desmarais16:11:25

oh ok @ghadi, I’ll try that

Jacques Desmarais16:11:33

thanks @ghadi, that helped me get further (to do brew upgrade clojure)

Jacques Desmarais16:11:47

Anyone ever seen this error before?

$ clj -A:graph 
Cannot run program "dot": error=2, No such file or directory
.IOException: Cannot run program "dot": error=2, No such file or directory
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
        at dorothy.jvm$render.invokeStatic(jvm.clj:67)
        at dorothy.jvm$render.invoke(jvm.clj:38)
        at dorothy.jvm$show_BANG_.invokeStatic(jvm.clj:138)
        at dorothy.jvm$show_BANG_.doInvoke(jvm.clj:108)
        at clojure.lang.RestFn.invoke(RestFn.java:410)
        at clojure.tools.deps.graph$make_graph.invokeStatic(graph.clj:107)
        at clojure.tools.deps.graph$make_graph.invoke(graph.clj:95)
        at clojure.tools.deps.graph$run.invokeStatic(graph.clj:186)
        at clojure.tools.deps.graph$run.invoke(graph.clj:160)
        at clojure.tools.deps.graph$_main.invokeStatic(graph.clj:205)
        at clojure.tools.deps.graph$_main.doInvoke(graph.clj:188)
        at clojure.lang.RestFn.invoke(RestFn.java:397)
        at clojure.lang.AFn.applyToHelper(AFn.java:152)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at clojure.lang.Var.applyTo(Var.java:705)
        at clojure.core$apply.invokeStatic(core.clj:665)
        at clojure.main$main_opt.invokeStatic(main.clj:514)
        at clojure.main$main_opt.invoke(main.clj:510)
        at clojure.main$main.invokeStatic(main.clj:664)
        at clojure.main$main.doInvoke(main.clj:616)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.lang.Var.applyTo(Var.java:705)
        at clojure.main.main(main.java:40)
Caused by: .IOException: error=2, No such file or directory
        at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
        at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
        ... 24 more

dpsutton16:11:13

It expects a program called “dot” on your path. I’m assuming that’s graphviz?

andy.fingerhut16:11:49

Dot is definitely part of graphviz, likely installable via brew as well if using a Mac

dharrigan16:11:46

Yes, definitely, graphviz is a hard dependency for that.

dharrigan16:11:53

That should be in the documentation and not assumed to be there.

dharrigan16:11:15

i.e., on the github page

andy.fingerhut16:11:17

Definitely. That way when someone does not read the readme, you can link to it :-). Sorry for that comment - I have spent time trying to make install docs complete and there is always some noticeable fraction that miss it anyway.

dpsutton16:11:37

Oh I didn’t realize it was about the clj tooling Thought it was some random lib

andy.fingerhut17:11:03

It is an optional add-on for clj tooling, released yesterday.

Artur Aralin17:11:08

Hi all (again 🙂). I have next code

(def myref (ref []))

(defn add-val-to-ref [val]
  (dosync
    (ref-set (conj @myref val)))
add-val-to-ref calls async by different threads. How can I do all incoming vals be in order of incoming from threads?
T1 (add-val-to-ref 10)
T2 (add-val-to-ref 20)
T1 (add-val-to-ref 30)
T1 (add-val-to-ref 40)
T2 (add-val-to-ref 50)

@myref [10 20 30 40 50]

andy.fingerhut19:11:55

I may be missing something - what evidence do you have that leads you to believe the results are not in the same order as the calls to add-val-to-ref ?

Artur Aralin05:11:52

I solved the problem. Blame frontend.

andy.fingerhut06:11:28

Cool you solved it .