This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-08
Channels
- # 100-days-of-code (4)
- # aws (1)
- # beginners (69)
- # business (1)
- # calva (1)
- # cider (10)
- # cljdoc (1)
- # cljs-dev (7)
- # clojure (49)
- # clojure-dev (4)
- # clojure-italy (2)
- # clojure-nl (11)
- # clojure-russia (2)
- # clojure-spec (7)
- # clojure-uk (64)
- # clojurescript (18)
- # clojurex (1)
- # core-async (11)
- # cursive (22)
- # datascript (7)
- # datomic (45)
- # editors (6)
- # emacs (7)
- # events (1)
- # fulcro (20)
- # graphql (1)
- # jobs (18)
- # jobs-discuss (132)
- # leiningen (2)
- # nyc (5)
- # off-topic (6)
- # onyx (2)
- # pedestal (3)
- # re-frame (8)
- # remote-jobs (6)
- # ring-swagger (2)
- # shadow-cljs (64)
- # specter (2)
- # tools-deps (4)
- # unrepl (1)
- # yada (3)
The two vectors beginning are compared… would comparing subvectors of the size of the smallest be fast enough?
This is very similar to determining whether one string is a substring of another. If you want to do that in guaranteed linear time, even when the substring and the one you are checking to see if it is a substring of have repetitive patterns in them, you need to do some kind of preprocessing. e.g. imagine if your substring to check if it was inside of another was "01010101012", and the string you were checking inside of had many occurrences of "010101011". The most straightforward approach would find out that there was a mismatch starting at the first "01", then again at the second "01", and at the third, and then the fourth. Each of those 2nd through 4th checks wastes time, that if you were cleverer in your algorithm you could skip past all of those without rechecking.
That is what the Boyer-Moore string matching algorithm does -- be clever about jumping ahead after a partial match failed.
If you don't care about guaranteed linear time, and/or if repeated elements are not common in the vectors you are dealing with, then just scanning the larger vector for occurrences of the first element of the smaller one, and wherever you find it, compare the subverter of the larger one to the smaller one, would be linear time.
(clarifying -- if the vectors are guaranteed to have no repeated elements, then the simple approach is linear time. If they can have repeated elements, the simple algorithm can take quadratic time in the worst case).
The Z-Algorithm is another approach too although I think it’s a bit less sophisticated than Boyer Moore.
The cool thing about these algorithms is that you can find matches in sublinear time.
Use Knuth-Morris-Pratt for short search elements
Boyer-Moore for long ones
similarly for "alphabet" sizes
hey folks does anyone know why clojure.core/map
would have different performance characteristics from my-map
if the source is identical?
what's my-map
@djtango?
I can't probably help you because I'm a clojure newbie
Possibilities: aot from a library, or it's been running longer so the jvm has had a chance to optimise it more
I'd say the performance should be identical but I'm not a clojure expert @djtango 🙂
btw, why do you want to have a copy of the original function?
the core one is AOT compiled and direct-linked
user=> (def a (future (loop [] (recur))))
#'user/a
user=> (future-cancel a)
true
user=> @a
Evaluation error at java.util.concurrent.FutureTask.report (FutureTask.java:121). CancellationException null
@bronsa I have some future that somehow continues running, but I can’t reproduce it in this example:
(do
(def f (future
(try
(while true
(Thread/sleep 100)
(debug "interrupted?"
(Thread/interrupted))))
10))
(Thread/sleep 1000)
(future-cancel f)
(println (future-cancelled? f)))
Here Thread/interrupted always returns false.
In my other future, I see (Thread/interrupted)
is true
after I cancelled it. When do you have to check Thread/interrupted@borkdude cancelling a future doesn't cause interruption of the thread, you indeed have to manually check Thread/interrupted
and stop the thread manually
(do (def f (future (while (not (Thread/interrupted)) (Thread/sleep 100) (binding [*out* *err*] (println "interrupted?" (Thread/interrupted)))))) (Thread/sleep 500) (future-cancel f))
@bronsa will Thread/interrupted return false after future-cancel or am I wrong here?
@seancorfield @noisesmith Thanks for the help the other day regarding connecting to Redshift! I got it to work, it is now simple, short and elegant code as Clojure solutions usually are. Turns out I overlooked the port number, and had the wrong one. Also, I removed the extraneous connection parameters you mentioned. Thanks a ton!
Cool! Thank you for reporting back on your success!
Also, let me know -- as the maintainer of clojure.java.jdbc
-- if there are things I could do to make interaction with RedShift easier (since it's not a system I use myself).
@seancorfield Will do, I'm just getting my feet wet with Redshift interaction via Clojure. I'm hoping to move much of the ETL type work I do at my company into pure Clojure. I am hoping Clojure and REPL will a good environment for me and potentially others to work in interactively to quickly test things out with the data, vs all the clunky hodgepodge of shell and SQL scripts we are using now. Also, creating easily reproducible pipelines is a goal. I'm looking at Drake and Honey SQL libraries as well in the effort.
While we are on this subject, I'm a bit disappointed that there seems to be no idiomatic way to create a persistent db connection object. I know there's with-* functions etc, but when working at the REPL all day it would be nice to be able to just keep the db connection alive (much like I do with my very fast psql
cli prompt) and be able to pass it into jdbc functions, e.g., (jdbc/query persistent-db-conn "select foo from bar")
. Anyone have suggestions for such a workflow?
At work we use c3p0 to create a connection pool. I gather HikariCP is another good option.
I would expect you could use a connection pool with RedShift?
Cool, I'll take a look and see. I glanced at c3p0 just earlier today but haven't tried it out yet.
Wrap it in a Component. Then you can
(defonce system nil)
...
(alter-var-root #'system component/start)
... work with (:db-spec system) ...
(alter-var-root #'system component/stop)
...
(assuming start
creates the connection pool and assoc
s into the Component as :db-spec
)
yeah, I found using c3p0 directly via interop and putting it in a component Just Works ™️
Write it once and forget it, yes. We have a DataSource Component that hides all the Java interop but still provides optional dials and knobs to tune the connection pool if needed.
Hi. Is anyone using a library to generate Markdown from a Clojure datastructure similar how hiccup does it? I'm aware of merkki and marge both of which look more like a proof of concept than a library really being used. But maybe I'm wrong? Happy to learn more and to contribute. https://github.com/jarcane/merkki https://github.com/markwoodhall/marge
I've not seen merkki before, I started playing around with marge because of a side project I used it on. I know of a couple of organisations that have given feedback about using it.