Skip to content

Commit

Permalink
fix: correct sed chapter sample (#353)
Browse files Browse the repository at this point in the history
* fix: correct the 'sed' chapter sample file

* fix: correct weight to match book

* fix: correct quotes to match book

* fix: correct samples

* fix: update diagrams (#348)

* fix: correct build script (#358)

* fix: correct build script

* fix: build

* fix: build

* fix: restore missing file

* fix: correct the 'sed' chapter sample file
  • Loading branch information
dwmkerr authored Jan 24, 2025
1 parent 891d717 commit 34281d7
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion samples/docs/chapter7.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Advanced Text Manipulation"
slug: advanced-text-manipulation
slug: "advanced-text-manipulation"
weight: 14
---

Expand Down
4 changes: 2 additions & 2 deletions samples/programs/lookup/lookup-v1.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import sys

# Read standard input until there is nothing left to read.
# Read standard input until nothing is left to read.
while True:
# Read a line of input.
word = sys.stdin.readline()

# If the user hits 'Ctrl+D' to end transmission, readline returns an
# If the user presses Ctrl-D to end transmission, readline returns an
# empty string and we can stop reading.
if not word:
break
Expand Down
8 changes: 4 additions & 4 deletions samples/programs/lookup/lookup-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def search_for_word(word):
url = "https://api.dictionaryapi.dev/api/v2/entries/en/{}".format(encoded_word)
command = ["curl", url]

# Run the 'curl' command to retrieve the definition.
# Run the "curl" command to retrieve the definition.
result = subprocess.run(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand All @@ -24,19 +24,19 @@ def search_for_word(word):
# Now try and parse the data.
data = json.loads(result.stdout)

# Grab the first 'meaning' value. If it doesn't exist in the response then
# Grab the first "meaning" value. If it doesn't exist in the response then
# the word was not found.
try:
return data[0]["meanings"][0]["definitions"][0]["definition"]
except KeyError:
return "definition not found!"

# Read standard input until there is nothing left to read.
# Read standard input until nothing is left to read.
while True:
# Read a line of input.
word = sys.stdin.readline()

# If the user hits 'Ctrl+D' to end transmission, readline returns an
# If the user presses Ctrl-D to end transmission, readline returns an
# empty string and we can stop reading.
if not word:
break
Expand Down
10 changes: 5 additions & 5 deletions samples/programs/lookup/lookup-v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def search_for_word(word):
url = "https://api.dictionaryapi.dev/api/v2/entries/en/{}".format(encoded_word)
command = ["curl", url]

# Run the 'curl' command to retrieve the definition.
# Run the "curl" command to retrieve the definition.
result = subprocess.run(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand All @@ -37,7 +37,7 @@ def search_for_word(word):
# Now try and parse the data.
data = json.loads(result.stdout)

# Grab the first 'meaning' value. If it doesn't exist in the response then
# Grab the first "meaning" value. If it doesn't exist in the response then
# the word was not found.
try:
return data[0]["meanings"][0]["definitions"][0]["definition"]
Expand All @@ -51,7 +51,7 @@ def write_definition(word, definition):
# We will separate the word and the definition with a colon and space.
separator = ": "

# If the 'crop' argument is set, use it.
# If the "crop" argument is set, use it.
if args.crop:
output_length = len(word) + len(separator) + len(definition)
if output_length > args.crop:
Expand All @@ -68,12 +68,12 @@ def write_definition(word, definition):
# Write out the word, separator and definition.
print(word + separator + definition)

# Read standard input until there is nothing left to read.
# Read standard input until nothing is left to read.
while True:
# Read a line of input.
word = sys.stdin.readline()

# If the user hits 'Ctrl+D' to end transmission, readline returns an
# If the user presses Ctrl-D to end transmission, readline returns an
# empty string and we can stop reading.
if not word:
break
Expand Down
8 changes: 4 additions & 4 deletions samples/programs/lookup/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def search_for_word(word):
url = "https://api.dictionaryapi.dev/api/v2/entries/en/{}".format(encoded_word)
command = ["curl", url]

# Run the 'curl' command to retrieve the definition.
# Run the "curl" command to retrieve the definition.
result = subprocess.run(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand All @@ -60,7 +60,7 @@ def search_for_word(word):
# Now try and parse the data.
data = json.loads(result.stdout)

# Grab the first 'meaning' value. If it doesn't exist in the response then
# Grab the first "meaning" value. If it doesn't exist in the response then
# the word was not found.
try:
return data[0]["meanings"][0]["definitions"][0]["definition"]
Expand All @@ -74,7 +74,7 @@ def write_definition(word, definition):
# We will separate the word and the definition with a colon and space.
separator = ": "

# If the 'crop' argument is set, use it.
# If the "crop" argument is set, use it.
if args.crop:
output_length = len(word) + len(separator) + len(definition)
if output_length > args.crop:
Expand Down Expand Up @@ -107,7 +107,7 @@ def read_words():

# Process words until we run out of the provided list or end standard input.
for word in read_words():
# If the user hits 'Ctrl+D' to end transmission, readline returns an
# If the user presses Ctrl-D to end transmission, readline returns an
# empty string and we can stop reading.
if not word:
break
Expand Down
2 changes: 1 addition & 1 deletion samples/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fi
# to get the most common commands.
if [[ $shell_binary == "bash" ]]; then
# Store the most commonly used commands.
commands=$(tail "${history_file}" -n ${history_lines} \
commands=$(tail -n ${history_lines}" ${history_file}" \
| sort \
| uniq -c \
| sed 's/^ *//' \
Expand Down
2 changes: 1 addition & 1 deletion samples/scripts/common.v1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
echo "common commands:"

# Show the most commonly used commands.
tail ~/.bash_history -n 1000 | sort | uniq -c | sed 's/^ *//' | sort -n -r | head -n 10
tail -n 1000 ~/.bash_history | sort | uniq -c | sed 's/^ *//' | sort -n -r | head -n 10
2 changes: 1 addition & 1 deletion samples/scripts/common.v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ history_lines=1000 # The number of lines of history to search through
command_count=10 # The number of common commands to show.

# Show the most commonly used commands.
tail ~/.bash_history -n ${history_lines} \
tail -n ${history_lines} ~/.bash_history \
| sort \
| uniq -c \
| sed 's/^ *//' \
Expand Down
4 changes: 2 additions & 2 deletions samples/scripts/common.v3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fi
# to get the most common commands.
if [[ $shell_binary == "bash" ]]; then
# Show the most commonly used commands.
tail "${history_file}" -n ${history_lines} \
tail -n ${history_lines} "${history_file}" \
| sort \
| uniq -c \
| sed 's/^ *//' \
Expand All @@ -33,7 +33,7 @@ elif [[ $shell_binary == "zsh" ]]; then
# Each line in the has some extra information at the beginning, the command
# text only appears after a semi-colon. So extract the text from after the
# semi-colon and then process it just like in the bash example.
tail "${history_file}" -n ${history_lines} \
tail -n ${history_lines} "${history_file}" \
| rev \
| cut -d';' -f1 \
| rev \
Expand Down
4 changes: 2 additions & 2 deletions samples/scripts/common.v4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fi
# to get the most common commands.
if [[ $shell_binary == "bash" ]]; then
# Store the most commonly used commands.
commands=$(tail "${history_file}" -n ${history_lines} \
commands=$(tail -n ${history_lines} "${history_file}" \
| sort \
| uniq -c \
| sed 's/^ *//' \
Expand All @@ -33,7 +33,7 @@ elif [[ $shell_binary == "zsh" ]]; then
# Each line in the has some extra information at the beginning, the command
# text only appears after a semi-colon. So extract the text from after the
# semi-colon and then process it just like in the bash example.
commands=$(tail "${history_file}" -n ${history_lines} \
commands=$(tail -n ${history_lines} "${history_file}" \
| rev \
| cut -d';' -f1 \
| rev \
Expand Down
4 changes: 2 additions & 2 deletions samples/scripts/common.v5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi
# to get the most common commands.
if [[ $shell_binary == "bash" ]]; then
# Store the most commonly used commands.
commands=$(tail "${history_file}" -n ${history_lines} \
commands=$(tail -n ${history_lines} "${history_file}" \
| sort \
| uniq -c \
| sed 's/^ *//' \
Expand All @@ -36,7 +36,7 @@ elif [[ $shell_binary == "zsh" ]]; then
# Each line in the has some extra information at the beginning, the command
# text only appears after a semi-colon. So extract the text from after the
# semi-colon and then process it just like in the bash example.
commands=$(tail "${history_file}" -n ${history_lines} \
commands=$(tail -n ${history_lines} "${history_file}" \
| rev \
| cut -d';' -f1 \
| rev \
Expand Down
2 changes: 1 addition & 1 deletion samples/scripts/showpstree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ "$(uname)" = "Darwin" ]; then
# BSD pstree; show for process -p.
pstree -p $$
else
# GNU pstree; use the long form (-l) show the command line (-a) and the
# GNU pstree; the command line (-a) and the
# details for a specific process (-s).
pstree -a -s $$
fi

0 comments on commit 34281d7

Please sign in to comment.