Fork me on GitHub
#clojure
<
2015-09-07
>
pupeno08:09:09

When making Ruby on Rails applications I generally just throw active_admin into my projects to be able to edit records. My searches for something like this for Clojure turned up nothing (not unexpected). What tools do you use for CRUDing records?

stathissideris08:09:37

is there any way to pr-str using the DEFAULT printers only?

jaen09:09:43

@pupeno: I remember caribou framework having some admin functionality, but I think it only works with their models.

profil09:09:59

is there anything similiar to map-indexed for reduce?

profil09:09:17

or should I do (reduce f val (map-indexed vector coll))?

pupeno09:09:53

I’m doing some performance testing of my Clojure app, and it seems the bare minimum will happily eat 350MB of RAM (Jetty with 6 threads, the minimum). As soon as I add Nashorn, it jumps to >512MB. Is this common or am I experience a problem here? Clojure/Java being memory hungry might have an effect on whether I use Heroku or not.

ergl10:09:42

is there any way of trying external libraries from lein repl without creating a new project?

pupeno10:09:58

ergl: lein-try is what you want, it was developed by the guys who wrote the Clojure Cookbook. I never tried it though, does it not work?

ergl10:09:59

haven't tried it yet, just asking because I saw that the last commit was a year ago

beppu10:09:00

lein-try works well.

beppu10:09:24

I would consider it a "done" project; there's nothing more to add or remove, hence no recent commits.

beppu10:09:37

...well, i guess there are a few issues (https://github.com/rkneufeld/lein-try/issues) but i have not run into them.

ergl10:09:18

you're right, it works pretty well

casperc10:09:50

prismatic/schema question: Is it possible to make the validation default to treating the keys as optional? By default it treats the keys as required, but alot of times we want to use the schema to outline the data structure, but most keys are actually optional.

casperc10:09:08

So if this is my scheme: (def FooBar {:foo s/Str :bar s/Keyword}) i want (s/validate FooBar {:foo "f”}) to pass validation.

jaen10:09:09

I don't think you can, at least in an obvious way. I just mapped the schema to wrap keywords in optional-key.

jaen10:09:43

If you have nested maps in schema then you'd have to use clojure.walk or something

casperc10:09:47

That’s what we are doing as well, but it does look quite ugly to basically do that to the entire map

jaen10:09:15

I do quite agree, but if there's an option for that it's not easily discoverable, to me at least

casperc10:09:28

yeah me neither.

casperc10:09:27

I might try writing a validate-optional function

ergl10:09:51

I think you can use s/Any for that specific case

ergl10:09:15

but you'd have to use a different schema

ergl10:09:23

so (def FooBar {:foo s/Str s/Any s/Any}) would make (s/validate FooBar {:foo "f}) pass

amithgeorge10:09:25

@casperc: tangential, but when you mean optional keys, do you mean missing keys will be given a default value? or are they mutually exclusive? If the former, then why not validate after the missing values are filled in?

casperc10:09:32

@amithgeorge: I don’t mean to give the missing values a default value. The specific case I keep running into is that I want to define a schema for a large(ish) data structure, but most of the keys are optional and not present in the normal case. I want the validation to pass if given a subset of what the schema defines. I want to the validation to fail if given a map containing keys not in the schema (or of the wrong types).

amithgeorge11:09:45

If the keys are optional and they won't get populated with default values, then can it be assumed that provided and missing keys won't be used by your code at the same time. In which case you could split each group of keys into separate schemas and create a top level schema whose each key is optional and value maps to corresponding group schema.

stathissideris14:09:05

is there any way to define a default handler for fressian, one that is used when no other handler is matched

pupeno14:09:36

Is there an easier way to use an unreleased branch of code than releasing it as a jar?

pupeno14:09:22

Like, can I point to a repository/branch instead of a jar in my project.clj (a-la Ruby/gem/bundle/Gemfile)?

jaen14:09:21

There's checkout dependencies in lein and recently I've stumbled upon this - https://github.com/tobyhede/lein-git-deps. Not sure how well does it work though.

benedek15:09:26

i have never used it tho...

benedek15:09:46

haha, i should read first before posting, sry

escherize15:09:52

oh my god, I've never used clj-webdriver before. It is sooo awesome

cfleming17:09:11

I’d like to check in some test data files somewhere in my project that I can access from clojure.test tests

cfleming17:09:44

What’s the best way of passing their location to the tests? I need them to be files so resources are probably not useful here.

cfleming17:09:03

I can use a system property obviously, is there a better way?

alexmiller17:09:22

if you can load them with relative path, the "current directory" will be the root of the project when you run

nberger17:09:48

What Alex said, but also, what's the issue with resources? You could even add a separate dev-resources to :resource-paths in the :dev profile... while in dev (I mean, not in the jar), (io-resource ...) will return a "file location" (not a url as when in the jar). The advantage of using resources instead of just files relative to the current directory is that you could move the resources dir to a new location without the need of changing the tests. But of course you could use a helper fn to abstract that location too

nberger17:09:34

Sorry, it will return a url, but one that will plays well with (io/file (io/resource ...))

cfleming17:09:33

@nberger: Interesting, thanks - I didn’t know that. That does sound like the best solution.

cfleming17:09:42

This is for testing the new lein integration I’m working on - it looks like lein itself just uses CWD as suggested by alexmiller to get to its test projects

cfleming17:09:48

But I think I like nberger’s solution better

pupeno19:09:16

What do you use to deploy Clojure web apps to your own servers?

martinklepsch19:09:49

@tcrayford: I assume that haskell app runs on a separate instance?

tcrayford19:09:24

I run one of them for each yeller server and front it with haproxy

tcrayford19:09:34

it doesn't do very much at all as far as modern computers are concerned

martinklepsch19:09:23

not asking from a perf perspective but rather stability or so, so the haskell thingies run on each instance that also runs the fat jar?

tcrayford19:09:27

well, one haskell thingy deploys to all servers. I just keep one on each instance so that if an instance is down I can deploy still

martinklepsch19:09:59

I see. Cool. I remember reading that article before but somehow missed the haskell app which is a nice idea. (Or at least seems like one.)

tcrayford19:09:20

just easier for me to write than a server in most other languages that talks over json/http to circle

amacdougall22:09:28

With clojure.test, is there a way of defining some setup that runs before any test namespace? Luminus provides a sample test namespace with this:

(use-fixtures
  :once
  (fn [f]
    (db/connect!)
    (migrations/migrate ["migrate"])
    (f)))
This is great and all, but I don't need to connect and bring migrations up to date before every test namespace. (I'm treating test namespaces kind of like suites, which seems reasonable enough, so I have a fair number of them.)

amacdougall22:09:55

It's not hurting anything, but offends my sense of tidiness.

tcrayford22:09:39

@amacdougall: how about just calling a function before you call run-tests

amacdougall22:09:21

Sounds reasonable! I'm using https://github.com/jakepearson/quickie for autotest (which is really handy in combination with a toast notification on failures), but I bet I could add the ability for it to run a little custom code before each execution.

jakemcc22:09:32

@amacdougall: responding to this a bit late, but both lein-test-refresh and quickie reload namespaces and rerun tests. They both add a couple features on top of the “use tools.namespace to refresh namespaces and rerun tests main feature”. It sounds like you already found a solution for notifications with quickie, but if you find lein-test-refresh’s success notifications annoying you can turn them off (https://github.com/jakemcc/lein-test-refresh/blob/master/sample.project.clj#L18).

amacdougall22:09:21

Oh, if lein-test-refresh does the namespace reloading thing, that could be just the ticket! I was using multitail to grep the Quickie output and fire notifications on failures/errors, which is kind of a Frankenstein solution. I'll try out lein-test-refresh and see if I like it better. Thanks!