Fork me on GitHub
#off-topic
<
2019-12-23
>
dangercoder08:12:33

Any good resources for beginners to learn Clojurescript? (Free). A co-worker with 8 years + of javascript experience is trying out Clojurescript for the holidays. πŸ™‚

dharrigan09:12:50

Perhaps someone in #clojurescript can help out?

πŸ‘ 4
vemv17:12:14

What's a unix equivalent of (sort-by (partial re-matches #"foo"))? i.e. some magical combination of sort + grep

andy.fingerhut18:12:15

That (re-matches #"foo" s) expression returns "foo" if s is "foo" , otherwise nil. Do you mean you want something that sorts all lines not equal to "foo" so they come first, followed at the end by all lines that are exactly "foo" ?

vemv18:12:59

the regex itself doesn't matter much, sorry for that confusing bit I care more about the notion of "sorting by whether $regex matches"

andy.fingerhut18:12:12

There is probably something different than this, but you could do grep foo file and concatenate that output with the output of grep -v foo file

vemv18:12:22

yeah that could be a last resource :) wouldn't look pretty in my CI pipeline

andy.fingerhut18:12:14

oh, you want "pretty" πŸ™‚

vemv18:12:03

not necessarily a code golfing request... but yeah... doing the grepping twice isn't optimal the process I'm grepping isn't free

andy.fingerhut18:12:29

If there were a way to make grep prepend something to each line indicating whether the line matches or not, you'd be all set, but I don't see any options to grep that do that on my system.

4
p-himik18:12:18

If that's your pipeline, do you really have to use grep?Why not use something like https://github.com/borkdude/babashka ?

p-himik18:12:56

BTW just prepending the output of grep won't work for all patterns since in general the separator could be in the pattern itself.

πŸ‘ 4
vemv18:12:27

I know babashka, introducing it in a CI pipeline is not free of risks (in the same way that I only use vi/bash in servers, as much as I love emacs/zsh)

andy.fingerhut18:12:31

sed/awk are more flexible than grep, and likely to provide more opportunities for answers.

πŸ‘ 4
andy.fingerhut18:12:33

Using sed/awk to prepend one string, e.g. '0' if a line contains a match, and '1' if a line does not contain a match, you can feed that directly to 'sort', and then another simple command could remove all of the '0' and '1' at the beginning of each line.

vemv18:12:45

interesting. this brings to mind similar solutions I've hacked in the past. fwiw I used things like XXX and YYY as delimiters ;p also I tend to like ruby for these, it has quite a sweet spot and is ubiquitious enough

andy.fingerhut18:12:07

do you want to sort lines of one file, or across multiple files?

vemv18:12:16

one input stream

borkdude18:12:05

@vemv :

$ echo "foo\nbar" | bb -io '(sort-by #(re-matches #"foo" %) *input*)'
bar
foo

vemv18:12:49

yeah it's nice :) at some point I might be babashkaing in CI