-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pythonifying the bash binaries (which should hopefully give a perform…
…ance boost
- Loading branch information
1 parent
eb4dfee
commit ffbbaef
Showing
6 changed files
with
55 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env python3.9 | ||
|
||
# Command line utility tool for processing input from stdin. Each line on the | ||
# input stream is base64 decoded. | ||
""" | ||
Command line utility tool for processing input from stdin. Each line on the | ||
input stream is base64 decoded. | ||
""" | ||
|
||
set -euo pipefail | ||
import sys | ||
from base64 import b64decode | ||
|
||
while read -r line | ||
do | ||
echo "$line" | base64 --decode | ||
done | ||
for line in sys.stdin: | ||
sys.stdout.write(b64decode(line.encode()).decode()) | ||
sys.stdout.flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env python3.9 | ||
|
||
# Command line utility tool for processing input from stdin. Each line on the | ||
# input stream is base64 encoded with no wrapping and ended with a newline. | ||
""" | ||
Command line utility tool for processing input from stdin. Each line on the | ||
input stream is base64 encoded with no wrapping and ended with a newline. | ||
""" | ||
|
||
set -euo pipefail | ||
import sys | ||
from base64 import b64encode | ||
|
||
while read -r line | ||
do | ||
echo "$line" | base64 --wrap=0; echo | ||
done | ||
for line in sys.stdin: | ||
sys.stdout.write(b64encode(line.encode()).decode() + "\n") | ||
sys.stdout.flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env python3.9 | ||
|
||
# Command line utility tool for processing input from stdin. Each line on the | ||
# input stream is prepended with the current timestamp in iso 8601 format according | ||
# to the RFC3339 subset. | ||
""" | ||
Command line utility tool for processing input from stdin. Each line on the | ||
input stream is prepended with the current timestamp in iso 8601 format according | ||
to the RFC3339 subset. | ||
""" | ||
|
||
set -euo pipefail | ||
import sys | ||
from datetime import datetime, timezone | ||
|
||
while read -r line | ||
do | ||
echo "$(date -u --rfc-3339=ns) $line" | ||
done | ||
for line in sys.stdin: | ||
sys.stdout.write(f"{datetime.now(timezone.utc).isoformat()} {line}") | ||
sys.stdout.flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env python3.9 | ||
|
||
# Command line utility tool for processing input from stdin. Each line on the | ||
# input stream is put in a separate brefv envelope (compact JSON output) with | ||
# the current timestamp in iso 8601 format according to the RFC3339 subset. | ||
""" | ||
Command line utility tool for processing input from stdin. Each line on the | ||
input stream is put in a separate brefv envelope (compact JSON output) with | ||
the current timestamp in iso 8601 format according to the RFC3339 subset. | ||
""" | ||
|
||
set -euo pipefail | ||
import sys | ||
import json | ||
from datetime import datetime, timezone | ||
|
||
while read -r payload | ||
do | ||
jo sent_at="$(date --rfc-3339=ns)" message="$payload" | ||
done | ||
for line in sys.stdin: | ||
output = json.dumps( | ||
{"sent_at": datetime.now(timezone.utc).isoformat(), "message": line.strip()} | ||
) | ||
sys.stdout.write(output + "\n") | ||
sys.stdout.flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters