Skip to content

Commit

Permalink
Merge pull request #193 from MinerMinerMods/main
Browse files Browse the repository at this point in the history
Improved Quality of Python Snippets, fixed issue with CONTRIBUTING.md
  • Loading branch information
Mathys-Gasnier authored Jan 7, 2025
2 parents 9181837 + 4a7da2b commit 52e7c9c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 23 additions & 20 deletions public/consolidated/python.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,16 +535,17 @@
"code": "def snake_to_camel(s):\n parts = s.split('_')\n return parts[0] + ''.join(word.capitalize() for word in parts[1:])\n\n# Usage:\nsnake_to_camel('hello_world') # Returns: 'helloWorld'\n"
},
{
"title": "Convert String to ASCII",
"description": "Converts a string into its ASCII representation.",
"title": "Convert String to Unicode",
"description": "Converts a string into its Unicode representation.",
"author": "axorax",
"tags": [
"string",
"ascii",
"unicode",
"convert"
],
"contributors": [],
"code": "def string_to_ascii(s):\n return [ord(char) for char in s]\n\n# Usage:\nstring_to_ascii('hello') # Returns: [104, 101, 108, 108, 111]\n"
"code": "def string_to_unicode(s):\n return [ord(char) for char in s]\n\n# Usage:\nstring_to_unicode('hello') # Returns: [104, 101, 108, 108, 111]\n"
},
{
"title": "Count Character Frequency",
Expand Down Expand Up @@ -626,6 +627,18 @@
"contributors": [],
"code": "import random\nimport string\n\ndef random_string(length):\n letters_and_digits = string.ascii_letters + string.digits\n return ''.join(random.choice(letters_and_digits) for _ in range(length))\n\n# Usage:\nrandom_string(10) # Results: Random 10-character string\n"
},
{
"title": "Remove Characters",
"description": "Removes specific characters from a string.",
"author": "axorax",
"tags": [
"string",
"remove",
"characters"
],
"contributors": [],
"code": "def remove_chars(s, chars):\n return ''.join(c for c in s if c not in chars)\n\n# Usage:\nremove_chars('hello world', 'eo') # Returns: 'hll wrld'\n"
},
{
"title": "Remove Duplicate Characters",
"description": "Removes duplicate characters from a string while maintaining the order.",
Expand All @@ -650,18 +663,6 @@
"contributors": [],
"code": "import string\n\ndef remove_punctuation(s):\n return s.translate(str.maketrans('', '', string.punctuation))\n\n# Usage:\nremove_punctuation('Hello, World!') # Returns: 'Hello World'\n"
},
{
"title": "Remove Specific Characters",
"description": "Removes specific characters from a string.",
"author": "axorax",
"tags": [
"string",
"remove",
"characters"
],
"contributors": [],
"code": "def remove_chars(s, chars):\n return ''.join(c for c in s if c not in chars)\n\n# Usage:\nremove_chars('hello world', 'eo') # Returns: 'hll wrld'\n"
},
{
"title": "Remove Whitespace",
"description": "Removes all whitespace from a string.",
Expand All @@ -683,7 +684,7 @@
"reverse"
],
"contributors": [],
"code": "def reverse_string(s):\n return s[::-1]\n\n# Usage:\nreverse_string('hello') # Returns: 'olleh'\n"
"code": "def reverse_string(s:str) -> str:\n return s[::-1]\n\n# Usage:\nreverse_string('hello') # Returns: 'olleh'\n"
},
{
"title": "Split Camel Case",
Expand All @@ -698,15 +699,17 @@
"code": "import re\n\ndef split_camel_case(s):\n return ' '.join(re.findall(r'[A-Z][a-z]*|[a-z]+', s))\n\n# Usage:\nsplit_camel_case('camelCaseString') # Returns: 'camel Case String'\n"
},
{
"title": "Truncate String",
"description": "Truncates a string to a specified length and adds an ellipsis.",
"title": "Truncate",
"description": "Truncates a string to a specified length and a toggleable truncation notation.",
"author": "axorax",
"tags": [
"string",
"truncate"
],
"contributors": [],
"code": "def truncate_string(s, length):\n return s[:length] + '...' if len(s) > length else s\n\n# Usage:\ntruncate_string('This is a long string', 10) # Returns: 'This is a ...'\n"
"contributors": [
"MinerMinerMods"
],
"code": "def truncate(s:str, length:int, suffix:bool = True) -> str :\n return (s[:length] + (\"...\" if suffix else \"\")) if len(s) > length else s\n\n# Usage:\ntruncate('This is a long string', 10) # Returns: 'This is a ...'\ntruncate('This is a long string', 10, False) # Returns: 'This is a '\n"
}
]
}
Expand Down
14 changes: 0 additions & 14 deletions snippets/python/string-manipulation/convert-string-to-ascii.md

This file was deleted.

14 changes: 14 additions & 0 deletions snippets/python/string-manipulation/convert-string-to-unicode.md
Original file line number Diff line number Diff line change
@@ -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]
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Remove Specific Characters
title: Remove Characters
description: Removes specific characters from a string.
author: axorax
tags: string,remove,characters
Expand Down
2 changes: 1 addition & 1 deletion snippets/python/string-manipulation/reverse-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tags: string,reverse
---

```py
def reverse_string(s):
def reverse_string(s:str) -> str:
return s[::-1]

# Usage:
Expand Down
14 changes: 0 additions & 14 deletions snippets/python/string-manipulation/truncate-string.md

This file was deleted.

16 changes: 16 additions & 0 deletions snippets/python/string-manipulation/truncate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Truncate
description: Truncates a string to a specified length and a toggleable truncation notation.
author: axorax
contributors: MinerMinerMods
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 '
```

0 comments on commit 52e7c9c

Please sign in to comment.