Skip to content

Instantly share code, notes, and snippets.

View simurq's full-sized avatar

Victor Quebec simurq

  • Baku, Azerbaijan
  • 09:19 (UTC +04:00)
View GitHub Profile
@simurq
simurq / locked_pairs.c
Last active February 10, 2021 19:56
Function locked_pairs() for CS50
// Lock pairs into the candidate graph in order, without creating cycles
void lock_pairs(void)
{
int i, j, row, win, los, cycle;
for (i = 0; i < pair_count; i++)
{
win = pairs[i].winner;
los = row = pairs[i].loser;
cycle = 0;
@simurq
simurq / set-o-pipefail.txt
Created January 24, 2024 10:19
POPPI Comments: `set -o pipefail`
Changes the behavior of the return code of a pipeline, which is normally the exit status of the last command in the pipe.
With `set -o pipefail`, the return code of a pipeline is the value of the last command that failed, or zero if all commands succeeded.
This maeks it possible to detect and handle errors that occur in any part of the pipe, not just the end.
E.g., suppose we have a script that uses the following pipeline:
$ cat file.txt | grep "foo" | wc -l
This pipeline counts the number of lines in 'file.txt' that contain the word 'foo'. If 'file.txt' does not exist, the `cat` command will
fail and print an error message, but the pipeline will still return zero, because the `wc -l` command succeeds. This means that the
script will not be aware of the failure and will continue as if nothing went wrong.