Fork me on GitHub
#clojure
<
2016-12-19
>
Pishty00:12:02

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

Pishty00:12:26

or if there is a cleaner way to start a scheduler on application start up

nikki03:12:30

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?

nikki03:12:36

in your experience

seancorfield07:12:25

@nikki: that particular section is justification for why spec is implemented the way it is -- not something that affects how you use it.

dbsgtk07:12:30

I'm trying to understand how to write a spec generator

dbsgtk07:12:55

what I want is a custom generator for DNA sequences.

dbsgtk07:12:50

`(gen/elements (seq "ACGT")) seems part of this. But not sure how to make the composition to generate strings (as a generator)

nikki07:12:22

@seancorfield: neat! and is the idea that by using spec it solves some of those problems 'for free'?

nikki07:12:31

without adding accidental complexity

abhir00p07:12:36

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?

dbsgtk08:12:27

oh, this works: (gen/sample (gen/fmap clojure.string/join (gen/vector (gen/elements (seq "ACGT")))))

nikki10:12:44

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

nikki10:12:54

(i think clojurescript over react-native is probs best suited for the UI rendering bit)

danielgrosse10:12:37

Exists a library which helps to communicate over unix sockets?

lvh11:12:52

@danielgrosse Hi 🙂 There’s manifold/aleph, which talk to netty. I don’t think they do UNIX sockets right now, but netty does.

lvh11:12:03

@danielgrosse If you want low-level bindings, there’s always jnr-unixsocket

lvh11:12:17

(I would strongly recommend looking at aleph and netty)

pesterhazy11:12:07

Trivia question: for an xs with 10 elements, when is (get xs 3) not equivalent to (nth xs 3)?

curlyfry11:12:38

@pesterhazy xs = [] for example

pesterhazy11:12:59

[] doesn't have 10 elements

lvh11:12:04

pesterhazy: seqs?

curlyfry11:12:13

I'll read the question properly next time! 🙂

pesterhazy12:12:05

curiously (get (seq [:a :b :c :d]) 3) returns nil

lvh12:12:15

at least it’s consistent I guess?

lvh12:12:35

pesterhazy: since it was trivia time, you know why it’s nil right

pesterhazy12:12:02

nihil, latin for nothing?

lvh12:12:15

(get '(1 2 3) 1 ::not-nil)

lvh12:12:35

(the real reason is about if it’s an IAssoc or not)

lvh12:12:25

a vec is, and a seq is not

lvh12:12:36

(at least not generally)

pesterhazy12:12:55

I guess it would be fine if get threw if applied to a non-associative coll

pesterhazy12:12:09

as it is it's a head scratcher

pesterhazy12:12:50

you change [:a :b] to (map identity [:a :b]) somewhere and ... suddenly nil

lvh12:12:57

vectors and seqs aren’t the same kind of thing in my head, so I haven’t really had that problem as much

lvh12:12:09

(it’s pretty rare that I call nth)

gfredericks12:12:00

I've developed that mental distinction too

gfredericks12:12:22

seq[able]s are generic "collections", that have ordering if you need it

gfredericks12:12:32

intentional vectors are very specialized

gfredericks12:12:56

and I never conj onto a seq so I don't have that problem either

lvh12:12:07

I treat a vec like a seqable reasonably often but then it’s no longer ok to call get on it

lvh12:12:16

typically: I want to reify a lazy seq

gfredericks12:12:43

what does that mean?

lvh12:12:54

like, unlazy

gfredericks12:12:04

you mean that's your typical use for a vector?

lvh12:12:20

maybe not the typical use case, but it happens, yeah

lvh12:12:37

but then it’s just an eager seq(able)

pesterhazy12:12:09

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

pesterhazy12:12:36

guess that's not good advice unless I know I'm dealing with a vector

gfredericks12:12:49

throwing is useful sometimes too

lvh12:12:49

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....

blkt12:12:53

does anyone of you use Bamboo with Leiningen to build and deploy jars?

blkt12:12:13

I can't get jar versioning right...

pandeiro12:12:29

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)?

pandeiro12:12:01

I thought that was kind of the whole point of component, but I must be Doing It Wrong™

dominicm12:12:15

@pandeiro Yes. Idempotency is a part of component. You should be able to call stop multiple times.

gfredericks12:12:58

idempotence is kind of ambiguous here

pandeiro12:12:04

@dominicm OK I can write conditional logic for that, but that's not the issue

pandeiro12:12:13

the issue is, the thing I assoc'd isn't there

pandeiro12:12:19

Not even on the first call of stop

dominicm12:12:39

Following a start, you mean?

gfredericks12:12:46

pandeiro: are you calling stop on the object you originally called start on, or the return value from start?

dominicm12:12:52

Ah, I misunderstood the question then.

pandeiro12:12:00

gfredericks: ahhh

pandeiro12:12:05

Which should it be?

gfredericks12:12:13

this is my least favorite thing about component

gfredericks12:12:38

it's a weeeird ambiguous mix of immutability and statefulness

pandeiro12:12:48

@gfredericks Do you have an alternative approach you use in some situations?

gfredericks12:12:21

the only other idea that comes to mind is just traditional OOP objects

gfredericks12:12:25

which I haven't tried

dominicm13:12:17

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?

pandeiro13:12:52

I am building my application at the REPL 🙂

pandeiro13:12:22

So I did (def system (start-my-system)), then (component/start system), and then silly me, (component/stop system)

pandeiro13:12:13

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

dominicm13:12:22

https://github.com/weavejester/reloaded.repl I would highly recommend just using this.

pandeiro13:12:30

Thanks, I will eventually check that out but I'd like to limit the moving parts first to better understand what I'm doing

pandeiro13:12:42

(as clearly I was not understanding component very well)

dominicm13:12:45

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.

dominicm13:12:04

The example in the README is good for understanding too ^^

dominicm13:12:46

Based on your examples, I think the distinction worth noting is that it should be init-my-system not start-my-system

pandeiro13:12:52

Is there a reason for preferring (assoc this :item nil) to (dissoc this :item)?

dominicm13:12:01

@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

dominicm13:12:50

Well, that didn't work (returned the first result..)

dominicm13:12:24

Works in the REPL ¯\(ツ)

Lambda/Sierra14:12:21

It is not strictly necessary for Component stop methods to be idempotent, but many people find it convenient to design them that way.

Lambda/Sierra14:12:17

@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.

pandeiro14:12:51

Appreciate the encouragement @stuartsierra, thanks

Lambda/Sierra14:12:05

https://github.com/stuartsierra/reloaded is a Leiningen template with an example of how I set up a new project using Component.

Drew Verlee16:12:26

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?

stephenmhopper16:12:52

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?

metametadata17:12:07

@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.

Drew Verlee17:12:54

@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 🙂

metametadata17:12:46

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.

metametadata17:12:35

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.

metametadata17:12:02

and you may also look at the Duct framework template as a starting point: https://github.com/duct-framework/duct

bcbradley19:12:04

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?

owen19:12:30

@drewverlee do you absolutely need luminus?

owen19:12:11

chestnut with the reagant template always works for me, and then you can add datomic and re-frame on top

bfabry19:12:17

@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"

Drew Verlee19:12:23

@owen, No there aren’t really any requirements. I’m trying to learn and put together a demo.

bcbradley19:12:29

@bfabry I guess it is more like layering than pipelining

dominicm19:12:15

@bcbradley it would be interesting to apply this to your clojure code.

dominicm19:12:49

To see if it encourages you to write more pure functions, and decomplect the state from logic

bcbradley19:12:08

I try to stay away from state entirely

bcbradley19:12:22

normally if i must have state, I'll "push it off till the end"

bcbradley19:12:33

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)

bcbradley19:12:56

then what I typically do is make a function that represents the entire application (when possible), that has that behavior

bcbradley19:12:32

then I implement that function using nothing but pure functions, potentially acting on some local state

bcbradley19:12:24

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

bcbradley19:12:38

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.

bcbradley19:12:09

Every app can be interpreted as a function from argument space to solution space. Sometimes its hard to coerce it though.

roelofw20:12:40

Is there a plugin or something like that for making pagination for a blog

roelofw20:12:37

oke, but partition-all cannot display things like 1 2 3 4 and so on

roelofw20:12:52

so links which a user can click to go to that page

danielcompton21:12:38

sure, that was a bit of a tongue in cheek comment 🙂

johnnyillinois21:12:54

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?

johnnyillinois21:12:11

I think it runs after each test-var

noisesmith21:12:24

@johnnyillinois the documentation for use-fixtures

johnnyillinois21:12:29

which is defined only by the deftest

johnnyillinois21:12:41

Documentation doesn't include all possible use cases

noisesmith21:12:44

it is either before and after each test, or before and after each namespace of tests

noisesmith21:12:52

it's never just before or after, it's surrounding

johnnyillinois21:12:57

Yeah, agreed on the surrounding

noisesmith22:12:02

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

johnnyillinois22:12:02

totally! the macro: deftest as part of the execution phase calls test-var (from my understanding)

johnnyillinois22:12:43

sorry, the macro only defines a function which calls test-var

noisesmith22:12:52

I didn't realize it was hooked up that way, but there we are

noisesmith22:12:46

that's funny - must be a trick so that reloads are handled properly

noisesmith22:12:59

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)

noisesmith22:12:01

the once-fixtures are all composed, and called with a function that calls the each fixtures surrounding each test

noisesmith22:12:13

(and the each fixtures are composed as well)

noisesmith22:12:51

it's the responsibility of the fixtures to make sure they call the testing function passed in

noisesmith22:12:00

and they can do their thing before or after or both as they wish

noisesmith22:12:17

and ideally they only call it once

johnnyillinois22:12:34

lol, yes ideally

noisesmith22:12:28

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

johnnyillinois22:12:05

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.

johnnyillinois22:12:21

Anyone dealing with this? How are solving it?

johnnyillinois22:12:01

Trivially, one can truncate the database inside the test execution (but that seems "dirty")

johnnyillinois22:12:09

I'll put some example code

johnnyillinois22:12:33

(deftest insertion-into-db-test
  (properties/for-all [entity entity-generator]
    (insert-into-db! entity) ; can violate uniqueness
    (is (in-db? entity)))

seancorfield22:12:39

Your fixture should run for that deftest — just once around the whole test.

johnnyillinois22:12:26

Agreed! I am wondering how people are doing database truncation under that implementation

seancorfield22:12:48

Don’t do generative testing on things that involve mutation and external services?

johnnyillinois22:12:14

Any other ideas?

seancorfield22:12:17

I mean, as a general principle. That’s just not safe in general.

tbaldridge22:12:17

Or truncate the DB, those are really your two options

tbaldridge22:12:39

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

tbaldridge22:12:53

but it'll be slow, so try something different if you can.

seancorfield22:12:23

What are you really testing here? Business logic? Or mutating the DB?

johnnyillinois22:12:23

Yeah... those are the baseline fixes. I am wondering if there is something better.

tbaldridge22:12:29

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.

tbaldridge22:12:44

Not really because the for-all has to do some sort of backtracking to shrink the failing case.

nwjsmith22:12:47

I’ve been opening a transaction and rolling it back at the end of the test

tbaldridge22:12:58

so the body of the for-all gets executed many times.

seancorfield22:12:13

You shouldn’t need to test that a JDBC insert! works — you should consider what in your function you’re really trying to test.

johnnyillinois22:12:50

The actual test is more like:

(deftest my-test
  (insert-into-db! entity)
  (is (expected-json? (app request)))

johnnyillinois22:12:18

Agreed, boundaries!

johnnyillinois22:12:43

I familiar with the argument for isolating unit testing from the database and other side effects

johnnyillinois22:12:48

These are integration tests

johnnyillinois22:12:46

and everyone else!

tbaldridge22:12:10

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?

tbaldridge22:12:49

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

johnnyillinois22:12:53

sure! we can have a database abstraction function (or set of functions)

tbaldridge22:12:58

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

tbaldridge22:12:17

Basically instead of testing a single command, you can test a session of dozens of commands.

johnnyillinois22:12:35

Yeah, that is a powerful feature