Fork me on GitHub
#clojure
<
2020-07-08
>
dominicm10:07:08

I've been playing with @borkdude's carve, and I've started using it as a basis for building code rewriting tools. Mostly one-off things. But the code (and the clever loop that borkdude came up with) is great for rewriting old functions to new ones in an automatic way.

šŸ‘ 6
Frosku18:07:59

I'm looking for a graph database that's easy to set up and has a mature Clojure client library, any suggestions?

Frosku18:07:17

Oooo, supports Kafka by default.

Frosku22:07:43

@U051V5LLP Just worked through the tutorial for Crux, seems really solid.

dvingo00:07:44

nice! it is pretty amazing

stopa04:07:19

Indeed this looks really cool! Side note: def think there is some startup idea, to build a firebase-like offering, but with something like crux backing it. You can do more complex queries, remember past information, maybe a dsl that a user can use to add permissions, and bam

dvingo12:07:06

ha, it's def in the adjacent possible - here's a good start already: https://findka.com/biff/#introduction

ā¤ļø 3
stopa18:07:20

veery cool!

dvingo10:07:19

hey, what's up?

Frosku11:07:40

Just having Crux issues, I can't re-mount it to make it work

Frosku11:07:28

I wrote a CLI script which downloads all or subsets of a public image archive, and inserts the metadata into Crux

Frosku11:07:13

What I want to do now is open the database and see if the data actually saved in it

dvingo12:07:16

very cool! when I was starting out with crux I ran into data retention issues, it turned out to be 2 issues: ā€¢ in memory tx-logs instead of being persisted ā€¢ all tx's are async by default I ended up using this helper to make all tx's synchronous for my app code https://github.com/dvingo/my-clj-utils/blob/master/src/main/dv/crux_util.clj#L60 and making sure all writes are fsync'd on the node https://github.com/dvingo/my-clj-utils/blob/master/src/main/dv/crux_node.clj#L20

dvingo12:07:06

The crux source has some gems as well. Here are 2 more node config examples https://github.com/juxt/crux/blob/master/dev/user.clj#L29

Frosku12:07:40

Thanks, I'll try the event log store, I turned on sync.

Frosku12:07:53

You're a genius

Frosku12:07:08

Please put this in the docs lol

dvingo13:07:15

I knowwww, pls suggest that in the crux channel

Frosku18:07:12

I don't need web scale, but it has to be reasonably performant.

rmxm18:07:20

