This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-08
Channels
- # bangalore-clj (4)
- # beginners (88)
- # boot (12)
- # cljs-dev (10)
- # cljsjs (1)
- # clojure (284)
- # clojure-denmark (2)
- # clojure-dev (35)
- # clojure-italy (8)
- # clojure-russia (36)
- # clojure-spec (38)
- # clojure-uk (51)
- # clojurescript (145)
- # cursive (6)
- # data-science (1)
- # datomic (8)
- # duct (43)
- # emacs (9)
- # figwheel (2)
- # fulcro (29)
- # graphql (1)
- # immutant (3)
- # instaparse (1)
- # jobs (1)
- # jobs-discuss (1)
- # lumo (16)
- # off-topic (50)
- # onyx (90)
- # re-frame (6)
- # reagent (20)
- # remote-jobs (3)
- # ring-swagger (18)
- # schema (8)
- # shadow-cljs (141)
- # slack-help (3)
- # spacemacs (36)
- # unrepl (7)
- # vim (1)
- # yada (2)
hey i’m trying my hand at clojure. I was wondering if there was a cleaner way to capitalize a list of names? https://gist.github.com/tjmaynes/92296bb41f026b305667f3868b65e249 I’m trying to avoid stateful behavior by passing the result of one transformation to the next.
what bothers me also is that i’m partitioning the flattened list to a list of lists (of size 2). If a person includes their middle name (or potentially many other names) (for instance ((“tj” “maynes”), (“big” “e” “smalls”)), then the partition will crop the “Smalls” in “Big E Smalls” into another list.
looks pretty good
the (reduce into [])
isn’t necessary
there’s a couple of ways around the partitioning issue
this may be a super noob question but: if the (reduce into [])
is not necessary, then how can I capitalize over this data (["Bruce" "wayne"] ["peter" "Parker"] ["your" "dad"])
(list of vectors).
oh sorry, I had made another change that made it unnecessary
I had changed the step before to use mapcat
which combines the two steps
one way to get around the partitioning issue is to skip the reduce/mapcat step
(defn capitalize-names
[names]
(->> names
(map #(->> (string/split % #"\s+" )
(map string/capitalize)))))
but that’s not necessarily a good way to write it
really digging this abstraction:
(map #(->> (string/split % #"\s+" )
(map string/capitalize)))
(defn capitalize-name
[name]
(->> (string/split name #"\s+" )
(map string/capitalize)))
(->> (map :real identities)
(map capitalize-name))
I think that’s a little easier to fiture out what’s going on
thank you @smith.adriane!
I think it’s easier to think about a function that works on one item and then use map to transform a sequence of items
then to have a function that wants to receive a list of items that it will transform on a per item basis
and you can easily turn the single-item function into a collection function later if you so choose by doing (partial map f)
(or (fn [coll] (map f coll))
)
it’s really weird (at first)
and then at some point, you can’t remember why you would do it any other way
any spacemacs users here? I need help debugging a large process (breakpoint and inspecting). I know spacemacs comes with the Sayid debugger but I dont know how to use it. Any other debugger/editor/tools that you think is better is welcome
@U7V9HE682 afaik, spacemacs doesn't come with Sayid out of the box - you have to add it. Most of the time, cider-debugger is sufficient. Check the first episode of my new screencast: https://curiousprogrammer.net/2017/11/05/introducing-clojure-tip-of-the-day-screencast/
nevertheless, I used sayid before and while it's a great tool I've found it a bit overwhelming. I've found that I don't really need it for most of my debugging/tracing use cases.
hello all, is there any way to replacing many string in a string? Like "Hello dot My name is Jonh dobuledot" -> "Hello . My name is Jonh :" ?
@fabrao I would just thread the string through a series of (str/replace ...)
calls...
(-> "Hello dot My name is Jonh doubledot" (str/replace "doubledot" ":") (str/replace "dot" "."))
user=> "Hello . My name is Jonh :"
re-pattern
Or just use the #".."
literal syntax if you have a literal.
I just used strings with str/replace
because that's all your example seemed to need.
Does anybody know of a tool like reveal.js (https://github.com/hakimel/reveal.js) in CLJS? It's a PowerPoint substitute in HTML/CSS/JS.
one of the main things about cljs is you can just use js things pretty easily
in Selmer, is there a function that can return all keys found in a template? "{{a}}, {{b}}, {{c}}" ====> [:a :b :c]
(I've looked through the source, nothing jumps out as being able to do this, and rolling my own parser defeats the purpose of using selmer)
hack idea: reify the method that looks up a key on a map to return “foo” and store the key looked up in an atom, then check the contents of the atom after passing it to a render
probably a terrible idea but might be fun
haha, shoot. not a bad idea, but... a bit hacky for this
@noisesmith When people say "easy" when talking about programming it normally means I'll have a really hard time doing that.
@anantpaatra one of the main design goals with clojurescript is that you should be able to use javascript directly
@anantpaatra for example, this is how you use the javascript Date
class:
cljs.user=> (js/Date.)
#inst "2017-11-08T19:05:28.040-00:00"
I guess my main problem right now is setting up the boilerplate code, understanding how things are tangled together. In HTML/JS it feels so clear, but in CLJS everything feels cryptic.
This is why I thought a ready-made project would help me with some README instructions or whatnot.
@anantpaatra the interop syntax is something you can learn in half an hour, and master in a week of regular usage easily
it’s not complicated, it’s just different from what you are used to
I've been in and out of CLJ/CLJS for an year and still don't. Maybe I'm just really, really dumb. Or I do something really wrong. Probably both.
the problem with immediately seeking wrappers instead of using the javascript directly is that you end up using broken libraries (most wrapper libs are incomplete at least, if not broken in some corner case), and in the long run it wastes your time
if you put in the effort to do interop, it’s easier than managing the hacky wrapper libs
That is good advice, I'll try doing it with plain interop.
Anyone know a good resource for clojurescript, or even javascript to deal with dates between the UI and the database? Just noticed my dates come across with transit in UNIX time, but when they create a date in the browser that time is for the timezone, so ends up being a different day sometimes (in this case i only care about dates)
Thanks @aconanlai I'm using moment. But in this case I don't need timezones, so that's the problem.
If my browser is in a different timezone than the server, i have issues when I read it back out of the db and put on the page.
through a rest api over transit. I can think of ways to fix it, but thought there would be a standard somewhere, or convention.
your browser should be storing time in a timezone-agnostic format like ISO or unix time
yes, unix time in the db. which probably converts to java dates before transit. so 1510185600000 (midnight in UTC) turns into Wed Nov 08 2017 19:00:00 GMT-0500 (Eastern Standard Time) http://currentmillis.com/?1510185600000
that's what i need. so i guess i can just take the date and figure out the current timezone and add the offset to get back to UTC. That's one idea.
https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript
moment-timezone will take care of this for you, the vanilla JS ways are a bit janky
ok, if that is your suggestion, i'll give it a go. just was surprised I hit this with such a simple use case. My first SPA, server side rendering is easy 🙂
I know. that's my prob. I can change it server side before it hits them to be a js string i guess that is utc, but seemed strange way to do it
you want to be passing a timezone agnostic date format over to the client and formatting it from there