loveknight

joined 3 weeks ago
[–] [email protected] 0 points 1 day ago

Ah that's good to know about zsh.

Sorry regarding the second code block; it does indeed work as intended, and quite elegantly.

[–] [email protected] 0 points 1 day ago (2 children)

For the first code snippet to run correctly, $list would need to be put in double quotes: echo "$list" | ... , because otherwise echo will conflate the various lines into a single line.

The for loop approach is indeed quite readable. To make it solve the original task (which here means that it should also assign a number just smaller than $threshold to $tail, if $threshold is not itself contained in $list), one will have to do something in the spirit of what @[email protected] and I describe in these comments.

[–] [email protected] 0 points 2 days ago* (last edited 2 days ago)

Thank you, in fact I ended up doing something that's mathematically just about that: I have the previous line stored in an auxiliary variable lastline, and it is the evaluation of the current line $0 that determines whether the previous line gets printed.

awk -v threshold=150 'BEGIN {lastline=""}
  (lastline!="" && threshold<$0){print lastline} #the additional check lastline!="" prevents an empty line at the very beginning
  {lastline=$0}
  END{print} #hardcode printing of the very last line, because otherwise it would never be printed
' 

(IIRC, it was a StackOverflow post that led me to this.)

 

Let me show you what I mean by giving an example:

# Assume we have this list of increasing numbers
140
141
145
180
190
...

# If we pick 150 as threshold, the output should consist of 145 and all larger values:
145
180
190
...

# In the edge case where 150 itself is in the list, the output should start with 150:
150
180
190
...

I guess one can always hack something together in awk with one or two track-keeper variables and a bit of control logic. However, is there a nicer way to do this, by using some nifty combination of simpler filters or awk functionalities?

One way would be to search for the line number n of the first entry larger than the threshold, and then print all lines starting with n-1. What command would be best suited for that?

Still, I'm also wondering: Can awk or any other standard tool do something like "for deciding whether to print this line, look at the next line"?

(In my use case, the list is short, so performance is not an issue, but maybe let's pretend that it were.)

 

When I'm editing with helix, I often have multiple instances of it running, one for each file, in different terminals (more precisely: in different tabs of my terminal emulator, Konsole). Currently, the title of these tabs reads just Directoryname: helix It would be really helpful the titles instead included the filename of the file currently opened. Is there a way to do this?

[–] [email protected] 1 points 6 days ago

Very specifically for learning about GNU/Linux and Unix, I highly recommend the book Classic Shell Scripting by Arnold Robbins and Nelson Beebe (O'Reilly Media, 2005).

ISBN: 9780596005955

I recently wrote the following about it in a post:

This book is extremely readable and gives a very good introduction to the various standard Unix shell commands (grep, sed, awk, tr, sort, to name but a few) and how to tie them together to do useful things. It’s very suitable if you have some experience with the command line at the level of individual commands but now want to see how to do construct more interesting pipelines and scripts. It includes an introduction to regular expressions. The fact that the book is already 20 years certainly means that some explanations and approaches are outdated, but since shell programming is at the core about text processing, almost all contents of the book are still highly relevant today.

1
submitted 6 days ago* (last edited 6 days ago) by [email protected] to c/[email protected]
 

I don't have to tell anyone that commercial printers suck (with the possible exception of Brother, but how long will this last?). I've read people on Lemmy talk about the viability of making a FOSS printer. I'd like to keep these thoughts going.

From what I remember, there are four main challenges, listed descendingly by their apparent difficulty:

  1. Handling ink
  2. Meeting legal regulations
  3. Moving the moving parts
  4. Patents

Patent difficulties indeed should be avoidable, since decent printers have been out there for way more than 20 years, the usual duration of a patent.

Moving the moving parts with the high precision necessary does at first glance seem daunting, but I've read people say that this is a problem many people know how to solve.

Meeting the legal obligations may ne trickier: Printer fingerprints? Aerosols? Other health and environmental hazards?

Handling ink: From what I remember, this would be the main difficulty (unfortunately I can't find that post or comment anymore). One should avoid the problem of creating an own cartridge & nozzle production by designing the printer such that it can use an existing cartridge model (one for which there are good third-party offers). Still, one would have to solve the apparently very difficult problem that the ink/toner has to be handled under very precise conditions, regarding things like flow velocity, drying rate, and perhaps temperature.

In view of these challenges, I've started to think that maybe the best approach would be to try our best to find ex-employees of printer companies and convince them that they would be doing humanity a huge service if they were to contribute with whatever they legally can towards developing a FOSS printer.

Also, I've wondered whether the time to do this may be running out: If even Brother one day starts to crack down on third-party ink/toner, all the producers for third-party ink/toner could eventually go out of business; so that one may successfully develop a FOSS printer, only to have no other ink in the stores than the price-gouged one, which was the reason to do all this in the first place.

Do you have any corrections, specifications, or further thoughts? I'd love to hear them.

 

ISBN: 9780596005955

This book is extremely readable and gives a very good introduction to the various standard Unix shell commands (grep, sed, awk, tr, sort to name but a few) and how to tie them together to do useful things. It's very suitable if you have some experience with the command line at the level of individual commands but now want to see how to do construct more interesting pipelines and scripts. It includes an introduction to regular expressions. The fact that the book is already 20 years certainly means that some explanations and approaches are outdated, but since shell programming is at the core about text processing, almost all contents of the book are still relevant today.

 

Things I would like every young web engineer to learn:

  • anything you can do in CSS + HTML, you should do in CSS + HTML
  • framework du jour is not a platform, it's a high-interest loan against your future capacity. The platform is the platform
  • understanding the memory hierarchy always matters
  • client-side isn't easier than the server, and "generalists" usually suck at client-side. Mind the (packet) gap
  • managers who are not technical are not useful
  • put users first, always

Second-order things to learn:

  • the way browsers work isn't static, but it also isn't changing that fast. Learn as much as you can and update every few years; particularly about networking and the rendering loop.
  • JS is the slowest way to do anything on the web. Never let it become the way you do everything.
  • a11y isn't nice-to-have, it's the job
  • shipping fast almost never matters as much as quality, & there are simple heuristics you can use to understand the difference
view more: next ›