This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-07-14
Channels
Any Clojure shops in Reykjavik seeking U.S. resident aliens?
(Mostly HHOS)
I’m constructing a hashmap and I want to add :port port to it, but only if port is non-nil and not -1. What’s the most idiomatic way of doing that?
@pupeno: I guess you’d use merge
: (merge {:new ‘hashmap} (when (and port (not= -1 port)) {:port port})
@andrewmcveigh: neat. thanks.
Is there a builtin way in Clojure of writing this without calling getPort twice? (if (not= -1 (.getPort parsed-uri)) (.getPort parsed-uri))... something like (return-if #(not= -1 %) (.getPort parsed-uri)) which would be trivial to implement.
@pupeno: sounds like if-let
should help
@pupeno: I use this:
(defmacro assoc-if
; Needs to be a macro so kvs is not evaluated if not required
[map test & kvs]
`(if ~test
(assoc ~map ~@kvs)
~map))
@cfleming: macros are beautiful. Unfortunately, I was trying to do a minimal patch for Korma and I wouldn’t lightly add macros to other people’s source code. I wish Clojure had assoc-if.
I mostly use it in threading forms though:
(-> params
(assoc-if (and port (pos? port)) :port port))
That’s useful since I often have multiple things I want to add conditionally to the same map.
That makes sense. I’m looking forward to the day threading comes natural to me.
@cfleming: that’s about the same as (cond-> params (and port (pos? port)) (assoc :port port))
which is more flexible
no, it return the map
I always forget about cond->
There should a service that emails you one Clojure function a day with the documentation.
Clojure gazette is a bit like that
@pupeno: I had a Twitter account like that. https://twitter.com/learnclojure
at some point I couldn't maintain it anymore, because I was too busy becoming a teacher...
when I ran the Columbus Clojure User Group we had a "Function of the Month" where someone would pick a random clojure function and present to everyone
we stole that from the Columbus Ruby Brigade which did a "Method of the Month"
I'm using @yogthos' clj-pdf
library to build a form, using templates which are applied to maps of values. To get database values in there, I want all the var's holding those maps of values to be evaluated at runtime. Using reset! on an atom and then deref'ing it won't work, as the dereferenced value has already been evaluated. I just tried wrapping all the vars in delay
, and then in my function calling (map force content-vector)
, which also didn't work. This all feels wrong, like I'm overlooking something obvious.
Like, I could wrap the entire thing in a function...but that's not very aesthetically pleasing
if I have a namespace
how do I dynamically get one of the symbols defined in it/
from a string I mean?
andrea.crotti: a: don't do that most of the time. b: find-var takes a symbol (iirc), you can make a symbol from a string
@andrea.crotti: resolve
basically what I'm thinking is that :code
can be modified to use the :buf
accumulator, and then at the close of a code block you run the :code-formatter
or whatever that's the identity by default but which I can use as a hook into pygments or whatever.
might want to introduce a separate one though, otherwise if you'll get funky behavior for stuff nested in lists
yeah but it kinda comes with the territory. I was looking at the markdown spec wondering if it would be nicer to just chuck your code and the answer is no 😛
but the general approach of leveraging the code block to do some post processing I like
I think it would be nice to split out a transformer that aggregates lines given the delimiter
and then it could be used internally by codeblock but also would allow custom transformers to hook into it
@bostonaholic: should have done "function of the fortnight" - 2 a month, alliteration bonus!
I'm all about those bonuses.
any leads on a good intro level guide to using kafka from clojure? the clj-kafka readme is not working for me, I follow the examples in my repl and get all sorts of errors
noisesmith: post your stacktrace (to refheap maybe) and I'll try to give you some nuggets. We use Kafka at LivingSocial, but not through clj-kafka
ghadi: cool, thanks
@noisesmith: hey, what issues are you having with clj-kafka?
@ragge: one message "WARN org.apache.zookeeper.ClientCnxn - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect"
@noisesmith: and what are you doing when you get that exception?
@noisesmith: or warning rather
@ragge: but I don't even know the difference between normal chatter and actual problems at this point
trying to consume a message
@noisesmith: haha, yeah, both zk and kafka are very chatty
@noisesmith: have you specified a port in zookeeper.connect?
hey is anyone here using circleci?
yeah, and the walkthrough is such that I wasn't totally sure which port numbers to use literally, and which I had to adapt to my install, and where to find the numbers
@ragge: I am starting to suspect I can't just start kafka and start interacting with it in the repl, and there is a big understanding of the architecture and API I need before I can start experimenting with it...
hundreds of lines of info and warnings and I don't really know which parts I can ignore at this point
@noisesmith: can you do stuff using kafka-console-consumer.sh and kafka-console-producer?
haven't tried it yet, I'll check those out
@noisesmith: yeah, might be worth making sure you can do something basic with those... publish in one shell, consume in another
@noisesmith: like @ghadi said, operating kafka is...
indeed
If you're running kafka in dev mode, there are sometimes /tmp/zookeeper files that are ok to blow away
and actually, given the error you're seeing, it might be worth starting with zookeeper, there's zkCli.sh for that
ragge: interesting
ragge: so establish that zookeeper is working on my machine as expected, from the shell, then establish that kafka works as expected from the shell, and finally kafka?
yeah, I guess it depends on what your setup is... just local dev stuff or some more realistic setup
local dev right now
but I'll need to do a proper install eventually too
I've been nominated to become "the kafka guy" for our product
which as of yet has no usage of kafka
well, good luck, let me know if you have any issues with clj-kafka, I'm partially guilty for that library so I'd be happy to help
cool, thanks a lot
I'll likely come back with more specific questions
@pleasetrythisathome: yep, what's up?
having trouble getting dependencies to cache correctly
I have ~/.m2/repository in the dependency cache part of circle.yml
and when sshing into the machine pre build, everything is getting copied correctly
which is strange...
we're not using any dependency caching, so I can't help there 😕 FWIW, it works fine without it… sounds like you're probably doing more with it than we are though.
yea it definitely works fine
just takes about 20min to build
which isn’t exactly ideal X_X
yea i have other projects like that. not exactly sure what deps take so long for this one, but there are a lot of them i guess
what about using a caching repo that is closer to your network?
what do you mean by caching repo?
you can define a maven repo that grabs things from the upstream source and caches them / provides them
but if you are using circleci's servers making one that is "close" may be easier said than done?
yea that sounds great in principle
but good point about “close"
not idea there
well, if eg. circleci is on aws, having a caching mvn repo on the same location would give you good throughput
circleci is supposed to support caching, and it’s working in that the .m2 directory gets populated for new builds, but for some reason the builds don’t see it
oh, circleci is supposed to support this already, I didn't realize
is there something that maven does locally that determines whether deps are available locally or need to be fetched beyond just storing them in .m2?
wondering if there’s some env var or something that’s missing
deps are considered immutable unless SNAPSHOT
and it should prefer the cache over fetching from remote, as long as this is all on the same machine and same user as before
i think same user may be the problem. i believe the circle builds are all on different machines
right, which is where having a maven repo "repeater" that is on the same local network (or shorter network distance) could make a difference
and the cache is stored somewhere and then fetched by the new machine
yea that’s interesting
it isn't just pulled from the repo?
not sure how they manage it. the project is pulled from a repo
but the env caching is a different process
here's the official maven docs on maintaining your own server that will mirror the official ones https://maven.apache.org/repository-management.html
well, we are talking about two kinds of repo here - maven repo vs. git repo
ah yea that’s confusing. but thanks i’ll look into the maven repo stuff
originally coming to clojure without much java experience has left some knowledge gaps on some of the basic java management stuff
@noisesmith: @pleasetrythisathome Circle caches your m2 repo between builds, and stores the cache in S3
@pleasetrythisathome: is your Circle build getting to the test
step, or is it exiting before then? i.e. do you see a “saving cache” step?
arohner: thanks for the info
@arohner: yea it’s getting to test
i have cache_directories: - ~/.m2/repository
sounds like that should be removed?
@pleasetrythisathome: you probably shouldn’t need it, unless it’s failing to infer this is a Clojure project
which is necessary when your project.clj can’t be read as EDN (there should be a warning on the page if so)
i’m using boot, so there isn’t a project.clj
which could be the entire problem
it definitely reads from there
Boot uses .m2 just like Leiningen
martin any experience with circleci and boot?
I know a few people that run things with boot on CircleCI, don’t remember them having such issues
caveat here, it works fine, deps just aren’t cached so the every dependency has to be downloaded for each build
@pleasetrythisathome: AFAIK, Circle doesn’t have inference for boot, so you’ll have to manually setup caching
I think when we set things up for CircleCI back then we had a Docker container as base that already had a populated ~/.m2
don’t exactly remember though
@arohner: does the dependency caching work by finding a file like project.clj and downloading listed dependencies?
@martinklepsch: the caching process is agnostic. It adds directories to be cached based on files present in the source repo. The logic looks like “if there’s a project.clj, or pom.xml, add ~/.m2/ to the cache directories. If there’s a Gemfile, add whatever it is that ruby caches"
ahhh, got it!
that makes sense
You’d think one could write programs that can check which of those directories have been populated 🙈
@arohner: you work at CircleCI, do you?
Remember, now. Stumbled upon your blog the other day for that CLJS module stuff
@arohner: thanks i’ll keep playing with it