This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-16
Channels
- # 100-days-of-code (16)
- # beginners (67)
- # boot (5)
- # cljs-dev (52)
- # cljsjs (2)
- # clojure (94)
- # clojure-spec (34)
- # clojure-uk (10)
- # clojurescript (91)
- # clojutre (1)
- # core-async (20)
- # cursive (5)
- # datomic (1)
- # figwheel-main (70)
- # fulcro (101)
- # hyperfiddle (3)
- # jobs (1)
- # klipse (16)
- # mount (1)
- # nrepl (3)
- # off-topic (24)
- # portkey (39)
- # re-frame (4)
- # reitit (1)
- # shadow-cljs (3)
- # spacemacs (9)
- # tools-deps (5)
Anyone have any best-practices, patterns, or clever macros for unobtrusive logging in clojure code? My current approach usually results in adding do
blocks or unused bindings within let
blocks.
Do you mean logging or tracing? What is your goal with logging @nick652?
Oh right. My goal at the moment would be more accurately described as tracing. I’m trying to output enough data that it’s possible to reproduce a user-reported issue by examining my backend trace output.
Have you looked at tools.trace
?
Not until now. Looks great! Is it a commonly used approach in released code, or is it usually just used in development?
Thanks for pointing me to that, in any case. It’s just what I was looking for (I think).
I personally haven't used it but I know some people seem to love tools.trace
...
Whenever I talk about running a REPL inside production processes to debug and/or fix issues, there are always a lot of folks who are shocked about that. Using tools.trace
in released code seems to require using a REPL (to apply and then remove tracing) so...
I've used tools.trace and it's kinda nice for systems where you don't have a ton of schema/spec validation to enable to narrow down issues
I think sayid replaced tools.trace in the spacemacs Clojure layer and that's what I used most recently for tracing something. I tend to just use the step debugger with a condition if I'm not in prod (or if I can isolate traffic)
sayid looks interesting, thanks for the suggestion
Is there any reason to use clj-http
over clj-http-lite
if the latter has all the features you need?
Need some help with regex matching 😞
(def banned-words
["token" "password"])
(def filter-regexp
(let [left-part (reduce #(str %1 %2 "|") "(.*)(" banned-words)
right-part " \\\"([a-zA-Z0-9.]+)\\\""
normalize-left #(if (string/ends-with? % "|") (string/join (butlast %)) %)]
(Pattern/compile (str (normalize-left left-part) ")" right-part))))
I wanted to create a regexp like #"(.*)(token|password) \\"([a-zA-Z0-9.]+)\\""
but for some reason java Pattern removes the slash #"(.*)(token|password) \"([a-zA-Z0-9.]+)\""
and I am unable to match the string string.
EDIT:
Here is the string I want to match "Ended [req :get] [path /development/installation-access-token] [s 200] [bd {:token \"v1.1231231231231\"}]"
Please help 😛I think the correct regex is (.*)(token|password) "([a-zA-Z0-9.]+)"
, not (.*)(token|password) \"([a-zA-Z0-9.]+)\"
that would be
(def filter-regexp
(let [left-part (reduce #(str %1 %2 "|") "(.*)(" banned-words)
right-part " \"([a-zA-Z0-9.]+)\""
normalize-left #(if (str/ends-with? % "|") (str/join (butlast %)) %)]
(str (normalize-left left-part) ")" right-part)))
@roti Check please the string which I want to match 😛 https://regexr.com/3vi8f As you can see your regexp does not match the string.
The correct regexp is #"(.*)(token|password) \\"([a-zA-Z0-9.]+)\\""
but for some reason java.util.Pattern removes the slash ;(
anyway, you want to match the backslash as well, so it needs to be escaped in regex (and then again in the Java string 🙂 )
@roti My regexp matches 😛 Please check https://regexr.com/3vi8r It's escaped: right-part " \\\"([a-zA-Z0-9.]+)\\\""
that would be this:
(def filter-regexp
(let [left-part (reduce #(str %1 %2 "|") "(.*)(" banned-words)
right-part " \\\\\"([a-zA-Z0-9.]+)\\\\\""
normalize-left #(if (str/ends-with? % "|") (str/join (butlast %)) %)]
(str (normalize-left left-part) ")" right-part)))
you need to escape backslash twice, once because of Java Strings, and again because of reged syntax
(def string
"Ended [req :get] [path /development/installation-access-token] [s 200] [bd {:token \"v1.12312312312312312312\"}]")
(re-matches filter-regexp string)
It does not match anything 😞Ok I got this sorry Roti! My bad ;( thank you very much for your help. You was right since the beginning.
Does someone have a sample how to do interactive web development with ring/compojure/hiccup/jetty? I tried several samples that use ring-jetty-adapter, but none of them worked.
@roti I Did 'lein new compojure my-webapp' but this did not have any code for starting /stopping the http server in the repl.
Most of the samples I found use "lein ring server" - but when I do that, then I loose all of the interactive development experience of the repl.
what about this one? https://github.com/weavejester/compojure-example
first, you should know that the code is automatically loaded when you run with "lein ring server"
"lein ring server" seems to compile the project, then run the function that is defined in the project.clj
oh, I did not read your message carefully. hmm, I think ring-jetty-adapter should do the trick. in the past it was mentioned in the compojure wiki, now I see it's gone
well, if you want the repl you just have to start jetty yourself. the jetty-adapter was a helper for that, but you can also start jetty yourself, it's more work though
actually, this is the helper I was using, not the jetty adapter: https://github.com/weavejester/ring-serve
BTW: the leinigen ring runner, it recompiles the solution, but it does not push the new version to the browser. I have seen some presentation by I thikn bob bauman, where everything was getting live reloaded.
I don't think it's possible. you could have some piece of code in the browser which would make a request to the server when something changed and then compute a diff and apply it, but it would run into problems because the old state (kept in javascript variables) might not be compatible with the new page. if you don't have such state in your page, then yes it would work, but it would only spare you a keypress
the big value which figwheel offers is loading code changes while keeping the state. so if you work on some component which you need 4-5 user actions to reach, it will spare you those actions (like: login, then search for "xxx", click on the second result)
I believe I saw a library which did such diffing with ring, but I can't remember the name now
It would be really cool, to have a library that sends you the data from the server to the reagent client sort of automatically,
I tried just copying the one source code file over, but then I could not find the dependency org.mortbay.log.Logger
playing around with writing scripts to run on the command line. How can I "return" strings so they can be piped and manipulated in the shell after running?
I can print them but they don't seem to be able to be piped and manipulated after the program finishes
clj -m levenshtein ant and | echo
i would hope to echo 1 but nothing gets piped through
Any #honeysql gurus out there at the moment? I'm using honey in a JVM lambda function and have loved it so far. However, I just went to deploy code and I'm over my 70 MB jar limit. Honey appears to pull in 20+ MB of goog
dependencies. Does anyone know if it's possible to build and use without these deps? Am I possibly doing something incorrectly that brings in Clojurescript deps?
if you use leiningen to create your jar, you can add a global :exclusions
clause, and if you don't hit code paths that need that artifact it should just work
Great. Thanks, I'll give that a go. I don't know exactly how #honeysql is implemented. I'll need to figure out where and why goog
is used.
my first guess is that it comes in via cljs - you can check lein deps :tree
Cheers, @noisesmith. I'll dig around
somebody save me from myself: at work we’re using a headless CMS (basically a RESTish DB-as-a-service), but we’re likely to move to a regular DB - either DynamoDB or some RDBS - in the future. so I’ve implemented a data-oriented DSL for creating tables in the headless CMS, and am now contemplating implementing something similar to datomic’s query language as well, with the idea that we could write a driver to use it with DDB or Postgres or what-have-you later. Is this… is this a bad idea? I feel like this must be a bad idea, but I’m not experienced enough with DBs to know why yet.
There’s a project for pull syntax for sql DBs here https://github.com/walkable-server/walkable
Rolling out your own query engine for something as expressive as Datalog on top of a remote data source certainly is a big endeavour, even without performance constraints. Probably a bad idea unless you lower your ambitions
how would you hedge yourself against the fact that your remote data source will change in the near future?
I’d isolate where those data sources are used. E.g., use abstracted functions rather than the core data source. For example, use a (get-items [db] ..) function that internally uses some driver, rather than calling (jdbc/query conn ..) itself