Fork me on GitHub
#clojure
<
2019-01-14
>
Alex Miller (Clojure team)03:01:15

Classes are not constants

Alex Miller (Clojure team)03:01:38

condp with = is a good match for this though

grounded_sage03:01:45

I'm getting this when I run 'clj' on a fresh linux install.

cp: cannot stat 'PREFIX/example-deps.edn': No such file or directory

grounded_sage04:01:34

ok so I found in old slack logs its to do with a botched clojure install

grounded_sage04:01:32

I can't get it installed though. If I remove the install from linuxbrew then it gives me. bash: /home/linuxbrew/.linuxbrew/bin/clj: No such file or directory but if I use brew I get the other error.

WhoNeedszZz04:01:57

Is there not a clojure package in your distro's package manger?

grounded_sage07:01:20

I managed to fix it. I completely removed linuxbrew and followed instructions on Linux install on Clojure website

WhoNeedszZz07:01:09

Glad to hear, but that may not be necessary if your distro has a package for it. The method on the website is manual updating

theeternalpulse05:01:59

are there core functions/macros that do something similar to this ones I've made

(defmacro anon-proxy
  [draw-fn]
  `(fn [& ~'args]
     (apply ~draw-fn ~'args)))

(defmacro map-keyed
  {:style/indent :defn}
  [& args]
  `(->> (list ~@args)
        (interleave (map keyword '(~@args)))
        (apply hash-map)))

theeternalpulse05:01:30

the first is for live coding with some libraries since you have to have function that calls the one you'll be re-deffing

Alex Miller (Clojure team)14:01:14

vars can be invoked and when done, will invoke the function they hold. so I think they already serve this purpose and on the caller side if you just invoked the var, you could change the var binding as much as you want.

theeternalpulse05:01:42

the second is to just get a key/value from a collection of symbols that are in scope.

dottedmag14:01:57

Is there a generic-ish way to transform stateful systems in functional ones? Namely, I have a server serving a complicated stateful protocol (Wayland to be precise), and would like to read some guide or a war story of turning these webs-of-mutating-objects into something more manageable.

dazld14:01:46

I’m having some fun with the cognitect AWS library, specifically with the KMS functions.. is there a good place to ask questions around this..?

dazld14:01:00

the hash aws channel here seems dead 😞

dazld14:01:26

{"__type" "InvalidCiphertextException", :cognitect.anomalies/category :cognitect.anomalies/incorrect} < trying to find out what this means

dazld14:01:26

the :Decrypt docs say :CiphertextBlob blob

gordon15:01:22

this info gave me enough to check the Java SDK API docs: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/kms/model/DecryptRequest.html#setCiphertextBlob-java.nio.ByteBuffer- and it looks like it takes a java.nio.ByteBuffer

👍 5
dazld16:01:45

I used amazonica for now but when i go back to this, will try it out

dazld16:01:25

it’s all pretty obscure, a couple of helper functions here would be really welcome

dazld14:01:34

but doesn’t really elaborate what blob is

dazld14:01:55

i’ve tried byte array, buffered input stream, string..

dazld14:01:51

the ciphertextblob output from encrypt is a bufferedinputstream

ghadi14:01:59

@dazld have you enabled validation?

dazld14:01:29

that sounds like it might be helpful

dazld14:01:57

how do I do that..?

dazld14:01:08

there’s nothing about validation in the readme

dazld14:01:13

(aws/validate-requests some-client true)?

dazld14:01:49

that really should be in the docs.. think they’d take a PR?

ghadi14:01:08

PRs not accepted, but file an issue please

mkvlr14:01:04

is there ways people work around the fact that strings and other primitives don’t implement IMeta? For a similar use case as REBL I’d like to allow different viewers for data and I’d like this to work for strings and numbers as well…

kwladyka15:01:56

{:status 200,
 :headers {"Content-Type" "application/json; charset=utf-8", "Vary" "Accept", "Content-Length" "44"},
 :body #object[java.io.BufferedInputStream 0x109943d3 "java.io.BufferedInputStream@109943d3"]}
How do you show maps with objects like in this example, but converted to the value (string) I need it for developing purpose

dazld15:01:44

slurp it?

kwladyka15:01:43

But I don’t want to do it on :body. I would like to have fn like (show-me-values m). Perhaps such function doesn’t exist 🙂

kwladyka15:01:01

But maybe it exists, so I am asking 🙂

dazld15:01:08

not afaik!

kwladyka16:01:44

What buddy exactly add on top of ring sessions? http://funcool.github.io/buddy-auth/latest/#session ? It doesn’t look like it is adding something special, but maybe I miss something. Asking in different way: I need to make sessions based on DB, I am thinking about https://github.com/clojusc/ring-redis-session . Does it make sense to glue it in some way with buddy?

victorb16:01:59

@kwladyka aren't ring sessions just for authentication? Buddy seems to give you authorization too

kwladyka16:01:46

Maybe. I am not sure what exactly buddy add. I didn’t use it before.

kwladyka16:01:31

But I see in buddy doc Authentication with sessions

kwladyka16:01:55

But there is no info what exactly is the point of using it

kwladyka16:01:02

I am trying to figure out if buddy is something for me or not. What I can use from there.

kwladyka16:01:44

I don’t see too much benefits while I am using liberator, but maybe I miss something. Am I miss something?

jdkealy18:01:42

any advice on how to parse this string (read-string "09")... It's an invalid number, was gonna maybe strip zero's but if there's anything less complicated, i'd love to know 🙂

java.lang.NumberFormatException: Invalid number: 09

souenzzo18:01:07

read-string is not safe (read-string "#=(prn :code-injection)") Prefer edn/read-string But sure, to parse a number, you can use Long or (bigdec "09")

temco03:01:26

read-string cannot recognize a decimal number headed with 0, but it recognizes "00" - "07", why? they're considered as octal ones

hiredman18:01:01

user=> (Long/parseLong "09" 10)
9
user=> 

hiredman18:01:06

using read-string to turn a string in to a number is using a missile to swat a fly

rutledgepaulv18:01:38

also read-string has security implications if it’s user input

✔️ 5
rutledgepaulv18:01:45

(read-string "#=(slurp \"/etc/passwd\")")

jdkealy18:01:50

cool good to know !

kwladyka18:01:57

What do you use for sessions in clouds with solution like kubernetes? redis to store sessions? sessionAffinity? I think the best solution is redis, but maybe I am in mistake 🙂 What do you use to store sessions and why?

jdkealy18:01:01

I've used Redis for session stores all the way back to my Ruby on Rails days, so I just use the same thing in clojure apps.

👍 5
jdkealy18:01:42

But... my new app uses a datomic db. So I could probably just use that. But I'm also using redis for a message queue, so, why not... If it ain't broke.

kwladyka18:01:09

redis is probably faster for session purpose - my guess

jdkealy18:01:25

Also I guess redis is nice too for expiring sessions.

kwladyka18:01:26

Cool you can use Datomic. It is a little expensive 😉

jdkealy18:01:47

yeah... i presume redis is faster. But then again, I'm storing a session key and a user id value, and then looking the user up in datomic anyways.

kwladyka19:01:27

hmm make sense

kwladyka19:01:46

but the point is you have a token for session

lilactown19:01:33

@jdkealy for temporary session-state type things, redis would be a better fit than datomic

lilactown19:01:57

datomic is best used as a system of record. for sessions that you want to throw away after 30 mins or whatever, you're going to end up growing your database very quickly and probably don't need a lot of what datomic brings to the table (at the cost of increased overhead)

devn23:01:05

Best way to implement first-and-only, which checks that there is only one item in coll, and throws otherwise?

(first-and-only [1]) => 1
(first-and-only []) => Exception
(first-and-only [1 2 3]) => Exception
(first-and-only nil) => Exception
(first-and-only 1) => Exception
(first-and-only [nil]) => nil
(first-and-only [nil nil]) => Exception

devn23:01:16

(defn first-and-only [x]
  (if (coll? x)
    (if (and (seq x)
             (next x)
             (first x))
      (throw (Exception. "too many"))
      (first x))
    (throw (Exception. "not a coll"))))
is close, but for instance, wouldn't catch the scenario where the next element is nil

chrisulloa23:01:28

Can’t you just count and see if it has 1 item in it?

devn23:01:23

i don't want to count if i can avoid it

devn23:01:39

if it contains 1029438294839248392 elements, i don't want to count all of them

chrisulloa23:01:33

ah that’s fair

Alex Miller (Clojure team)23:01:58

There’s bounded-count

devn23:01:06

there's a way to do this. i've written this maybe 4 times, but i forget the solution

devn23:01:19

ah, never used bounded-count, but that's cool!

devn23:01:24

(defn first-and-only [x]
  (if (coll? x)
    (let [bc (bounded-count 1 x)]
      (condp = bc
        0 (throw (Exception. "not enough"))
        1 (first x)
        (throw (Exception. "too many")) ))
    (throw (Exception. "not a collection"))))
bleep bloop

souenzzo23:01:29

@devn solutin with #specter

(select-one! ALL [1])
;; => 1
;; This thows with a 'good' error
(select-one! ALL [])
(select-one! ALL (range))
(select-one! ALL [1 2])

dpsutton23:01:03

If the bounded count throws the right error you might just be able to use and bounded count = 1 and then first