Hacker News new | past | comments | ask | show | jobs | submit | more lelf's comments login

Ctrl + [


C11 (C—E—G—Bb—D—F) is a superset of C major (C—E—G), so just use it.


> Where are the comments?

While I can understand how that code can be intimidating to a programmer with a more “traditional” background… there are 26 (non-empty) lines of comments, and only 15 lines of code.


10 of those 26 are "exercise", not comment. The 6 lines above that are ununderstandable, and I can only find two others, which fail to explain what it's supposed to do.

In this context, "intimidating" and "less tradational" are euphemisms that stem from cognitive dissonance reduction.


Stable software! Rare these days.


Liked, subscribed, followed on twitter, starred on github, and added on myspace


  10 LIST


Agree about ligatures too. Many of those are pretty unpleasing to read (AKA typographically wrong), e. g. /=.


Quite surprising for me too. Or rather, I don't understand the unit they mention. From the article linked:

also collected alcoholic beverage consumption, including red and white wine separately (4 ounces, increasing to 5 ounces in 2006), beer (one glass, can, or bottle), and liquor (one drink or shot). We multiplied the amount of alcohol in grams per specified portion size by servings per day, determined the midpoint of the frequency category, and summed across all beverages to estimate the average alcohol consumption (g/day). We defined moderate alcohol consumption as 5-15 g/day for women and 5-30 g/day for men

Surely it cannot be 4 bottles of beer daily (or 4*7 bottles on weekend).


This left me confused as well. This NHS article on alcohol abuse cleared it up, though: https://www.nhs.uk/conditions/alcohol-misuse/

> A unit of alcohol is 8g or 10ml of pure alcohol, which is about:

> half a pint of lower to normal-strength lager/beer/cider (ABV 3.6%) > a single small shot measure (25ml) of spirits (25ml, ABV 40%)

So a 12oz bottle (.75 pint) of 3.6% beer would be 1.5 NHS units. A bottle of 7.2% stout would be 3 units. A full 4 units per day would require a bottle of strong 9.6% beer, or two bottles of a 4.8%.

While less eye-popping than four bottles a day, that still seems like a lot of drinking to me, especially if concentrated around a few days. That's 14 bottles of 4.8% beer per week, so imagine four beers on a Wednesday, seven on Friday night, and another three over the weekend after the hangover's worn off – week after week. That seems like it would have to have a health impact, and it's surprising to see it as the limit for "moderate" drinking.


It is a lot. Recent advice (2016) cut the limits for men down to 14 units a week. The advice has always included recommendations to have some days drink free, and not to save the units up to drink more on one day.


Ah. A USA "drink" is 15ml, so 1.5 UK units.


That still seems like a lot to me. I've always heard that 2 "drinks" is the limit for being able to drive, and it seems that drinking "during the day" (before dinner) is culturally frowned upon, so taking the advice of 2-3 "drinks"/day would mean you're at the limit every evening. If you have one or more sober days, you'd be over the limit every non-sober day if you do it in one sitting.

That being said, I don't drink, so I don't know for certainly what is culturally acceptable, I'm just going based on observations (lunches and dinners with coworkers and whatnot). However, this seems like it could be used to justify poor behavior, especially for health conscious individuals who like to check off boxes.


A bottle of beer (say 500ml) at 5% strength would be 2.5 units, so not as much as 4 bottles a day [1]. Also worth noting that alcohol you buy in shops in the UK has the number of units printed on the label, so it's fairly easy to keep track of.

[1] https://en.wikipedia.org/wiki/Unit_of_alcohol


A standard bottle of beer is 330ml to 375 ml. 500ml is closer to an imperial pint @ ~17 oz. That's roughly the size of an American "pint"


Here in Europese standard bottle /can sizes are 250, 300/330 and 500ml. The former are more common west of the Rhine, the 500ml is the standard East of it


A unit is 10ml of pure alcohol, roughly half a pint of 4% beer or half a glass of wine. This unit value is printed clearly on pretty much all alcohol containers. (In the US it seems incredibly difficult to find the ABV % for the drinks you buy.)

A bottle of beer is usually 330ml so 1.3 units, so moderate drinking would be defined as up to 2 pints or 3 bottles of 4% beer daily.


I believe ABV is printed on every alcohol label in the US (I suspect there is a regulation mandating it)


While most does, at least the box of Heineken in my fridge (don't judge me, left over from a party!) doesn't have the ABV on the box, though does on the cans inside.


To find the units you multiply the serving size in litres by the number for the ABV.

So, a 250 ml glass of wine at 12% ABV is 0.25 * 12 = 3 units.

In the past when units were created wine was about 8% ABV, and a serving size was about 125 ml, which gives 0.125 * 8 = 1 unit per glass. When you see advice saying "one small glass of wine is about 1 unit" it's a bit misleading, because currently in the UK one small glass is going to be about 175 ml, and the ABV is going to be about 12%, which gives about 2 units per glass.



  -o >(grep O_DIRECT)
This is cool. Never seen it (but it makes sense.)


Its cousin

  diff <(cmd a) <(cmd b)
is also very handy.


It also has a great unofficial name: the penguin operator.

<()

See? Penguin!


Not a command line guru, but this looks interesting. Does it compare outputs of two commands? How does it do it?


It might be easiest to view it like so:

  $ echo <(echo 1) <(echo 2)
  /dev/fd/63 /dev/fd/62
The shell spawns two commands connected to pipes, then replaces those with a file that represents the other (read) side of that pipe.

The command above with >(grep something) does the same thing, just with the other end of a pipe.


It's not actually a pipe. >, < and | are IO redirection commands; but of those only | is a pipe. Pipes specifically "pipe" the STDOUT of one command as the STDIN of another. The other two instead point a command to the file descriptor of the output of another.

This is explained in more detail here:

https://askubuntu.com/questions/172982/what-is-the-differenc...


It is a pipe, just for a different definition of pipe.

| is the pipe operator in sh for doing a shell "pipeline". However, the parent comment is referring to a linux pipe as in pipe(7) [0].

One easy way to see this is with the following:

    $ ls -l <(echo foo)
    lr-x------ 1 user group Jan 12 01:23 /proc/self/fd/16 -> 'pipe:[2937585]'
As you can see, that command created a fd (16) which referred to a pipe (pipe:[2937585]).

Those file descriptors were created using the pipe(2)[1] call by the shell, so it seems fine to refer to them to pipes.

I'll also note that <() / >() are _not_ using the "redirection operator". They're actually distinct operators for "process substitution"[2] in bash terminology. They look similar to redirects, but they're not the same operator, so that stack overflow answer isn't really relevant.

[0]: http://man7.org/linux/man-pages/man7/pipe.7.html

[1]: http://man7.org/linux/man-pages/man2/pipe.2.html

[2]: https://tldp.org/LDP/abs/html/process-sub.html


On POSIX systems, the line between file and pipe doesn’t exist. If you create a named pipe w/ mknod or mkfifo, you would interact with the named pipe as you would a normal file. Or block/character device. Etc.

In case of unnamed pipe the fds just exist as long as the process is running, then it disappears. Point is it’s irrelevant what you refer to as pipe, at the end of the day some file-like object is either written to or read from. And really, that file-like object is actually just a buffer.


The line absolutely exists, it's just behind an abstraction barrier for read(), write(), and close() calls. The creator of a pipe calls pipe() or pipe2(), and holders of the fd can get access to pipe-specific features with fcntl() and ioctl().


On linux at least, these two constructions are effectively identical from the view of the "piped" process.

  # cat <(ls -l /proc/self/fd/)
  total 0
  lrwx------ 1 root root 64 Jan 12 15:02 0 -> /dev/pts/0
  l-wx------ 1 root root 64 Jan 12 15:02 1 -> pipe:[20519634]
  lrwx------ 1 root root 64 Jan 12 15:02 2 -> /dev/pts/0
  lr-x------ 1 root root 64 Jan 12 15:02 3 -> /proc/23611/fd/

  # ls -l /proc/self/fd/ | cat -
  total 0
  lrwx------ 1 root root 64 Jan 12 15:02 0 -> /dev/pts/0
  l-wx------ 1 root root 64 Jan 12 15:02 1 -> pipe:[20518265]
  lrwx------ 1 root root 64 Jan 12 15:02 2 -> /dev/pts/0
  lr-x------ 1 root root 64 Jan 12 15:02 3 -> /proc/23621/fd/


Yes, because “cat” can use either STDIN or a file as input:

https://github.com/coreutils/coreutils/blob/master/src/cat.c...

It’s an intentional design decision.


I think we're probably in agreement, but we're getting caught up on the definition of "piping".

In my case I'm using it to describe the use of a kernel pipe object. In your case, you are using it to describe the higher-level concept of connection from one processes stdout to another process's stdin (or something along those lines).


Repeating shawnz's comment more explicitly: you said that the mechanism used by <() is "not actually a pipe". What is `pipe:[20519634]` doing in the output of `cat <(ls -l /proc/self/fd/)`?

What it looks like is ls having its stdout (fd 1) directed to a pipe.


I think the point is that the directory listing is the same, not that cat supports both syntaxes.


Does anybody know if this can be done in Windows (not WSL)? E.g. is it possible to open a named pipe (?) through its name, and work with it as a sequential file?


This isn’t a Linux thing, it’s a bash thing. The <() syntax isn’t using a named pipe — it is creating an anonymous pipe. But you can replicate the same functions with named pipes.

A quick search says that Windows has support for named pipes as an IPC mechanism [1], but I’ve never used them. But this is a Windows API. I am not aware for any way to do this with plain cmd.exe. You’re not the first to ask though... [2]

[1] https://docs.microsoft.com/en-us/windows/win32/ipc/named-pip...

[2] https://superuser.com/questions/430466/in-windows-can-i-redi...


Are you sure? How does diff know to read from those two pipes?

Even the echo example hints, that the created pipe has a name, and that name is then simply passed as the argument to the command.


> Even the echo example hints, that the created pipe has a name

Well, the echo example shows that the pipe is reified at /dev/fd/63 (or /dev/fd/62 for the other pipe).

That's not a named pipe. It's a file descriptor identified by the integer that defines it, accessed under the /dev/fd listing of all file descriptors.

So, to sort of answer your questions:

> How does diff know to read from those two pipes?

They're two different pipes. Diff takes two arguments. Each argument is one of the pipes.

> (implied) Is there such a thing as an anonymous pipe, in any context?

Not if you consider /dev/fd/id-of-pipe to be a name. The operating system lists them all there. But usually you would use a named pipe if you wanted to be able to know the name, so that you could find it again if you didn't already have a reference to it. If you jammed your finger into my chest, I would be there, and my physical form would block the passage of your finger analogously to how an anonymous pipe nevertheless exists as an entry (two entries?) in /dev/fd. But that wouldn't tell you my name in the conventional sense, even though it would be a valid and unambiguous way to refer to me.


It is called process substitution and specific to Bash (not POSIX shell compliant). The output of the commands in parenthesis will become runtime (file) inputs for the diff command.

More: https://www.gnu.org/software/bash/manual/html_node/Process-S...


It's not specific to bash -- it's in ksh as well. And zsh.

I'm also pretty sure it originated in ksh, not bash.


<(command) is being replaced by a path to a file which contains the output of the command:

  $ ls <(echo A)
  /dev/fd/63

  $ cat <(echo A)
  A
So

  diff <(command1) <(command2)
becomes

  diff /dev/fd/62  /dev/fd/63


The <(foo | bar) syntax evaluates to a file path, e.g.

  $ echo <(echo hi)
  /dev/fd/63
If a program reads from that file path, it gets the output of the command chain.

  $ cat <( (echo foo; echo bar) | grep bar )
  bar
Of course, that's a silly example. But that explains how the diff example works, since it's the same idea: diff just reads from the two "files".

EDIT: Heh, 5 different replies within the same 60 second window.


it does[0] you are redirecting stdout of both of the subprocesses (the things in brackets) to the stdin of the diff command (I think it creates two different input streams, that diff knows how to compare).

[0] http://tldp.org/LDP/abs/html/process-sub.html


Yes. You're directing the STDOUT of each command as a FILE into diff. Diff takes two files, thus the duplication.


diff compares files line by line, here we just redirect the output of cmd1 and cmd2 via <, so they serve as 'proxies' for the file-args diff expects

you might want to read into redirection on the commandline, it's amazingly powerful


If exiting vim is too easy, try the advanced level: exiting "vim -y".


Try Ctrl-o followed by :q!

That should do it. ;)

Ctrl-o moves from INSERT mode to COMMAND mode for one command and so it still works in "easy" mode. I notice that "easy" mode was one of the things that the Nvim guys removed.


Wow, that's an evil mode. Man says it's the "easy" mode.


Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: