This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-07
Channels
- # adventofcode (38)
- # aleph (1)
- # bangalore-clj (3)
- # beginners (126)
- # boot (165)
- # boulder-clojurians (5)
- # cider (42)
- # cljsrn (11)
- # clojure (203)
- # clojure-greece (6)
- # clojure-hk (1)
- # clojure-italy (11)
- # clojure-new-zealand (1)
- # clojure-nl (1)
- # clojure-russia (112)
- # clojure-spec (86)
- # clojure-uk (176)
- # clojurescript (38)
- # code-reviews (2)
- # core-async (2)
- # cryogen (2)
- # cursive (16)
- # datascript (2)
- # datomic (80)
- # events (2)
- # garden (28)
- # hoplon (115)
- # jobs (1)
- # jobs-discuss (7)
- # klipse (50)
- # lein-figwheel (15)
- # liberator (17)
- # luminus (6)
- # off-topic (8)
- # om (31)
- # onyx (26)
- # parinfer (4)
- # planck (35)
- # protorepl (26)
- # quil (2)
- # re-frame (50)
- # reagent (21)
- # ring (5)
- # rum (2)
- # schema (1)
- # untangled (29)
- # vim (10)
- # yada (40)
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))
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@mkaschenko yes, that is correct : (client/get "
But ->>
puts ( str "
as the last arg
I added {:key <mnasked>} {:env{}}
to profiles.clj and try to read it with (env :key)
but no value is returned
@roelofw what library are you using for reading your environment variables?
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.)
alternatively you can add environment specific defaults to you project.clj
in the :profiles
section
:profiles
{:dev
{:env {:port 3000,
:host "localhost"
:db-uri "jdbc:h2:./gallery?user=sa&password=;database_to_upper=false"
:galleries-path "galleries"}}}
...
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
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?
https://github.com/aphyr/tesser might interest you
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
@agile_geek . oke, and then I can do something like this :
{:env {:key <masked}
in the profiles.clj and read it with '(env :key)` ?See example above. In profiles it needs to be under a profile, in my example :dev
so in my example, using environ I could read the port number using this (env :port)
So, if I need that for :dev and for :production I need to do the same code two times ?
That snippet needs to go in you project.clj map
Using profiles, yes. But typically you would inject values in production using environment variables
i.e. in my example I might have a script that runs my application that also set port numbers like this export PORT=8000
@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.
I had read the readme of environ but I could not find a example of how to store things in the enviroment
Don't take this as a criticism, it's intended to be constructive 😄
It's fine...just making sure I didn't scare you off
we're good then 😉
@agile_geek maybe time for giving me feedback on my code ?
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
I'm afraid I'm busy atm or I would help
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.
Are there some packages that could need the help of a beginner in clojure so I can learn more and more about clojure ?
@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 🙂
@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
I did a lot of exercises . Im quit in the middle of the easy challenges to build my own website with clojure
but I can always go on with 4Clojure and maybe http://exercism.io
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
Has anyone ever tried using SonarQube with clojure code? Or any other source code analysis tools?
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)))
partition!
(partition 2 1 nil [1 2 3])
returns ((1 2) (2 3) (3))
which is close enough, yes?
sorry, specifically you want
user=> (partition 2 1 (repeat nil) [1 2 3]) ((1 2) (2 3) (3 nil))
the pad argument should be a collection
@cemerick wow 😞 no way... @raynes was an inspiration for many
I always think of the first Conj "scholarship" when I think of him
as just a high schooler
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
if you create a new project with lein then it will have Clojure included automatically!
@quoll Yep. Sorry, was interested in getting set up specifically with datomic, not clojure
@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
yeah, the maven-install command is giving me issues. I don't know if its an OSX issue or what
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 %))))
@tjtolton: Have you tried with lein?
@shaun-mahood well, presumably it needs to be installed in my local maven repo before I can depend on it with lein, no?
@tjtolton: Nope, lein should go grab it for you just like any other dep as far as I can remember.
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
take-nth
is lazy so if you return it in some other form than a vector you could preserve that
i'm imagining the vector realizes the whole sequence which might be dangerous for your needs
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))
@tjtolton: Datomic pro requires your credentials to get it - it's all in your account page at http://my.datomic.com
@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.
@mgrbyte thats what I tried initially. I dont know if it's an OSX thing or what, but the maven-install command fails
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)
it fails because i dont have mvn, which is apparently part of the maven-install script
@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.
if you're on osx updates sometimes helpfully uninstall java so that might also be a contributing factor
instead of changing a channel we make new channels so that everything is always backwards compatible
Someone was watching last Thursday’s keynote 🙂 that’s a hint for people to watch it, if they haven’t yet
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 😃
I've wondered that
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!
@seancorfield: I believe @ericnormand is also looking for additional video authors for http://purelyfunctional.tv
@seancorfield : the first page of my paintings site is now ready
@shaun-mahood Cool. I suspect @ericnormand would be a lot more pleasant to work with than Packt 🙂
@roelofw Congrats! What’s the URL?
@seancorfield and the code can be found here : https://github.com/rwobben/paintings
where'd you learn your sales techniques, @seancorfield ?
😆 I’m no salesman!
he is following the ABCs of sales: Always Be Cautioning
@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.
anyone who has a idea why heroku thinks why there is no :main namespace when there is a :main namespace
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
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.
@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
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 {}})
You don’t need an explicit :production
profile — that just tells Leiningen to turn a bunch of stuff off.
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?
@roelofw what command are you using to push the app to heroku? are you using the toolbelt?
oke, I did clone the right one but now I see a 500 error and nothing is found on the logs
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
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
I think it’s unlikely we would add such a thing to Clojure itself
but it would not be hard to macro such a thing into existence
oh i certainly dont think it belongs in clojure, but was interested if anyone else had a need or solution floating a round
people have certainly written things that will error on keys not in the record
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.
not sure I’ve seen the option to ignore/drop them though
alright, thanks @alexmiller i’ll keep poking around
hack:
(select-keys x (keys (map->Foo {})))
- keeps only the keys of x that are defined formally for a Foothere's probably a less hacky / more elegant version of that
it’s reaching into the internals, but you can do (.getBasis Foo) to get the keys of the record
actually, I’m not sure if that’s still exposed
alexmiller : that fails with Foo and with an instance of Foo in my clojure 1.9 repl
sorry (Foo/getBasis)
you don’t need an instance that way
oh, that still works, yes
(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}