Fork me on GitHub
#off-topic
<
2018-09-01
>
priornix06:09:24

Hi, just a quick question. Is anyone using Slack for notifications about things like website, server monitoring? Just a quick question for you guys

emilaasa07:09:02

@priornix Did you have any specific question?

dominicm08:09:51

I need to document that it handles a lot of event types now

vemv12:09:26

Unixy one... given a set of lines, how do I sort them by a set of words? i.e given an input like,

cljfmt/src/cljfmt/core.cljc
cljfmt/test/cljfmt/core_test.cljc
I want to show the lines matching src first, then test. For each group (src/test), lines should remain sorted lexicographically. So the final command would look like git ls-files | sort-by "src,test" Hopefully the syntax would be clean so I can easily change src,test to foo,barin a different project (also speed is a requirement)

henrik13:09:58

@vemv Check out group-by or partition-by. Then sort each group internally (`sort-by`).

henrik13:09:42

Note: if you use partition-by, you have to make sure the primary collection is sorted first.

vemv13:09:00

asking for unix, sorry! 😊

henrik13:09:11

You even said so.

henrik13:09:09

Alright, then #!/usr/local/bin/lumo at the top of your script, then all of the above applies. 😉

souenzzo13:09:00

@vemv just git ls-files | sort should do the work

vemv13:09:48

@henrik dunno, I feel it'll be slow. 1.5 secs too unnerving for the UX I'm building

vemv13:09:20

@souenzzo what if I want to sort by foo, bar instead of by src,test?

henrik13:09:18

Surely Lumo is faster than that? But I haven’t really measured.

henrik13:09:57

And to be fair, I’ve never written anything short-running with Lumo

souenzzo13:09:15

git ls-files | tee tmp.txt | egrep 'foo' > foo.out; cat tmp.txt | egrep 'bar' > bar.out egrep allow to use regexp.

roklenarcic13:09:02

Lumo is node-js tech?

roklenarcic13:09:41

NodeJS startup time = JVM startup time, difference is Clojure class loading and compilation

souenzzo13:09:18

you can also checkout GraalVM. Do this script with sh/sh and slurp, then build with native-image and then export a binary with "zero" startup time (like cljfmt does)

roklenarcic13:09:54

yes grallvm works, but you can't run any eval and the community edition only has binaries for linux

henrik13:09:58

That’s a shame

vemv13:09:39

I'd try to go the bash route (that way I don't have to make presumptions about my users)

vemv13:09:05

will play with the bash snippet above. btw item 6 would be a good fit https://zwischenzugs.com/2018/01/06/ten-things-i-wish-id-known-about-bash/

roklenarcic13:09:18

oh just looked.... MacOS binaries are now also available

👍 4
3Jane13:09:23

It depends on how involved you want the foobar criteria to be (is it a list of entirely arbitrary strings?), and whether they change over time

vemv13:09:41

* the strings represent directories like src, test, src/dev etc. So not that arbitrary * they definitely change over time - each project can have its own directory list

3Jane13:09:05

And in the order it matters that src is not the same as lines with src/dev, right?

vemv13:09:06

yeah it's like a priority list. For src/dev,test,src Lines should be emitted in that order: src/dev, test, src

3Jane13:09:23

The simplest way I can think of is to have an array/list of patterns, and use the index of matched pattern as score for the sorting function.

3Jane13:09:56

The fact that one line could match several patterns (as with src, src/dev) complicated things, since you have to check patterns in order of specificity which might not be the same as the order you in which you want to output

3Jane13:09:29

Which means you might have to annoyingly hand craft a map for every project

3Jane13:09:56

(If you used this method)

3Jane13:09:34

Unless you can figure out some restrictions that will always apply to your sort criteria.

3Jane14:09:45

That’s why I asked about arbitrariness: as a further example, for patterns abc/src, src, src/cde - and a file on path abc/src/cde, which one would you expect to match, and in what order to sort, would require defining pattern match order and sort order separately

vemv14:09:50

I like the idea of an array of patterns. if you have [/src\/dev/, /test/, /src/], then you can shortcircuit at the first matching regex and grab that index. That way there's no ambivalence

vemv14:09:41

I'll probably implement it as a ruby script, they tend to be reasonably fast and accessible. Perl definitely out my reach 😂

3Jane14:09:09

You could not short circuit at the first matching regex if you wanted src to be sorted before src/dev

3Jane14:09:54

(Because all src/dev would match on src)

3Jane14:09:57

But yeah, language makes no difference as long as you know the env contains it :)

vemv14:09:12

> You could not short circuit at the first matching regex if you wanted src to be sorted before src/dev The intent is kind of non-sensical, the user cannot possibly want to display src before src/dev. Bit hard to explain but I think it's easy to see. That said, one could pass a regex like src/^(?!dev)

roklenarcic13:09:45

I hear Windows GraalVM will come with Java 11

schmee14:09:47

where did you hear this? 🙂

henrik13:09:53

What would be really cool is Graal in serverless workflow, such as with Ions. But I understand there are limitations still.

3Jane13:09:51

Perl tends to be good for this kind of stuff (ie somewhat more advanced string processing if you’re doing it as a one liner from command line.) You can feed a comparison function to its sort. Also it’s ubiquitous, like bash.

👍 4
vemv13:09:23

thanks for the pointer!

roklenarcic13:09:55

I am mostly excited about using Clojure to write command line apps with GraalVM

roklenarcic13:09:33

Unfortunately what is more likely to be the result of GraalVM is more intrusion by Python, JS and Ruby on Clojure's turf

henrik13:09:08

I will stick with Clojure until there’s a smaller mind-machine interface available. None of those languages solve that for me.

vemv14:09:36

For anyone curious this is how the final script looks like git ls-files | ruby -e 'puts STDIN.read.split("\n").sort_by{|line| %w(src test).find_index{|pattern| line.include? pattern } || 9999 }' I often forget about ruby's scripting capabilities, defo they take a sweet spot between speed, concision, ubiquity, etc

ahungry15:09:26

scripting with common lisp is decent, the startup time with a core dumped image is sub 5ms, if not core dumping its a second or two the first run of it on boot and then, again, sub 5ms runs after

parens 4
tbaldridge17:09:47

Community edition of GraalVM runs on OSX. Ran it last night 😀

👍 12