Fork me on GitHub
#clojure
<
2016-12-07
>
roelofw07:12:05

I have this code :

(ns paintings2.api-get
  (:require [clj-http.client :as client]
            [environ.core :refer [env]]))


(defn read-numbers
  "Reads the ids of the paintings"
  []
  (let [ids (->> ( str "" (env :key)  "&format=json&type=schilderij&toppieces=True")
                 (client/get {:as :json})
                 :body
                 :artObjects
                 (map :id))
        ids (reduce (fn [results id] (conj results (.substring id 3))) [] ids)]
    ids))  

roelofw07:12:12

but when I run it , I see this error message

java.lang.String cannot be cast to clojure.lang.IPersistentCollection 
on the 'client/get` part

Maxim07:12:46

@roelofw (client/get "" {:as :json}) {:as :json} should NOT be the first arg

Maxim07:12:08

in your case it becomes this (because of ->>) (client/get {:as :json} “

roelofw07:12:16

sorry, I do not understand what you mean

roelofw07:12:29

I do the whole time this without any problems

Maxim07:12:17

I meant that regarding docs for clj-http the first arg to client/get is URI.

roelofw07:12:48

@mkaschenko yes, that is correct : (client/get "" {:as :json})

roelofw07:12:22

I use the -> so the output of str is the first argument of client/get

Maxim07:12:34

But ->> puts ( str "" (env :key) “&format=json&type=schilderij&toppieces=True”) as the last arg

roelofw07:12:53

oke, that is what you mean

roelofw07:12:12

chips , still something wrong. I see a 403 error 😞

Maxim07:12:16

At least it sends a request now 🙂

roelofw07:12:08

yes, there you are right

roelofw08:12:47

I think I have to find out how to add my key to profiles.clj

roelofw08:12:13

I did put it into .lein-env but then things get overwritten

roelofw08:12:56

This :profiles/test {:env {} means the profiles/test get added to the enviroment ?

roelofw08:12:37

I have to add :key <masked> to the enviroment

roelofw08:12:23

I added {:key <mnasked>} {:env{}} to profiles.clj and try to read it with (env :key) but no value is returned

roelofw08:12:36

someone who can help me with this ?

agile_geek09:12:21

@roelofw what library are you using for reading your environment variables?

agile_geek09:12:13

If you are using @weavejester's environ https://github.com/weavejester/environ#Usage he mentions here you can add environment specific defaults into a separate profiles.clj file in your project directory that you might not want to commit to version control if it's got sensitive info (passwords etc.)

agile_geek09:12:59

alternatively you can add environment specific defaults to you project.clj in the :profiles section

agile_geek09:12:47

:profiles
  {:dev
   {:env {:port 3000,
             :host "localhost"
             :db-uri "jdbc:h2:./gallery?user=sa&password=;database_to_upper=false"
             :galleries-path "galleries"}}}
...

agile_geek09:12:31

but remember the whole point is you can set environment variables on you machine to override these using export (linux) in a .sh file that runs your app or set in a windows .bat file

bcbradley09:12:59

Suppose I have a use case for r/fold where I have a bunch of maps as elements of a collection. These elements will be mapped to arrays of elements and concatenated (mapcat) using a fairly expensive mapping function. There may be fewer, and equal number, or more elements yielded from the mapcat than were fed into it. But most importantly, I do not care about the order of the elements. The documentation states that the combinef argument supplied to r/fold must be associative. In the semantics of my use case, elements returned in one order is the same as being returned in any other order, so can I use concat as a combinef? What confuses me is that strictly speaking concat isn't associative, but my gut tells me it will be fine. What do you think?

bcbradley09:12:23

looks interesting, I'm looking it over. I'd still like to know whether combinef argument in r/fold will make volcanoes if I give it a non associative function, or whether it will simply use it as if it were an associative function and simply return things out of order in the case that the non associative function of choice is just concat

roelofw10:12:28

@agile_geek . oke, and then I can do something like this :

{:env {:key <masked} 
in the profiles.clj and read it with '(env :key)` ?

agile_geek10:12:26

See example above. In profiles it needs to be under a profile, in my example :dev

agile_geek10:12:17

so in my example, using environ I could read the port number using this (env :port)

roelofw10:12:18

oke, so I can use your example and adapt it

roelofw10:12:50

So, if I need that for :dev and for :production I need to do the same code two times ?

agile_geek10:12:52

That snippet needs to go in you project.clj map

roelofw10:12:26

oke, I want to use profiles.clj instead of project.clj

roelofw10:12:37

that does not make any difference

agile_geek10:12:41

Using profiles, yes. But typically you would inject values in production using environment variables

agile_geek10:12:41

i.e. in my example I might have a script that runs my application that also set port numbers like this export PORT=8000

roelofw10:12:20

oke, I would make the changes and hopefully I get the site working again

roelofw11:12:43

Thanks, the site is working again with a hidden key

agile_geek11:12:04

@roelofw a lot of libraries (like environ) have good doc's and readme's so always worth checking them first. Also when you get problems try and isolate a really simple case without anything else involved as sometimes this leads you to the solution without even asking and if you do have to ask you have a minimal test case to share with ppl here.

roelofw11:12:03

I had read the readme of environ but I could not find a example of how to store things in the enviroment

roelofw11:12:31

but next time I try to make a minimal test case

agile_geek11:12:05

Don't take this as a criticism, it's intended to be constructive 😄

roelofw11:12:33

sorry that my respons did not show it

agile_geek11:12:26

It's fine...just making sure I didn't scare you off

roelofw11:12:12

no, you did not

roelofw11:12:38

Im just looking how to improve my code

roelofw11:12:56

The first page of my first site is ready 🙂

agile_geek11:12:04

we're good then 😉

roelofw11:12:57

we are all good

roelofw11:12:44

@agile_geek maybe time for giving me feedback on my code ?

agile_geek11:12:46

One thing you could do is post a link to your github repo in the #code-reviews channel and let ppl know you are a beginner

agile_geek11:12:02

I'm afraid I'm busy atm or I would help

igrishaev12:12:08

Has anyone used core.match for objects declared with deftype? The code snippet shown in https://github.com/clojure/core.match/wiki/Deftype-and-defrecord-matching does not work.

roelofw13:12:18

Are there some packages that could need the help of a beginner in clojure so I can learn more and more about clojure ?

tomeklipski13:12:33

@roelofw A book on Clojure in general is usually a great start. There isn't much to learn though - Clojure is one of the simplest languages I think 🙂

zzamboni13:12:47

@roelofw Once you've read up on the basics, I would highly recommend through an exercise course - I am still going through http://4clojure.com, and found the exercises super useful to solidify the concepts from the books

zzamboni13:12:21

Books: I started with #braveandtrue and am now reading "Applied Clojure"

roelofw13:12:55

I did a lot of exercises . Im quit in the middle of the easy challenges to build my own website with clojure

roelofw13:12:16

but I can always go on with 4Clojure and maybe http://exercism.io

cemerick13:12:09

As some may have already seen on Twitter or other channels, our friend Anthony Grimes (@raynes in #clojure IRC, here, and elsewhere, @StRaynes on Twitter) has passed away. More info and a place to help is here: https://groups.google.com/forum/#!topic/clojure/VZB4-yVDq7k

tjtolton14:12:24

Has anyone ever tried using SonarQube with clojure code? Or any other source code analysis tools?

rfhayashi14:12:55

Is there a better way for going from [1 2 3] to [[1 2][2 3][3 nil]] than this: (defn group-adjacents [coll] (loop [item (first coll) remaining (rest coll) result []] (if item (recur (first remaining) (rest remaining) (conj result [item (first remaining)])) result)))

jcromartie14:12:01

(partition 2 1 nil [1 2 3])

jcromartie14:12:09

returns ((1 2) (2 3) (3))

jcromartie14:12:18

which is close enough, yes?

jcromartie14:12:21

sorry, specifically you want

jcromartie14:12:21

user=> (partition 2 1 (repeat nil) [1 2 3]) ((1 2) (2 3) (3 nil))

jcromartie14:12:28

the pad argument should be a collection

rfhayashi14:12:41

nice, gonna read the doc to understand how it works, thanks!

jcromartie14:12:40

@cemerick wow 😞 no way... @raynes was an inspiration for many

jcromartie14:12:16

I always think of the first Conj "scholarship" when I think of him

jcromartie14:12:20

as just a high schooler

tjtolton16:12:45

how does one include datomic in their project? What's the lein dependency I need to have? lol, I'm spoiled by having git repos with clearly spelled out dependency information

tjtolton16:12:53

i have it downloaded, etc

tjtolton16:12:54

found it! sorry

quoll16:12:09

if you create a new project with lein then it will have Clojure included automatically!

tjtolton16:12:15

you have to do a maven-install from the directory you downloaded it in

tjtolton16:12:12

@quoll Yep. Sorry, was interested in getting set up specifically with datomic, not clojure

shaun-mahood16:12:01

@tjtolton: Have you got an account on http://my.datomic.com ? If you log in to your account there it sets out instructions for both Maven and Leiningen

tjtolton16:12:16

that page, right?

quoll16:12:21

ooops! I wasn’t paying attention. My bad. Sorry 🙂

tjtolton16:12:38

yeah, the maven-install command is giving me issues. I don't know if its an OSX issue or what

borkdude16:12:24

I’m looking for a nicer way to partition a collection on even/odd indices:

(defn partition-by-index [coll]
  (->> coll
       (map vector (range))
       (group-by #(-> % first even?))
       vals
       (map #(map second %))))

shaun-mahood16:12:08

@tjtolton: Have you tried with lein?

tjtolton16:12:46

@shaun-mahood well, presumably it needs to be installed in my local maven repo before I can depend on it with lein, no?

shaun-mahood16:12:21

@tjtolton: Nope, lein should go grab it for you just like any other dep as far as I can remember.

tjtolton16:12:32

oh, well, damn

tjtolton16:12:18

so, just

[com.datomic/datomic-pro "0.9.5544"]
will work?

quoll16:12:22

getting the transactor is separate, but your project will just need the Datomic libraries for talking to a transactor, and that’s just a dependency in project.clj

dpsutton16:12:50

take-nth is lazy so if you return it in some other form than a vector you could preserve that

dpsutton16:12:05

i'm imagining the vector realizes the whole sequence which might be dangerous for your needs

borkdude16:12:16

E.g.:

(defn partition-by-index [coll]
  (reduce (fn [[even odd] e]
            (if (> (count even) (count odd))
              [even (conj odd e)]
              [(conj even e) odd]))
          [[] []]
          coll))

borkdude16:12:03

@dpsutton looking at yours now

shaun-mahood16:12:17

@tjtolton: Datomic pro requires your credentials to get it - it's all in your account page at http://my.datomic.com

tjtolton16:12:02

wow, thanks, I missed that section

tjtolton16:12:43

whooo boy this is more involved than I was expecting

tjtolton16:12:48

got to get lein gpg going

mgrbyte17:12:34

@tjtolton You don't actually need to get the lein gpg credentials thing going - should be able to to download datomic-pro archive from http://my.datomic.com, then run ./bin/maven-install from the directory you've extracted it.

tjtolton17:12:16

@mgrbyte thats what I tried initially. I dont know if it's an OSX thing or what, but the maven-install command fails

mgrbyte17:12:22

If that doesn't work, it's probably worth fixing anyway, since lein is essentially acting as front-end to maven anyways (as far as i understand things, relative n00b to clojure-land myself)

tjtolton17:12:40

it fails because i dont have mvn, which is apparently part of the maven-install script

tjtolton17:12:47

so, yeah, I think its an OSX thing.

mgrbyte17:12:48

@tjtolton I had a similar issue with maven after an ubuntu upgrade, turned out the CA certificates needed upgrading separately after doing a dist-upgrade - could be a similar thing.

mgrbyte17:12:02

@tjtolton get brew, do brew install maven

mgrbyte17:12:11

that's what I'd do anyways on osx

tjtolton17:12:24

brewing maven now...

dexter17:12:35

if you're on osx updates sometimes helpfully uninstall java so that might also be a contributing factor

tjtolton17:12:53

maven installed datomic.

tjtolton17:12:45

you did it guys! Thanks @mgrbyte ! You saved me from fighting with lein gpg

mgrbyte17:12:59

fwiw, this thread should of been on #datomic

tjtolton17:12:38

oh, is that a thing?

tjtolton17:12:58

holy crap, there are 358 channels on this team?

gfredericks17:12:27

instead of changing a channel we make new channels so that everything is always backwards compatible

quoll17:12:29

Someone was watching last Thursday’s keynote 🙂 that’s a hint for people to watch it, if they haven’t yet

gdeer8117:12:24

But first you have to watch Paula's talk so when he mention's how logic systems don't ever say what can't ever exist or what will never be true, you'll know what he means 😃

spacepluk17:12:08

hi, is there any way to stop clojure from referring some java classes like Byte?

gfredericks17:12:34

I've wondered that

seancorfield18:12:30

If there are folks who enjoy putting together video tutorials of Clojure stuff, one of the acquisition editors at Packt is looking for someone to author a video course on Clojure. If you think you might be interested (and willing to work with a publisher to produce a full video “master class” series), DM me and I’ll hook you up. I have no affiliation with Packt (and, to be honest, no love for them either) but they’ve approached me several times about writing books and just now about producing videos so I figured I could get them off my back by throwing them a new victim, er, volunteer!

shaun-mahood18:12:24

@seancorfield: I believe @ericnormand is also looking for additional video authors for http://purelyfunctional.tv

roelofw18:12:11

@seancorfield : the first page of my paintings site is now ready

seancorfield18:12:01

@shaun-mahood Cool. I suspect @ericnormand would be a lot more pleasant to work with than Packt 🙂

seancorfield18:12:11

@roelofw Congrats! What’s the URL?

roelofw18:12:45

I can only show your the code. For the layout I have to find a free hosting platform

ericnormand18:12:44

where'd you learn your sales techniques, @seancorfield ?

seancorfield18:12:21

😆 I’m no salesman!

gfredericks18:12:32

he is following the ABCs of sales: Always Be Cautioning

roelofw19:12:06

That I need a translator for

roelofw19:12:03

Anyone ever worked with openshift or heroku for very simple clojure site's

albaker19:12:42

yeah, the heroku clojure guide worked fine

cptully19:12:20

@roelofw I have setup two sites on Heroku. Both were written Java, but there should not be much difference in the setup for Clojure should not be much different. And as @albaker says the Heroku setup guides are quite helpful.

roelofw19:12:48

both thanks

roelofw19:12:08

then I wll try to make my little site workable on heroku

roelofw20:12:21

oops. error on heroku : No :main namespace specified in project.clj.

roelofw20:12:46

I think I schould do something like main: paintings.core

roelofw20:12:34

Wierd it is there ; ` :main paintings2.core

roelofw20:12:40

anyone who has a idea why heroku thinks why there is no :main namespace when there is a :main namespace

roelofw20:12:09

here is the relevant log from heroku :

2016-12-07T20:23:39.302333+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2016-12-07T20:23:52.566433+00:00 app[web.1]: No :main namespace specified in project.clj.
2016-12-07T20:23:52.583939+00:00 app[web.1]: Error encountered performing task 'trampoline' with profile(s): 'production'
2016-12-07T20:23:52.584172+00:00 app[web.1]: No :main namespace specified in project.clj.
2016-12-07T20:23:53.690609+00:00 heroku[web.1]: State changed from starting to crashed
2016-12-07T20:23:53.676416+00:00 heroku[web.1]: Process exited with status 1  

pseud20:12:51

A while back, a Paul deGrandis gave a talk titled "Unlocking data-driven systems". I found the talk a little too good to be true, but I'm nonetheless intrigued. Do anyone know of any concrete examples exemplifying these data-driven systems of which he speaks ? Random searching has revealed that data-driven is a heavily overloaded term, from something UX designers use in their process, to an old 90's OO design philosophy to something which (and this seems closest to the mark) is described in an AI book authored (at least in part) by Peter Norvig.

gdeer8120:12:51

@roelofw that looks like a pretty straightforward error message, it mentions the production profile but I don't see a :production keyword in your :profiles key in your project,clj file

roelofw20:12:35

you are right. I can only find this :

:profiles
  {:uberjar {:omit-source true
             :aot :all
             :uberjar-name "paintings2.jar"
             :source-paths ["env/prod/clj"]
             :resource-paths ["env/prod/resources"]}

   :dev           [:project/dev :profiles/dev]
   :test          [:project/dev :project/test :profiles/test]

   :project/dev  {:dependencies [[prone "1.1.4"]
                                 [ring/ring-mock "0.3.0"]
                                 [ring/ring-devel "1.5.0"]
                                 [pjstadig/humane-test-output "0.8.1"]]
                  :plugins      [[com.jakemccrary/lein-test-refresh "0.14.0"]]
                  
                  :source-paths ["env/dev/clj" "test/clj"]
                  :resource-paths ["env/dev/resources"]
                  :repl-options {:init-ns user}
                  :injections [(require 'pjstadig.humane-test-output)
                               (pjstadig.humane-test-output/activate!)]}
   :project/test {:resource-paths ["env/test/resources"]}
   :profiles/dev {}
   :profiles/test {}}) 

roelofw20:12:45

and this is made bu luminus

roelofw20:12:24

so I have to find out how the production keyword must look like

seancorfield21:12:51

You don’t need an explicit :production profile — that just tells Leiningen to turn a bunch of stuff off.

seancorfield21:12:41

Are you sure Heroku is picking up the correct project.clj file and that your :main paintings2.core is in the right place in that file?

gdeer8121:12:36

@roelofw what command are you using to push the app to heroku? are you using the toolbelt?

roelofw21:12:46

I use git push heroku master to push the app to heroku

roelofw21:12:58

and I do it from the root of the project

roelofw21:12:07

I use the toolbelt

roelofw21:12:33

Is there a way I can see the code that I have pushed

gdeer8121:12:23

look at the contents of target/uberjar/paintings2.jar

roelofw21:12:10

That one can I find locally ?

roelofw21:12:22

there is no uberjar there

gdeer8121:12:20

can you DM me the output after you executed git push heroku master?

roelofw21:12:22

moment, I have to check something

roelofw21:12:33

it looks like the wrong directory is pushed

gdeer8121:12:12

bowtie 🗃️ another case closed

roelofw21:12:42

oke, I did clone the right one but now I see a 500 error and nothing is found on the logs

gdeer8121:12:44

you get a 500 error when you try to access the app from the browser?

gdeer8121:12:51

and nothing shows up when you do heroku logs --tail ?

roelofw21:12:15

nope, I do not see any errors

roelofw21:12:56

Thanks for helping, Im going to bed

gdeer8122:12:10

bowtie Until next time, pesky deployment errors

lwhorton23:12:42

i wonder .. after working with records for a while, it would be nice if there was a way to (defrecord foo [a b c]) and then use a constructor map->foo {:a 1 :b 2 :c 3 :d 4} that would ignore any keys not declared in the defrecord

lwhorton23:12:00

since often the use case for records is polymorphism at some point “downstream”, it would be mighty convenient to not have to special-case parse various data into slightly different records

alexmiller23:12:27

I think it’s unlikely we would add such a thing to Clojure itself

lwhorton23:12:42

imagine a record bar that shares 5/6 keys with foo

alexmiller23:12:46

but it would not be hard to macro such a thing into existence

lwhorton23:12:11

oh i certainly dont think it belongs in clojure, but was interested if anyone else had a need or solution floating a round

alexmiller23:12:52

people have certainly written things that will error on keys not in the record

camdez23:12:06

Anyone done proper lexicographical ordering of Strings? I assume there’s a method somewhere in Java land I can use to strip diacriticals, downcase, etc. but my Google fu hasn’t succeeded yet.

alexmiller23:12:07

not sure I’ve seen the option to ignore/drop them though

lwhorton23:12:45

alright, thanks @alexmiller i’ll keep poking around

noisesmith23:12:33

hack:

(select-keys x (keys (map->Foo {})))
- keeps only the keys of x that are defined formally for a Foo

noisesmith23:12:49

there's probably a less hacky / more elegant version of that

lwhorton23:12:47

that’s pretty darn close to good enough for my purposes

alexmiller23:12:55

it’s reaching into the internals, but you can do (.getBasis Foo) to get the keys of the record

alexmiller23:12:33

actually, I’m not sure if that’s still exposed

lwhorton23:12:35

is .getBasis any different from keys?

noisesmith23:12:17

alexmiller : that fails with Foo and with an instance of Foo in my clojure 1.9 repl

alexmiller23:12:02

sorry (Foo/getBasis)

alexmiller23:12:10

you don’t need an instance that way

noisesmith23:12:44

oh, that still works, yes

noisesmith23:12:16

(ins)org.noisesmith.tuning=> (defrecord Foo [bar baz])
org.noisesmith.tuning.Foo
(ins)org.noisesmith.tuning=> (select-keys (map->Foo {:a 0 :b 1 :bar 2 :baz 3}) (map (comp keyword name) (Foo/getBasis)))
{:bar 2, :baz 3}