From bb34347736d079632f2aa0fd6f4172ed03c44b01 Mon Sep 17 00:00:00 2001 From: MinerMinerMods <81445535+MinerMinerMods@users.noreply.github.com> Date: Sun, 5 Jan 2025 08:17:05 -0600 Subject: [PATCH 1/8] Renamed and improved python truncate snippet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renamed from `truncate-string.py` to `truncate.py` Replaced "..." with ellipses("…") to only use one character Implemented toggle for the `suffix` "…" on string with default of `True` --- .../python/string-manipulation/truncate-string.md | 14 -------------- snippets/python/string-manipulation/truncate.md | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 snippets/python/string-manipulation/truncate-string.md create mode 100644 snippets/python/string-manipulation/truncate.md diff --git a/snippets/python/string-manipulation/truncate-string.md b/snippets/python/string-manipulation/truncate-string.md deleted file mode 100644 index 9788ac3e..00000000 --- a/snippets/python/string-manipulation/truncate-string.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: Truncate String -description: Truncates a string to a specified length and adds an ellipsis. -author: axorax -tags: string,truncate ---- - -```py -def truncate_string(s, length): - return s[:length] + '...' if len(s) > length else s - -# Usage: -truncate_string('This is a long string', 10) # Returns: 'This is a ...' -``` diff --git a/snippets/python/string-manipulation/truncate.md b/snippets/python/string-manipulation/truncate.md new file mode 100644 index 00000000..53bc84c4 --- /dev/null +++ b/snippets/python/string-manipulation/truncate.md @@ -0,0 +1,15 @@ +--- +title: Truncate String +description: Truncates a string to a specified length and adds a toggleable ellipsis. +author: minerminermain +tags: string,truncate +--- + +```py +def truncate(s:str, length:int, suffix:bool = True) -> str : + return (s[:length] + ("…" if suffix else "")) if len(s) > length else s + +# Usage: +truncate('This is a long string', 10) # Returns: 'This is a …' +truncate('This is a long string', 10, False) # Returns: 'This is a ' +``` From 45d04d353a4eb2802a0b33a59296ed730be8aa09 Mon Sep 17 00:00:00 2001 From: MinerMinerMods <81445535+MinerMinerMods@users.noreply.github.com> Date: Sun, 5 Jan 2025 08:20:54 -0600 Subject: [PATCH 2/8] Update reverse-string.md Added type hints --- snippets/python/string-manipulation/reverse-string.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/python/string-manipulation/reverse-string.md b/snippets/python/string-manipulation/reverse-string.md index fa045607..c5967ae9 100644 --- a/snippets/python/string-manipulation/reverse-string.md +++ b/snippets/python/string-manipulation/reverse-string.md @@ -6,8 +6,8 @@ tags: string,reverse --- ```py -def reverse_string(s): - return s[::-1] +def reverse_string(s:str) -> str: + return s[::-1] # Usage: reverse_string('hello') # Returns: 'olleh' From c3f21fb87828c40640df5d3fa71cb6d7bf6e6401 Mon Sep 17 00:00:00 2001 From: MinerMinerMods <81445535+MinerMinerMods@users.noreply.github.com> Date: Sun, 5 Jan 2025 08:26:31 -0600 Subject: [PATCH 3/8] Renamed `remove-specific-characters.md` to `remove-characters.md` --- .../{remove-specific-characters.md => remove-characters.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename snippets/python/string-manipulation/{remove-specific-characters.md => remove-characters.md} (100%) diff --git a/snippets/python/string-manipulation/remove-specific-characters.md b/snippets/python/string-manipulation/remove-characters.md similarity index 100% rename from snippets/python/string-manipulation/remove-specific-characters.md rename to snippets/python/string-manipulation/remove-characters.md From 6945396426ccf620992db2305696eeafc7d1bc20 Mon Sep 17 00:00:00 2001 From: MinerMinerMods <81445535+MinerMinerMods@users.noreply.github.com> Date: Sun, 5 Jan 2025 09:53:56 -0600 Subject: [PATCH 4/8] Improved accuracy of Description for `convert-string-to-ascii` for better functional representation Renamed `convert-string-to-ascii.md` to `convert-string-to-unicode.md` Replaced ASCII with Unicode Kept `ascii` tag as it is a subset of unicode and to minimize search errors Fixed issue https://github.com/dostonnabotov/quicksnip/issues/192 --- .../string-manipulation/convert-string-to-ascii.md | 14 -------------- .../convert-string-to-unicode.md | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 snippets/python/string-manipulation/convert-string-to-ascii.md create mode 100644 snippets/python/string-manipulation/convert-string-to-unicode.md diff --git a/snippets/python/string-manipulation/convert-string-to-ascii.md b/snippets/python/string-manipulation/convert-string-to-ascii.md deleted file mode 100644 index 61e830ba..00000000 --- a/snippets/python/string-manipulation/convert-string-to-ascii.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: Convert String to ASCII -description: Converts a string into its ASCII representation. -author: axorax -tags: string,ascii,convert ---- - -```py -def string_to_ascii(s): - return [ord(char) for char in s] - -# Usage: -string_to_ascii('hello') # Returns: [104, 101, 108, 108, 111] -``` diff --git a/snippets/python/string-manipulation/convert-string-to-unicode.md b/snippets/python/string-manipulation/convert-string-to-unicode.md new file mode 100644 index 00000000..28d3f676 --- /dev/null +++ b/snippets/python/string-manipulation/convert-string-to-unicode.md @@ -0,0 +1,14 @@ +--- +title: Convert String to Unicode +description: Converts a string into its Unicode representation. +author: axorax +tags: string,ascii,unicode,convert +--- + +```py +def string_to_unicode(s): + return [ord(char) for char in s] + +# Usage: +string_to_unicode('hello') # Returns: [104, 101, 108, 108, 111] +``` From cc4d448230e7a725c6789a2d936bdba9914889dc Mon Sep 17 00:00:00 2001 From: MinerMinerMods <81445535+MinerMinerMods@users.noreply.github.com> Date: Sun, 5 Jan 2025 10:07:42 -0600 Subject: [PATCH 5/8] Update CONTRIBUTING.md Added a `not` on line 68 in "Does that snippet have a real, and practical use case ?" to prevent useless snippets from being acceptable and useful snippets from being denied. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2ad95510..256798c8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,7 @@ If your function doesn't return anything just show how to use it. If the result To ensure your snippet isn’t refused, consider these questions: - **Does the standard library of my language provide an easy way of doing this ?** -- **Does that snippet have a real, and practical use case ?** +- **Does that snippet not have a real, and practical use case ?** - **Could it be split into separate parts to be better understood ?** If any answer is yes, then your snippet will most likely get rejected. From 1ee65c606084855c2e253712dc95033f187b60b8 Mon Sep 17 00:00:00 2001 From: MinerMinerMods <81445535+MinerMinerMods@users.noreply.github.com> Date: Sun, 5 Jan 2025 10:19:18 -0600 Subject: [PATCH 6/8] Rectified loss of attribution recovered old attribution in the python snippet`truncate` to axorax and added the contributors tag. --- snippets/python/string-manipulation/truncate.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snippets/python/string-manipulation/truncate.md b/snippets/python/string-manipulation/truncate.md index 53bc84c4..f5d1e765 100644 --- a/snippets/python/string-manipulation/truncate.md +++ b/snippets/python/string-manipulation/truncate.md @@ -1,7 +1,8 @@ --- title: Truncate String description: Truncates a string to a specified length and adds a toggleable ellipsis. -author: minerminermain +author: axorax +contributors: MinerMinerMods tags: string,truncate --- From 12c74a2f35260e1fc9884c394f606fe88a0830b8 Mon Sep 17 00:00:00 2001 From: MinerMinerMods <81445535+MinerMinerMods@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:35:24 -0600 Subject: [PATCH 7/8] truncate.md reconformed to PEP 8 removed Tab --- snippets/python/string-manipulation/truncate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/python/string-manipulation/truncate.md b/snippets/python/string-manipulation/truncate.md index f5d1e765..9fc4a875 100644 --- a/snippets/python/string-manipulation/truncate.md +++ b/snippets/python/string-manipulation/truncate.md @@ -8,7 +8,7 @@ tags: string,truncate ```py def truncate(s:str, length:int, suffix:bool = True) -> str : - return (s[:length] + ("…" if suffix else "")) if len(s) > length else s + return (s[:length] + ("…" if suffix else "")) if len(s) > length else s # Usage: truncate('This is a long string', 10) # Returns: 'This is a …' From becd0db9237e546b833afc84c49e23471accdd11 Mon Sep 17 00:00:00 2001 From: MinerMinerMods <81445535+MinerMinerMods@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:40:50 -0600 Subject: [PATCH 8/8] Update truncate.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced "…" with "..." Updated Description to match --- snippets/python/string-manipulation/truncate.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/python/string-manipulation/truncate.md b/snippets/python/string-manipulation/truncate.md index 9fc4a875..8f016cdd 100644 --- a/snippets/python/string-manipulation/truncate.md +++ b/snippets/python/string-manipulation/truncate.md @@ -1,6 +1,6 @@ --- title: Truncate String -description: Truncates a string to a specified length and adds a toggleable ellipsis. +description: Truncates a string to a specified length and a toggleable truncation notation. author: axorax contributors: MinerMinerMods tags: string,truncate @@ -8,9 +8,9 @@ tags: string,truncate ```py def truncate(s:str, length:int, suffix:bool = True) -> str : - return (s[:length] + ("…" if suffix else "")) if len(s) > length else s + return (s[:length] + ("..." if suffix else "")) if len(s) > length else s # Usage: -truncate('This is a long string', 10) # Returns: 'This is a …' +truncate('This is a long string', 10) # Returns: 'This is a ...' truncate('This is a long string', 10, False) # Returns: 'This is a ' ```