This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-19
Channels
- # beginners (240)
- # boot (9)
- # braveandtrue (2)
- # bristol-clojurians (2)
- # cider (2)
- # cljsrn (84)
- # clojars (1)
- # clojure (195)
- # clojure-belgium (9)
- # clojure-china (5)
- # clojure-denmark (4)
- # clojure-italy (7)
- # clojure-mke (1)
- # clojure-norway (1)
- # clojure-russia (16)
- # clojure-spec (74)
- # clojure-uk (15)
- # clojurescript (78)
- # clr (3)
- # code-reviews (4)
- # datascript (8)
- # datomic (71)
- # emacs (9)
- # hoplon (18)
- # jobs (3)
- # kekkonen (32)
- # klipse (19)
- # lambdaisland (2)
- # luminus (15)
- # off-topic (6)
- # om (35)
- # om-next (62)
- # onyx (17)
- # overtone (5)
- # pedestal (1)
- # perun (1)
- # planck (31)
- # protorepl (1)
- # re-frame (135)
- # reagent (34)
- # ring-swagger (6)
- # rum (54)
- # specter (3)
- # untangled (14)
- # yada (14)
hello guys, am using figwheel to start my ring handler with the :ring-handler option, however was wondering if there is a way to start something like a scheduler on application start up when using figwheel, something like :ring {:init xxx } for the ring plugin
http://clojure.org/about/spec#_don_t_further_add_to_overload_the_reified_namespaces_of_clojure do these things have to be explicitly kept in mind when using spec or does it fall naturally out of its API/nature?
@nikki: that particular section is justification for why spec is implemented the way it is -- not something that affects how you use it.
`(gen/elements (seq "ACGT")) seems part of this. But not sure how to make the composition to generate strings (as a generator)
@seancorfield: neat! and is the idea that by using spec it solves some of those problems 'for free'?
Hi I am trying to run a long running method And i want to track it via jmx the code i currently wrote looks like this
(defn- start-long-running-method []
(let [start-ts (ts/now)]
(jmx/register-mbean
(jmx/create-bean (ref {:time-elapsed (- (ts/now) start-ts)}))
"my.namespace:name=Foo")
(start-long-running-method)))
but when I try to do (jmx/read "my.namespace:name=Foo" :time-elapsed)
I keep getting 0
So how do i dynamically update the current time?oh, this works: (gen/sample (gen/fmap clojure.string/join (gen/vector (gen/elements (seq "ACGT")))))
wondering if an editor could use clojure.spec specs to generate local UIs for editing sexps -- like a color picker for the color field -- if you are using something like 'lisping' for editing clojure https://www.youtube.com/watch?v=nHh00VPT7L4
(i think clojurescript over react-native is probs best suited for the UI rendering bit)
Exists a library which helps to communicate over unix sockets?
@danielgrosse Hi 🙂 There’s manifold/aleph, which talk to netty. I don’t think they do UNIX sockets right now, but netty does.
@danielgrosse If you want low-level bindings, there’s always jnr-unixsocket
Trivia question: for an xs with 10 elements, when is (get xs 3)
not equivalent to (nth xs 3)
?
@pesterhazy xs = [] for example
[] doesn't have 10 elements
curiously (get (seq [:a :b :c :d]) 3)
returns nil
nihil, latin for nothing
?
I guess it would be fine if get
threw if applied to a non-associative coll
as it is it's a head scratcher
you change [:a :b] to (map identity [:a :b]) somewhere and ... suddenly nil
vectors and seqs aren’t the same kind of thing in my head, so I haven’t really had that problem as much
I've developed that mental distinction too
seq[able]s are generic "collections", that have ordering if you need it
intentional vectors are very specialized
and I never conj onto a seq so I don't have that problem either
I treat a vec like a seqable reasonably often but then it’s no longer ok to call get
on it
what does that mean?
you mean that's your typical use for a vector?
right
my idea so far was, nth
is not very useful because it throws on index out of bounds, so I should just use get
instead
guess that's not good advice unless I know I'm dealing with a vector
throwing is useful sometimes too
Anyone here familiar with Amazonica? I’m trying it, and evaling (#'amazonica.aws.ec2/describe-vpc-attribute :vpc-id "vpc-xyzzy" :attribute “EnableDnsHostnames”)
gets me com.amazonaws.services.ec2.model.AmazonEC2Exception: Value (EnableDnsHostnames) for parameter attribute is invalid. Unknown attribute. (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterValue; Request ID: iddqd)
. From the Javadoc and examples I was expecting that to work....
Is there any reason a component's (stop [this] ...)
function wouldn't be able to (get this :something-i-assoced-as-the-final-expr-of-start)
?
I thought that was kind of the whole point of component, but I must be Doing It Wrong™
@pandeiro Yes. Idempotency is a part of component. You should be able to call stop
multiple times.
idempotence is kind of ambiguous here
pandeiro: are you calling stop on the object you originally called start
on, or the return value from start
?
the latter
this is my least favorite thing about component
it's a weeeird ambiguous mix of immutability and statefulness
@gfredericks Do you have an alternative approach you use in some situations?
the only other idea that comes to mind is just traditional OOP objects
which I haven't tried
I've never run into a case where I'm interacting with the components this directly. Mostly I use the example copy/paste from component or the reloaded.repl one. Why are you doing this directly, out of interest?
So I did (def system (start-my-system))
, then (component/start system)
, and then silly me, (component/stop system)
the irony being that in trying to figure this out, I have restarted my REPL dozens of times... not exactly the reloaded workflow I was hoping for
https://github.com/weavejester/reloaded.repl I would highly recommend just using this.
Thanks, I will eventually check that out but I'd like to limit the moving parts first to better understand what I'm doing
It's the stock https://github.com/stuartsierra/component#reloading example, packaged up so it doesn't get lost when doing a c.t.n/refresh.
Based on your examples, I think the distinction worth noting is that it should be init-my-system
not start-my-system
@pandeiro So, :item
should be a key on the record, during the init
stage it would be nil
, during the start
stage it will be (state)
. If, during the stop
stage, you dissoc
:item
, I believe it stops being a Record, and turns back into a hashmap
It is not strictly necessary for Component stop
methods to be idempotent, but many people find it convenient to design them that way.
@pandeiro It is common to have to restart the REPL a few times when developing / debugging your component implementations. I still have to do this myself on a new system. Once it's set up, the workflow gets smoother.
Appreciate the encouragement @stuartsierra, thanks
https://github.com/stuartsierra/reloaded is a Leiningen template with an example of how I set up a new project using Component.
How long should it take a complete newbie to get a bare bones full stack clojure application live? I wanted to put together a small talk for my company about clojure and i assume they would respond best to a working application. Which i tried to headstart using luminus:
lein new luminus vending_machine +re-frame +datomic
My plan was to immediately deploy that to heroku and make sure i could redeploy every step along the way.
sadly i hit an unexpected error on the next step.
‘lien uberjar` leads to ...
Compiling "target/cljsbuild/public/js/app.js" failed.
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.CharMatcher.javaUpperCase()Lcom/google/common/base/CharMatcher;, compiling:(/private/var/folders/qx/mn5d4sjn7w5b4fxs2l15lzk80000gn/T/form-init612906228494054095.clj:1:124)
Which i assume means someone is trying to call a method that doesn’t exist. The only way i figure thats happening on a brand new app is because of dependency problem. That or i need to do something before building the uberjar. But assuming i dont, the next thing i can think to do was check the dependencies.
lein deps :tree
and i get about 50 lines of "Possibly confusing dependencies found:” with recommendations on how to do exclusions, none of which i’m sure will help. Any suggestions on maybe a better course of action in general or for tackling this specific problem? Maybe a different toolchain?I'm looking for a general Clojure oauth2 library. It looks like there's a billion different such projects on GitHub or Clojars, few of which are both actively maintained, pushed to Clojars, and support Oauth2. Is there a go-to library for Clojure projects for this?
@drewverlee yeah, hard to tell why the compilation of cljs fails... One of the solutions is to assemble your project from the scratch, only using Luminus as an inspiration. To prevent dep conflicts earl on, add :pedantic? :abort
to your project file.
@metametadata
Thanks!.
> One of the solutions is to assemble your project from the scratch, only using Luminus as an inspiration.
Do you mean build just a luminus application then add :pedantic? :abort
as a measure against dependency problems? then add re-frame
and datomic
as individual steps?
I was sort of hoping that lein new luminus vending_machine +re-frame +datomic
would just work 🙂
I feel your pain! But I meant creating a totally empty Clojure project with pedantic setting and start adding stuff iteratively 🙂 It will take more time and figuring stuff out but you'll really understand all the code.
Maybe you could also try using the luminus template without "+re-frame" and add that part manually or use another profile for frontend (e.g. "+reagent"). Because it looks like only the frontend compilation is broken.
and you may also look at the Duct framework template as a starting point: https://github.com/duct-framework/duct
I don't know where else to ask this, but after making a few clojure projects I'm starting to gravitate towards a specific way of organizing my project sub directories. Rather than create sub directories for various aspects of the project, like documentation, source, resources, testing and so forth, I find it more intuitive to organize the project in a pipeline like fashion. I have a directory named pipeline, and it contains subdirectories 0, 1, 2, and so forth. In the 0 directory I have a cljs directory, in the 1 I have html, css, and javscript directories, in the 2 I have clj files and so forth. Basically, I ask myself "What depends on what?", come up with a linear order, and then that is the way I structure my pipeline directory. What do you think the weaknesses or tradeoffs of this approach are?
@drewverlee do you absolutely need luminus?
chestnut with the reagant template always works for me, and then you can add datomic and re-frame on top
@bcbradley I think if you could come up with names for those directories it would dramatically improve discoverability. what you're talking about sounds a little like the concept of "layering" more than "pipelining"
@owen, No there aren’t really any requirements. I’m trying to learn and put together a demo.
@bcbradley it would be interesting to apply this to your clojure code.
To see if it encourages you to write more pure functions, and decomplect the state from logic
well that sounds a little lazy, this is what I really mean: If you have a function that is supposed to have impure behavior, if its current value given an input is supposed to actually depend on past values (in other words, it takes the "past" as a hidden argument)
then what I typically do is make a function that represents the entire application (when possible), that has that behavior
then I implement that function using nothing but pure functions, potentially acting on some local state
that allows me to keep the statefulness out of the real "meat" of the application, and keeps the complexity of the application to as low a level as it can be from the perspective an outsider
in other words, if i have to have statefulness (impurity) i make sure that only one function has statefulness. Namely the function that represents the application itself. Every other function (obviously the application is going to be built out of smaller functions) is totally stateless.
Every app can be interpreted as a function from argument space to solution space. Sometimes its hard to coerce it though.
@roelofw partition-all
😛
sure, that was a bit of a tongue in cheek comment 🙂
Can someone point me in the right direction to understand when test-fixtures are run? For example, after each deftest
or after testing
or after properties/for-all
?
I think it runs after each test-var
@johnnyillinois the documentation for use-fixtures
which is defined only by the deftest
Documentation doesn't include all possible use cases
it is either before and after each test, or before and after each namespace of tests
it's never just before or after, it's surrounding
I was looking at this: https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/test.clj#L707
Yeah, agreed on the surrounding
that has nothing to do with fixtures - that's for calling tests defined via metadata, which is a feature that is rarely if ever used
totally! the macro: deftest
as part of the execution phase calls test-var
(from my understanding)
it does?
sorry, the macro only defines a function which calls test-var
https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/test.clj#L621
oh, funny
I didn't realize it was hooked up that way, but there we are
that's funny - must be a trick so that reloads are handled properly
crazy world!
I knew that the :test
metadata was an optional way to define your tests, I didn't realize that deftest actually used that same mechanism (very counterintuitive)
@johnnyillinois - I think this code makes it clear what the fixtures do https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/test.clj#L730
the once-fixtures are all composed, and called with a function that calls the each fixtures surrounding each test
(and the each fixtures are composed as well)
@noisesmith Awesome! thanks
it's the responsibility of the fixtures to make sure they call the testing function passed in
and they can do their thing before or after or both as they wish
and ideally they only call it once
lol, yes ideally
though I guess I could imagine someone making an argument for conditionally not running the tests or conditionally running them multiple times for performance metrics or something - though I would be unlikely to agree
#makes-sense
Is anyone run into this issue with database truncation and fixtures? Currently, fixtures do not run around clojure.test.check.properties/for-all
so there can be duplicate entities generated without a surrounding database truncation. If you have a uniqueness constraint, this can cause a problem.
Anyone dealing with this? How are solving it?
Trivially, one can truncate the database inside the test execution (but that seems "dirty")
I'll put some example code
(deftest insertion-into-db-test
(properties/for-all [entity entity-generator]
(insert-into-db! entity) ; can violate uniqueness
(is (in-db? entity)))
Your fixture should run for that deftest
— just once around the whole test.
Agreed! I am wondering how people are doing database truncation under that implementation
Don’t do generative testing on things that involve mutation and external services?
Any other ideas?
I mean, as a general principle. That’s just not safe in general.
Or truncate the DB, those are really your two options
truncate inside the for-all, it's not dirty, that's actually the way you should do it if you have some sort of mutable state
but it'll be slow, so try something different if you can.
What are you really testing here? Business logic? Or mutating the DB?
Yeah... those are the baseline fixes. I am wondering if there is something better.
When I'm working with Datomic, I'll use a in-memory DB to do testing like this and just throw it away inside the for-all.
Not really because the for-all has to do some sort of backtracking to shrink the failing case.
so the body of the for-all gets executed many times.
You shouldn’t need to test that a JDBC insert!
works — you should consider what in your function you’re really trying to test.
The actual test is more like:
(deftest my-test
(insert-into-db! entity)
(is (expected-json? (app request)))
Agreed, boundaries!
I familiar with the argument for isolating unit testing from the database and other side effects
These are integration tests
and everyone else!
So imo, this is a great way to test, and the way I prefer to do it, is there a way you can isolate your DB inside this test?
Either use a in-memory db like sqlite or some option where creating and deleting a DB dozens of times in a single test isn't that painful
sure! we can have a database abstraction function (or set of functions)
The thing I love about this sort of testing, is that you have a single invocation of insert-into-db!, but there's nothing stopping you later on from doing for-all [op (gen-ops ...)] and then you can test for combinations of commands that result in invalid state
Basically instead of testing a single command, you can test a session of dozens of commands.
Yeah, that is a powerful feature