-
-
Notifications
You must be signed in to change notification settings - Fork 632
Add new project: base64 encode decode #4523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0843ab8
bcd46d4
5374365
b09ee58
84a2191
1dc7df3
696e78c
989a9a8
2209163
00e58b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import base64 | ||
| import binascii | ||
| import sys | ||
| from typing import NoReturn | ||
|
|
||
|
|
||
| def usage() -> NoReturn: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have never actually seen this before. Is this because the function exits no matter what, so it has no chance to return
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
| print("Usage: please provide a mode and a string to encode/decode") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def base64_encode(s: str) -> str: | ||
| return base64.b64encode(s.encode("ascii")).decode("ascii") | ||
|
|
||
|
|
||
| def base64_decode(s: str) -> str: | ||
| return base64.b64decode(s.encode("ascii")).decode("ascii") | ||
|
|
||
|
|
||
| def main() -> None | NoReturn: | ||
| if len(sys.argv) < 3 or not sys.argv[2]: | ||
| usage() | ||
|
|
||
| mode = sys.argv[1] | ||
| s = sys.argv[2] | ||
| if mode == "encode": | ||
| result = base64_encode(s) | ||
| elif mode == "decode": | ||
| try: | ||
| result = base64_decode(s) | ||
| except binascii.Error: | ||
| usage() | ||
| else: | ||
| usage() | ||
|
|
||
| print(result) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
|
|
||
|
|
||
| def is_prime(x): | ||
| if (x % 2 == 0 and x is not 2) or (x == 1): | ||
| if (x % 2 == 0 and x != 2) or (x == 1): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch |
||
| return False | ||
| return not bool([n for n in range(3, int(ceil(sqrt(x))+1)) if x % n == 0]) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,5 @@ folder: | |
|
|
||
| container: | ||
| image: "python" | ||
| tag: "3.7-alpine" | ||
| tag: "3.12-alpine" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a wonderfully good jump! |
||
| cmd: "python {{ source.name }}{{ source.extension }}" | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am so thankful we moved to a config file format for the tests. I will say: I deleted my twitter account for good, and part of the reason was that tech bros constantly post rage bait. I recently saw multiple people claiming YAML is a terrible config file format, and I just don't really get it. There really was one guy going on this huge crusade about it not being typesafe, and that a turing-complete language is better for configurations. In my mind, I was thinking: wasn't
setup.pyone of the most painful files to setup for a project? I'll stick to my simple YAML, JSON, TOML files.I will say the folks I've seen complaining about YAML use it in K8s, and I guess that can be annoying. I also find the GitHub Actions use of YAML to be a bit finicky. Anyway, thanks for reading my late night thoughts 😆