Fork me on GitHub
#clojure
<
2018-07-25
>
souenzzo01:07:43

I need a "infinite loop" that every "5" seconds fetch a API and insert data in a channel In some situations, I wanna be allowed to stop this service and start it again. Should I use thread, async/go, future-call? There is many options and I cant decide.

delitescere02:07:31

Do you want the responses to be in the channel in the same sequence as the requests that made them?

henrik05:07:00

What routing libs are the kids using nowadays?

henrik05:07:54

Are they hanging on to their grandfather’s Compojure?

😀 4
justinlee06:07:52

@dominicm i think the framing is wrong: the question isn’t whether they are constants but whether they are globals. there is (some) value to calling attention to that.

manuel06:07:00

@henrik I am still on Compojure

👍 4
seancorfield06:07:28

@henrik We use Compojure mostly at work, with Bidi on one of our apps. We may use Bidi more in future since it separates routes from handlers better (and allows for bidirectional route naming).

👍 8
↔️ 4
4
seancorfield06:07:19

@lee.justin.m Globals as opposed to... local bindings? Do they need separate naming conventions? Surely you can see a local binding on the same screen as the code that uses it? (or else you should probably refactor your function into smaller functions)

seancorfield06:07:55

Would you argue "global" functions should have a different naming convention to local bindings of functions?

seancorfield06:07:32

Any symbol that isn't obviously and visibly a local binding (or argument) must be global by definition, right? I'm having a hard time accepting that different naming conventions are needed for that...

👍 4
justinlee06:07:42

I think it is helpful and it doesn’t hurt. But I’m just offering my view

justinlee06:07:38

commas in english text aren’t strictly necessary, but they improve readability

justinlee06:07:15

I find it particularly helpful in communicating that “this is an arbitrary parameter” like 200ms of delay or something like that.

seancorfield06:07:04

Commas in English text have semantic meaning so, yes, that are necessary.

seancorfield06:07:22

Commas can't just be randomly added and taken away. They're not about readability.

andy.fingerhut07:07:33

Compare: "Let's eat, grandma!" vs. "Let's eat grandma!"

orestis08:07:17

Perhaps editor support would help. Different color based on binding type.

jgh09:07:26

hey guys, I want to read from stdin as it is written to by another program, doing (slurp *in*) works, but only if i've received EOF. What I want instead is to know about more data and be able to react to that as it comes in (similar to epoll/select in C). It seems like there may be a way of doing that with channels, but I'm not really familiar enough with them to put it together yet. If anybody has some tips it would be helpful 🙂

jumar09:07:05

@U36FXS8SD you may create a BufferedReader and read from it - e.g. line by line:

(let [rdr ( *in*)]   
  (.readLine rdr))

jgh09:07:38

this will block until it gets more data?

jgh09:07:59

Seems to work. I ended up having to do

(let [rdr ( *in*)]
    (doseq [line (line-seq rdr)] ... ))
but you got me pointed in the right direction, thanks!

heefoo20:07:21

line-seq calls .readline with lazy-seq if I remember correctly. Doseq goes all the way around to realize the sequence. You should just call .readLine directly

heefoo20:07:05

Maybe with a type hint to avoid reflection and make ir faster.

jgh20:07:19

shouldnt it just return a string?

heefoo15:07:05

I think the .read method returns a character and you can read until eof.

heefoo15:07:19

And .readline the next string until EOL.

jgh15:07:49

you were saying to call readLine with a type hint, but isn't it always just string?

heefoo18:07:18

Indeed but as far as i know . Notation uses reflection either way.That can slow production code. Just

` (set! *warn-on-reflection* true) 
`on the repl and see it for yourself. @U36FXS8SD

heefoo18:07:12

Warn-on-reflection inside earmafs

beoliver09:07:08

is it possible to inline predicates in a spec? Assume that I am checking maps with three keys :foos :bars and :op where :foos and :bars are always vectors - but the structure of their elements is dependent upon the value of :op. Assuming that :op could be be 1 or 2 - Is there a way of achieving something like

(s/def ::check-op-1 (s/keys :req-un [[::op op-1?] [::foos foo-1-pred?] [::bars bar-1-pred?]]))
(s/def ::check-op-2 (s/keys :req-un [[::op op-2?] [::foos foo-2-pred?] [::bars bar-2-pred?]]))
(s/def ::valid-data (or ::check-op-1 ::check-op-2)))

chrisblom09:07:15

@henrik I can never remember the bidi syntax, so i still use compojure for simple stuff, and bidi for everything else

👍 4
andrea.crotti12:07:43

is there any tool that helps with replacing all the :refer :all in namespace declarations with :as something and then prefixing all the vars accordingly?

andrea.crotti12:07:21

I would like to clean up a project that uses that all over the place without having to do it manually since it would take ages

andrea.crotti13:07:40

that's quite nice actually but I can do similar things with Emacs and projectile probably

andrea.crotti13:07:08

it's more important to have enough knowledge about the project like refactor-nrepl has to really do it in one go maybe

orestis12:07:52

I wonder how hard would it be to write a program that does it, using the Clojure reader. But I’d probably use sed or something similar…

andrea.crotti12:07:04

well it's not so easy/possible with sed since it would have to find where something comes from

andrea.crotti12:07:12

assuming there are many :refer :all per namespace

andrea.crotti12:07:36

if there is only one it could be doable but you would still have to know which symbols to replace

andrea.crotti12:07:04

and well probably need to do something ad hoc, I thought maybe Cursive or something else was able to do that

mg12:07:15

@andrea.crotti clj-refactor for emacs has some tools for that. For instance https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-stop-referring

👍 8
andrea.crotti12:07:59

ah nice. it's failling on this project now but I can try that in other projects as well

Al Baker13:07:30

is the etaoin library for webdriver based testing still in vogue as A Good Thing or has it been surpassed by another library/methodology?

metametadata14:07:17

Hi. Is a single spit into a file atomical? I want to make sure that either the old content is left in or all the new data is written.

manutter5114:07:24

If there’s a power failure or something, it might not be. The safe way is 1) write new data to a file with a tmp name, 2) rename the old file to file.bak, 3) rename the new file to the correct file name. That way you’re as sure as you can be that your old data is there until the new data is fully written.

metametadata15:07:41

Right, or use some 3rd party solution. I was just hoping that maybe it's a built-in feature for the single write.

genekim16:07:25

Hello all! Quick question? I’ve noticed when I used either pmap or Thread/sleep 100 (don’t know if it’s one, the other, or both) causes my Clojure program to require 30 seconds before exiting, as if waiting for a thread to be killed. I seem to recall there was a Clojure call that “kills/cleans-up all threads” so the program can exit quickly/cleanly — can anyone point me in the right direction? Thank you, as always!

genekim16:07:25

Yes! Thanks so much, @the2bears! Iit was one of those things I just put up with (just hit Control-C), but part of me really wanted to figure out how to actually fix it. 🙂

👍 4
adam16:07:16

I am using bidi make-handler for routing but it seems / is required. "something" something-handler doesn't work when called like ...com/something/ - any idea how I can make non / redirect to /. Should I really create a redirection for every route?!

dominicm21:07:54

Bidi is data, so automatically adding the routes is easier

emccue21:07:56

what are the best clojure/java authentication libraries

emccue21:07:13

im looking for some set of libraries at least on par with Passport.js

arrdem21:07:04

With deps.edn, is there a good way to have several projects in a single repository which share a single set of pinned dependencies? I’d like to have something akin to a versions.edn which just pins versions for dependencies, which deps.edn files can reference.

Alex Miller (Clojure team)21:07:49

default-deps is a nod in this direction and something we want to enable, but not really practically useful yet. Needs a bit more work

ghadi21:07:14

unlike boot and lein, deps.edn is Just Data.

ghadi21:07:47

that's my semi-sarcastic answer at the end of a long day simple_smile

hiredman21:07:56

something like a parent pom, a project that is just there for common deps, could be a thing

ghadi21:07:25

nothing baked in (yet), but trivial with a small build step

arrdem21:07:54

Hah no worries Ghadi, I’m currently trying to replace a fairly involved set of lein projects with something that’s at least Mostly Data (TM) mainly for classpath caching and simplified impact analysis.

ghadi21:07:46

Small Build Step is also (TM)

arrdem21:07:37

Looks like the “easiest” thing to do is a custom runner which uses the deps machinery under the hood, and comparable bash script to $ which clojure that can handle the cache check/hit logic.

ghadi21:07:17

I think the caching currently includes a timestamp check, too

arrdem21:07:32

Since really what I want is effectively middleware - of which deps has none because exposing arbitrary middleware defeats most caching 😕

hiredman21:07:00

it may also be easier if you break it in to parts

hiredman21:07:45

there are at least 2 parts. 1. specifying commons deps in one place and 2. ensuring all projects are using a specified version of certain deps

hiredman21:07:16

#2 seems like the biggest bang for the buck, just some tool to scan deps.edn files and throw an error if the expanded deps map uses a different version of a dep, and then make it part of your test suite

ghadi21:07:34

Untested; You could also use a top-level deps.edn only, and aliases to mix in the correct versions, along with the :default-deps key @arrdem

ghadi21:07:12

> :default-deps provides a set of default coordinate versions to use if no coordinate is specified. The default deps can be used across a set of shared projects to act as a dependency management system: https://clojure.org/reference/deps_and_cli

ghadi21:07:35

It depends on how much varies with the subprojects

arrdem21:07:09

Hum, that may be close enough for what I need.

ghadi21:07:04

I think you can trigger default-deps by making the rhs in the deps map nil

arrdem21:07:22

That’s what it looks like - which is actually exactly what I need.

ghadi21:07:38

I'd be curious to see how that works out.

arrdem21:07:40

Cool that totally lets me fake this well enough.

arrdem21:07:48

Thanks Ghadi!

arrdem21:07:48

I promise I’ll write up an experience report once this works out 😉

Alex Miller (Clojure team)21:07:24

We would definitely like to have a clean path to do this. It is In Scope. :)

arrdem21:07:42

Hum yeah it doesn’t look like there’s a way to bolt on another source of deps data atm beyond the “$PWD/deps”, CLI args and the config, and I’d like to avoid making my coworkers install user level configs.

ghadi21:07:34

arrdem for now I think you'd have to put everything in the top-level deps edn:

{:deps {whatever...}
  :aliases {
  :versions {:default-deps ....}
  :subdir1 {...}
  :subdir2 {...}}}

ghadi21:07:46

Sorry for the pseudogarbage. Then you'd launch with clj -A:versions:subdir2

ghadi22:07:16

no need for user-level config

arrdem22:07:59

Computer, do what I mean not what I say

arrdem22:07:53

Yeah that’d definitely work Ghadi, and wiring CI up to run that would be pretty straightforwards.

ghadi22:07:31

the version alias would have :default-deps, all other aliases could be free form (mostly extra-deps / extra-paths)

arohner22:07:47

Is quartzite still the best way to do cron-like tasks?

martinklepsch22:07:02

I recently used tea-time for that stuff. If you care about dates and not just time also consier tick

camdez23:07:48

I’ve also used Chime (https://github.com/jarohen/chime) for a couple years in production and it works just fine.

val_waeselynck05:07:58

On AWS, I use Cloudwatch

manuel06:07:29

I went with factual/timely recently to schedule a task