This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-03
Channels
- # bangalore-clj (1)
- # beginners (160)
- # boot (174)
- # cider (57)
- # cljs-dev (16)
- # cljsrn (5)
- # clojure (144)
- # clojure-argentina (1)
- # clojure-austin (6)
- # clojure-finland (2)
- # clojure-france (4)
- # clojure-russia (185)
- # clojure-serbia (4)
- # clojure-spec (61)
- # clojure-uk (126)
- # clojurescript (212)
- # community-development (7)
- # core-async (2)
- # cursive (17)
- # datomic (210)
- # emacs (10)
- # euroclojure (2)
- # gsoc (23)
- # hoplon (86)
- # jobs (8)
- # lein-figwheel (9)
- # luminus (19)
- # lumo (12)
- # off-topic (4)
- # om (14)
- # om-next (6)
- # pedestal (38)
- # perun (11)
- # planck (35)
- # portland-or (2)
- # ring (1)
- # ring-swagger (28)
- # specter (6)
- # untangled (6)
- # yada (2)
(let [prevnext 6
num-pages 466
page 466
lower (max 0 (- page prevnext))
upper (min num-pages (+ page prevnext))]
(range lower upper))
prev-next is a bad name tbh. It's the number of previous and next pages that you want to show
so if im at page 4 . then prev-next is 6 . num-pages is 466. page = 4 , lower (max 0 (- 4 6) lower (max 0 -2) Lower = 0
@rauh : it;s not complete working as expected. When page = 10 then lower = 0 , upper = 16 so I see a range of 0 till 16 where I expect to see a range of 6 - 14
actually there is a tiny bug, ti shoudl be upper (inc (min num-pages (+ page prevnext)))
(let [prevnext 6
num-pages 450
page 466
lower (max 0 (- page prevnext))
upper (min num-pages (+ page prevnext))]
(range lower upper))
and when I do :
(let [prevnext 10
num-pages 460
page 466
lower (max 0 (- page prevnext))
upper (inc (min num-pages (+ page prevnext)))]
(range lower upper))
and when I do :
(let [prevnext 10
num-pages 466
page 460
lower (max 0 (- page prevnext))
upper (inc (min num-pages (+ page prevnext)))]
(range lower upper))
I see as output :
(450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466)
Do you know how I can use this in selmer. Can I do something like
(for [x [(range lower upper)]
Can I do something like this :
(defn home-page [page]
(let [page-num (s/conform ::page page)
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(if (s/invalid? page-num) 1 page-num)
(layout/render
"home.html" {:paintings (-> (client/get url options)
(api/get-objectNumbers)
(api/fetch-paintings-and-images-front-page))},
{:current-page: page-num})))
Just as I say it, there is a syntax error in the code you pasted. Not sure if that is the reason for your error, but in general it can not work like that.
@sveri : I think you mean something like this :
(defn home-page [page]
(let [page-num (s/conform ::page page)
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10}}]
(if (s/invalid? page-num) 1 page-num)
(layout/render
"home.html" {{:paintings (-> (client/get url options)
(api/get-objectNumbers)
(api/fetch-paintings-and-images-front-page))},
{:current-page: pagenum}})))
@roelof syntax is the way you write your code. From my point of view you need more practice. And if I tell you the syntax error you wont learn as much as if you find it yourself, so go ahead and search for it. Every seasoned programmer had to go through this several times in his life
Usually this means looking at a few lines of code for several hours and banging your head at the wall when you see it.
now when I do
(:data test)
I see nill where I expected to see this part test = {:data {:painting "painting" :current-page 2}}
could someone help me out with clojure(script) and regex? i'm trying to un-camelcase a word but my output is the same as my input:
(defn uncamel [s]
(let [pattern (re-pattern "/([A-Z])/g")]
(clojure.string/replace s pattern "$ 1")))
(uncamel "unCamelCase")
=> unCamelCase
user=> (str/join " " (str/split "unCamelCase" #"(?=[A-Z][^A-Z])"))
(str/join " " (str/split "unCamelCase" #"(?=[A-Z][^A-Z])"))
"un Camel Case"
now I want to display all the name in Selmer. So I do :
{% for painting in (:painting(:data data)) %}
{{ painting.name}}
{% endfor %}
@roelof Your code is invalid.
@henriklundahl yep, but I cannot see where it is invalid
{:painting {:name "painting 1"},{:name "painting2"}}
is invalid.
is there a paste that I can use to see the real output @henriklundahl ?
You can paste this: {:data {:painting {:name "painting 1"},{:name "painting2"}}} into a repl
yep, here you can find the real output when I do {{ data }} in selmer : http://lpaste.net/591130986197024768
Now you can test it with the render function: https://github.com/yogthos/Selmer#templates It returns a string IIRC
You'll need to fix the template as well. You can't use (:painting(:data data))
in {% for painting in (:painting(:data data)) %}
.
Take a look at https://github.com/yogthos/Selmer#for
solved. I can do this :
{% for painting in data.paintings %}
{{painting.name}}
{% endfor %}
Is it possible to make changes to the dimensions of a image in clojure or must I use something like jquery for that
I have found this way : https://rijksmuseum.github.io/demos/
you need to display the images at a certain size or you need the source image at a certain size?
i'm guessing these aren't your images so modifying them seems not what you want to do
but as far as i can tell you need this functionality:
<img src="smiley.gif" alt="Smiley face" height="42" width="42">
> So at some way I have to make squares out of rectangles if you need an aspect ratio change you have a significantly different problem
How can I rewrite this : (fn[x] (+ x 20 )
into this #(+ % 20)
but that one gives error messages
the #(..) one is correct, the (fn ..) version is missing a closing parenthesis
user> (#(+ % 20) 5) => 25
user> ((fn[x] (+ x 20 )) 5) => 25
other than that, as you can see, they’re equivalent
I see this error message :
ClassCastException java.lang.String cannot be cast to java.lang.Number clojure.lang.Numbers.add (Numbers.java:128)
I see.
the-world
here is just a number right?
you want (dosync (alter the-world #(+ % 20 )))
a ref to a number
otherwise, why do you want to add 20 to it?
ClassCastException java.lang.String cannot be cast to java.lang.Number clojure.lang.Numbers.add (Numbers.java:128)
there’s a whole lot of things going wrong in that snippet @roelof
wierd, I thought here the world would be a integer :
"Don't forget to do your work in a transaction!"
(= 0 (do
(dosync
(ref-set the-world 0 ))
@the-world))
so it’s not “hello” but 0
if so, my snippet above should work: (dosync (alter the-world #(+ % 20 )))
an equivalent to that is (dosync (alter the-world + 20))
btw
@alexmiller that works
@roelof the ClassCastException you get was (probably) because the ref contained a string at the time you tried it.
both should work
not because of any difference between (fn .. ) #( …) and + 20 - those constructs are all exactly equivalent
that seems likely :)
like if you did (def the-world (ref "hello"))
before
i have a sneaky suspicion that the jvm didn't know how to convenrt a string to a number
correct - that will never happen automatically