This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-22
Channels
- # adventofcode (1)
- # beginners (172)
- # boot (47)
- # cider (7)
- # cljs-dev (30)
- # cljsrn (43)
- # clojure (180)
- # clojure-dusseldorf (1)
- # clojure-greece (1)
- # clojure-italy (3)
- # clojure-russia (41)
- # clojure-spec (67)
- # clojure-uk (101)
- # clojurescript (128)
- # core-async (4)
- # cursive (13)
- # datomic (29)
- # devcards (5)
- # emacs (19)
- # events (1)
- # hoplon (38)
- # lein-figwheel (1)
- # luminus (8)
- # midje (1)
- # off-topic (47)
- # om (10)
- # onyx (23)
- # protorepl (1)
- # re-frame (11)
- # reagent (7)
- # ring (3)
- # ring-swagger (9)
- # rum (6)
- # sql (5)
- # untangled (4)
Hello.guys. Anyone know a page break library for web?
yes,clojure pagination lib
I have a question, I need print n time a string. for example. if i get the number 3, the string "example" should be print 3 times.
(fn[n]
(println (repeat n (str "Example\n"))))
the issue with my solution is that print (Example Example)
but I need Example Example
`(Example Example Example ) nil`
I dont need the list
only need the string
:thinking_face:
yes, it works.
thanks a lot.
ok, let me see..
rather than constructing what we want to print, we can take the traditional route and do what we want n number of times
so rather than making the string of three examples with line breaks, we could just "loop" and print example however many times we want
but probably always good to write things twice in two different styles while you are learning
yes, thanks. I get it.
Thanks for share with me the dotimes
function.
yes !!!!!
This is the first time I have tried out playing with API's and I am trying to get some stuff from Meetup. I'm just stumped on the time format.
"id": "ngmmrlywjbdc",
"name": "Social Meetup",
"status": "upcoming",
"time": 1498118400000,
"updated": 1457950138000,
"utc_offset": 36000000,
This is a snippet taken from Meetup. What am I supposed to do with that "time":
@grounded_sage If you want to convert it to a normal time object. you can look at clj-time
I managed to find some information on it. Google didn't surface it very well with my queries but I got there in the end.
I'm looking to grab it on the front end so I guess I will have to find a cljs-time equivalent.
@grounded_sage this is a timestamp, see https://en.wikipedia.org/wiki/Unix_time. And there is cljs-time: https://github.com/andrewmcveigh/cljs-time which is similar to clj-time
Also, please be aware that the map contains a "utc_offsett" which you would have to apply too, to get the correct time. Although it might be a bit difficult depending on the timezone the user consuming the API, sits.
Thank you. I think it's easier for now if I just manually update.
Hitting a lot of issues with Rum that are more critical
my homepage looks like this. The first page can be found with just / . Next pages are found with /pages=x . Must I make two seperate routes or can one route handle both cases
im trying to save an array of images to my postgres db.
im trying to save an array of images to my postgres db.
(doseq [file files]
(upload/save-image! user file))
but only the first image is stored before i get batch update exception. Any ideas on how to make sure all images gets stored?@joakimmohn Not sure if I understand that correctly, but if you do get an exception, you should get rid of that first
in honeysql what is this operator ‘-> ‘ https://github.com/jkk/honeysql
-> (select :a :b :c)
(from :foo)
(where [:= :f.a "baz"]))
@sveri `(POST "/file" [] :multipart-params [files :- [TempFileUpload]] (doseq [file files] (db/save-image! "kappachino" file)) (ok))` This is how the handler looks like. I think the problem is that postgres isn't finished working before the next image is attempted to be stored.
If the images are small (< 50 kb it works fine)
@kevinbheda I'm pretty sure it's just a thread first macro http://clojuredocs.org/clojure.core/-%3E
@joakimmohn i am Sure that PostgreSQL Cab handle multiple parallel requests
i wrapped the operation in a try catch block and now i'm not able to recreate the problem, so i guess thats called a solution? should all db operations be wrapped in try catch blocks?
how do I compose futures together? Like if I want to map a function over a future is there a standard library function for that?
Ideally it would wait till the future is realized, then apply the function to that value, returning another future
@joakimmohn If you wrap it in a try catch, the exception wont go away. You will just have to handle it explicitly then. What does your code look like now?
(POST "/file" []
:multipart-params [files :- [TempFileUpload]]
(doseq [file files]
(try
(upload/save-image! "userid" file)
(catch Exception e (.getNextException e))))
(ok))
in emacs clojure what is the short cut for copying s-expression ?
@joakimmohn Like this you catch the exception and thats about it. That is not the way to go. You should log at least and do something, depending on the exception. Instead of (.getNextException e) you could call (.printStackTrace e) to get an idea what it is about and post it here.
@sveri '(catch Exception e (.printStackTrace e))' I would post it here, but it seems like all the images are being stored without any issues now. I haven't used try/catch blocks a lot tbh
IM finisched reading compojure routes in detail. so if I make a routes like this
(GET "//?page=:page" [page] (home-page))
@roelofw you don't route on query params. In other words your route only has the URL in it
Also another gotcha will be that page will be a string when it comes from params so be aware of that.
I was following this example :
(GET "/user/:id" [id]
(str "<h1>Hello user " id "</h1>"))
Basically it goes like: 1. Make an assumption: If I change this, I expect that. 2. Test your assumption
or must I follow this example I found at stack overflow :
(GET "/:id/descendants" [id]
:return [d/CategoryTreeElement]
:path-params [id :- Long]
:query-params [context-type :- d/ContextType
levels :- Integer
{tenant :- d/Tenant :DEF_TENANT}
{show-future :- Boolean false}
{show-expired :- Boolean false}
{show-suppressed :- Boolean false}
:summary "Fetch category descendants"
(ok ...))
@roelofw that is an example of destructuring a parameter from the URI
you want an example of getting a query param
oke, I think you mean this :
(GET "/:foo" [foo id] ; You can always destructure and use query parameter in the same way
(str "Foo = " foo " / Id = " id))
; curl get /bar?id=33 would be "Foo = bar / Id = 33"
kind of but you don't need :foo
in this example
that would pattern match this URL "/thisisfoo?id=1"
(defn defaulted ([x] (defaulted x default)) ([x y] ...))
or that, yeah
but in this case if you have one route that expects a page
param you will never have zero args. You always have one....just it might be nil
(GET "/" [page] (hame-page page))
roelof a nice pattern for this is (defn find-page [p] (get {nil "/home" "/" "/home"} p p))
or map it to "1" or whatever
@agile_geek am I still on the right track ?
How do you work with unsigned longs in clojure?
and how would you convert one into a byte array
@roelofw yes although that if-let
doesn't look right.
Here's a tip - if you want to return the value of a var if it's not nil and a default if it is, instead of if:
(if page page "1")
you can use or
:
(or page "1")
oh BTW (if page page "1")
is the same as (if (not (nil? page)) page "1")
as nil
is falsey
@agile_geek so I can do (GET "/" [page] (home-page page))
and then this :
(defn home-page [page]
(let [
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page }}]
(or page "1")
(layout/render
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)})))
no that (or page "1")
needs to set a variable in the let
that you then reference in the options
as the value of :p
oke, that would then be :
defn home-page [page]
(let [ page (or "page" 1 )
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page }}]
(layout/render
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)})))
Yes although I would avoid shadowing page
just to avoid confusion:
(defn home-page [page]
(let [ page-num (or page "1")
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num }}]
(layout/render
"home.html" {:paintings (-> (client/get url options)
api/read-numbers
api/fetch-paintings-and-images-front-page)})))
and make sure your code is better formatted. Slack is not an IDE or an editor so hard to keep formatting consistent!
BTW can you see why (or page "1")
will work? If not have a try of similar expressions in a repl
oops, something is not right. when I do localhost:3000 I see this error message :
Wrong number of args (0) passed to: home/home-page
roelof, just a heads up, you don't need to post every thing you are going to investigate
try to work on stuff on your own and come to us when you need help, but not just for every error that pops up
check your routes
@roelofw I agree with @dpsutton. The way to learn is to try and investigate your problems, isolate as much of the problem as you can and create simple experiments to work out what's wrong. If you need to add println
or debug. Distil the problem to a simple use case if possible and then you can easily communicate it to us without us having to understand your entire application. Having said all that, we don't mind helping but we want you to help yourself too
remember to use the repl as much as possible and read documentation and examples of functions
I want to +100 ☝️
Cool I would leave on a high note and carry on tomorrow
let your brain sleep on what you've learned
last question before I goto sleep : the right url for a page is now localhost:3000/?page=n
where n is an integer in the range 1 - 470
I think this can be a solution : https://github.com/nberger/ring-logger
every time I see someone leave the beginners channel I'm like "nice, another graduate..." 🙌:skin-tone-2: 🎓 🙌:skin-tone-2:
I found this for logging
;; print request info to *out*:
(client/get "" {:debug true})
so I did
(defn home-page [page]
(let [page-num (or "page" 1)
url ""
options {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True" :p page-num :ps 10} }]
(layout/render
"home.html" {:paintings (-> (client/get url options {:debug true})
api/read-numbers
api/fetch-paintings-and-images-front-page)})))
#object[java.io.PrintWriter 0x164cd27 "[email protected]"]
oke, when I try (print (client/get url options {:debug true } ))
I see only the request back
@roelof Think carefully about the number of arguments you are passing to client/get
there. You have options
— isn’t :debug
an option as well?
i’ve updated my cider nrepl version from 0.8.1 to 0.9 in my .lein/profiles.clj file. does this mean the next time i do lein deps
, it’ll update automatically?