Fork me on GitHub
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)


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 ( ) 60 lines could someone give some feedbacks/code-review the code ( it will be open source ) ? thx in advance


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

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


@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

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.


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


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


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


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?


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


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.


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?


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


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


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.


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 🙂


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


programming is amazing, incremental rocket construction


how to survive without a repl?


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


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


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


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


Ah, that's a cool trick


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.


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


not actually returning values lol


my brain had an awesome WTF moment there 😃


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


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

Jacques Desmarais16:11:48

Following this announcement, I get this error when running the tool:

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


@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?


hmm I wonder. Probably?


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


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


: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(
        at java.base/java.lang.ProcessBuilder.start(
        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(
        at clojure.lang.RestFn.invoke(
        at clojure.lang.AFn.applyToHelper(
        at clojure.lang.RestFn.applyTo(
        at clojure.lang.Var.applyTo(
        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(
        at clojure.lang.Var.applyTo(
        at clojure.main.main(
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>(
        at java.base/java.lang.ProcessImpl.start(
        at java.base/java.lang.ProcessBuilder.start(
        ... 24 more


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


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


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


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


i.e., on the github page


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.


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


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


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.


Cool you solved it .