I have a code in namespace X, that code has caching via memoize. So in I have X: (def get-val (memoize load-val)) (def some-map (get-val)) (def some-key (:key some-map). Now when I import namespace X into namespace Y and try and call (prn X/some-key) - > I am getting: #object[clojure.core$constantly$fn__5394 0x50ecef36 "clojure.core$constantly$fn__5394@50ecef36"] While if I call in the same namespace, its just a plain value.

noisesmith18:07:03

try calling it (X/some-key) - that will return the same thing no matter how many args it is given

noisesmith18:07:19

sounds like your namespaces are out of sync

rmxm18:07:20

yeah I know

rmxm18:07:30

but its inconsistent

noisesmith18:07:49

what you provide there isn't enough to know what's wrong, as it's not how clojure behaves, something else is up on your local repl state

rmxm18:07:50

from the same namespace i get value, from someother namespace I have function.

rmxm18:07:46

any tips for the witch-hunt šŸ™‚?

noisesmith18:07:39

I'd start with a full shutdown of the repl and clean up of any cache

noisesmith18:07:56

(eg. class files you might have generated under target/)

rmxm18:07:05

it happens in unittest, so I am not particularly placed in repl env

hiredman18:07:05

you(or some tool you are using) is deleting clojure namespaces, and defining them without redefining the namespaces they depend on

hiredman18:07:36

scratch that

hiredman18:07:47

some tool is just defing the var

hiredman18:07:39

somewhere something is doing (alter-var-root #'get-val (constantly 'whatever))

hiredman18:07:01

the reason you see different values is because you doing things at different times

rmxm18:07:20

ok, thanks for hints

hiredman18:07:20

and in the time in between other side effecting (var value changing) code is running

hiredman18:07:43

given it is in tests it is likely some heavy handed test mocking

hiredman18:07:11

and depending, your test mocking may be stepping on itself, a lot of mocking code that mutates vars is not thread safe, and may not be safe to nest

hiredman18:07:03

(my wild irresponsible guess would be you are using midje)

Ben Sless19:07:53

Question about writing libraries wrapping java libraries: It makes sense (to me) to map enums to keywords and use utility functions to transform POJOs to maps. I don't want my users to .getThis and .getThat every time they want to work with Just Data. Would you rather the keywords be namespace qualified? i.e. :state vs. :domain.object/state. The first option looks like it might be easier to work with, at the cost of information and context loss. What do you think?

noisesmith19:07:11

I think it's best not to wrap things unless the API is designed to waste your time or be error prone

noisesmith19:07:44

I guess there's also the use case of portability but that usually doesn't work as well as planned

Ben Sless19:07:54

You mean not to wrap Java libs/clients at all?

noisesmith19:07:19

I mean not to wrap them unless there's an urgency, in the long run it's usually causes more problems than it solves (wrappers are incomplete, the author didn't really understand the API, ...)

noisesmith19:07:05

but that's very generic advice, and I don't mean to be combative

noisesmith19:07:20

there might be a valid reason to make your wrapper, I just want people to consider the question carefully

Ben Sless19:07:42

You aren't coming off as combative, it's okay. Giving me a lot to consider, is all

noisesmith19:07:58

I'd usually use non-namespaced keys if there is a reason to wrap, but in the big picture there's less reason to wrap a POJO, and more reason to wrap things that require inheritance (clumsy in clojure) or factories (very easy to simplify in clojure)

Ben Sless19:07:53

Alright, thank you šŸ™‚

seancorfield20:07:33

@ben.sless Also, when dealing with POJOs, look at clojure.core/bean for simple cases and org.clojure/java.data library for more complex stuff.

ā¤ļø 9
seancorfield20:07:05

The latter handles the builder syntax as well as the bean syntax, and knows how to handle constructors and various other things.

Ben Sless20:07:25

Will do, thanks šŸ™ƒ

Ben Sless20:07:40

Should I refer to next.jdbc.datafy for examples?

seancorfield20:07:22

LMK if you have specific questions about it.

chrisblom20:07:34

What am I doing wrong with buddy here?

(require '[buddy.hashers]
         '[buddy.auth.backends :as backends]
         '[buddy.auth.middleware :refer [wrap-authentication]])

(defn authfn [request {:keys [username password]}]
  (when-let [password-hash (get {"admin" (buddy.hashers/derive "admin")} username)]
    (buddy.hashers/check password password-hash)))

(authfn {} {:username "admin" :password "admin"}) ; => true
(authfn {} {:username "admin" :password "wrong"}) ; => false

(defn handler [request]
  {:status 200 :body "ok" :req request})

(let [backend (buddy.auth.backends/http-basic {:authfn authfn} )
      app (-> handler
              (buddy.auth.middleware/wrap-authorization backend)
              (buddy.auth.middleware/wrap-authentication backend))
      request {:headers {"Authorization" "incorrect password"}}]
  (app request)) ; should return a 403, but returns the 200 response

chrisblom20:07:30

Got it, the handler should throw an exception if not authenticated:

chrisblom20:07:38

(defn handler [request]
  (if (buddy.auth/authenticated? request)
    {:status 200 :body "ok" :req request}
    (buddy.auth/throw-unauthorized)))

chrisblom20:07:54

I expected the middleware to do it all for me

chrisblom21:07:01

Maybe i'll write an auth library with an honest name some day

chrisblom21:07:31

Not 'buddy' or 'friend', but 'nemesis'

adam04:07:25

Lol. I started using buddy yesterday and it's pretty amazing, especially wrwrap-access-rules middleware and its rules mechanism

chrisblom07:07:48

buddy is ok, i was just traumatized by friend

jrychter08:07:37

Buddy is pretty good. Friend is very opinionated and I found it difficult to fit into my architecture.