Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ef1eb88

Browse files
Merge pull request #144 from Mathys-Gasnier/main
New guidelines for snippets
2 parents ef24250 + dc0ee70 commit ef1eb88

File tree

232 files changed

+759
-1883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+759
-1883
lines changed

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
text eol=lf

‎.github/pull_request_template.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
<!-- **ANY PULL REQUEST NOT FOLLOWING GUIDELINES OR NOT INCLUDING A DESCRIPTION WILL BE CLOSED !** -->
2+
13
# Description
24

3-
<!-- Please include a summary of your changes. -->
5+
<!-- Include a summary of your changes. -->
46

57
## Type of Change
68

‎CONTRIBUTING.md‎

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,65 @@ If you have a feature request or want to fix a bug, feel free to:
1818

1919
---
2020

21+
## Snippets Guidelines
22+
23+
### Snippet Tags
24+
25+
Tags must describe the snippet with simple word. \
26+
For example a snippet that capitalize a word would have `string` and `capitalize` as tags. \
27+
**! Do not add the language you are using as a tag, nor some generic keyword like `utility` !**
28+
29+
### Snippet Format
30+
31+
**All** snippets should follow the following structure:
32+
- A `code` segment, containing a function with the actual snippet functionnality
33+
- An `example` segement, containing one or more examples of use
34+
35+
Example in javascript:
36+
```js
37+
function example(x) {
38+
return x * 2;
39+
}
40+
41+
// Usage:
42+
example(5) // Returns: 10
43+
```
44+
If your function doesn't return anything just show how to use it. \
45+
If the result of your function is too complicated to be expressed in a single comment, your snippet is probably too complex to begin with.
46+
47+
### Snippet boundaries
48+
49+
To **check if your snippet will not get refused** ask yourself those questions:
50+
- **Does the standard library of my language provide an easy way of doing this ?**
51+
- **Does that snippet have a real, and practical use case ?**
52+
- **Could it be split into separate parts to be better understood ?**
53+
54+
If one of question is true, then your snippet will most likely get refused !
55+
56+
---
57+
2158
## Adding Snippets
2259

2360
### Adding a New Snippet
2461

25-
To add a new code snippet:
62+
1.**Ensure your snippet match [guidelines](#snippets-guidelines)**
2663

27-
1. **Navigate to the relevant folder:**
64+
2. **Navigate to the relevant folder:**
2865

2966
- Go to the `/snippets` folder in the root directory.
3067
- Locate the folder for the programming language of your snippet, such as `javascript` or `python`.
3168

32-
2. **Choose the correct category:**
69+
3. **Choose the correct category:**
3370

3471
- Within the language folder, find the relevant category folder for your snippet.
3572
- If no suitable category exists, refer to [Adding a New Category](#adding-a-new-category).
3673

37-
3. **Create a markdown file:**
74+
4. **Create a markdown file:**
3875

3976
- Create a new file with a `.md` extension.
4077
- Name the file appropriately, keeping it descriptive and concise.
4178

42-
4. **Add your snippet:**
79+
5. **Add your snippet:**
4380

4481
- Use the following format to structure your snippet:
4582

@@ -74,11 +111,11 @@ console.log(formatDate(new Date())); // Output: '2024年12月10日'
74111
```
75112
````
76113

77-
5. **Use syntax highlighting:**
114+
6. **Use syntax highlighting:**
78115
- Enclose your code with triple backticks (```).
79116
- Specify the language after the first set of backticks for syntax highlighting.
80117

81-
6. **Test your snippet:**
118+
7. **Test your snippet:**
82119
- Ensure your code runs as expected. \
83120
To test that your snippets are formatted correctly use the `snippets:check` script:
84121
```

‎cspell-dict.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
quicksnip
2+
slugifyed

‎public/consolidated/c.json‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
"description": "Prints Hello, World! to the terminal.",
88
"author": "0xHouss",
99
"tags": [
10-
"c",
1110
"printing",
12-
"hello-world",
13-
"utility"
11+
"hello-world"
1412
],
1513
"contributors": [],
1614
"code": "#include <stdio.h> // Includes the input/output library\n\nint main() { // Defines the main function\n printf(\"Hello, World!\\n\") // Outputs Hello, World! and a newline\n\n return 0; // indicate the program executed successfully\n}\n"
@@ -25,26 +23,11 @@
2523
"description": "Calculates the factorial of a number.",
2624
"author": "0xHouss",
2725
"tags": [
28-
"c",
2926
"math",
30-
"factorial",
31-
"utility"
27+
"factorial"
3228
],
3329
"contributors": [],
34-
"code": "int factorial(int x) {\n int y = 1;\n\n for (int i = 2; i <= x; i++)\n y *= i;\n\n return y;\n}\n"
35-
},
36-
{
37-
"title": "Power Function",
38-
"description": "Calculates the power of a number.",
39-
"author": "0xHouss",
40-
"tags": [
41-
"c",
42-
"math",
43-
"power",
44-
"utility"
45-
],
46-
"contributors": [],
47-
"code": "int power(int x, int n) {\n int y = 1;\n\n for (int i = 0; i < n; i++)\n y *= x;\n\n return y;\n}\n"
30+
"code": "int factorial(int x) {\n int y = 1;\n\n for (int i = 2; i <= x; i++)\n y *= i;\n\n return y;\n}\n\n// Usage:\nfactorial(4); // Returns: 24\n"
4831
}
4932
]
5033
}

‎public/consolidated/cpp.json‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
"description": "Prints Hello, World! to the terminal.",
88
"author": "James-Beans",
99
"tags": [
10-
"cpp",
1110
"printing",
12-
"hello-world",
13-
"utility"
11+
"hello-world"
1412
],
1513
"contributors": [],
1614
"code": "#include <iostream> // Includes the input/output stream library\n\nint main() { // Defines the main function\n std::cout << \"Hello, World!\" << std::endl; // Outputs Hello, World! and a newline\n return 0; // indicate the program executed successfully\n}\n"
@@ -25,13 +23,12 @@
2523
"description": "Convert vector into queue quickly",
2624
"author": "mrityunjay2003",
2725
"tags": [
28-
"cpp",
2926
"data structures",
3027
"queue",
3128
"vector"
3229
],
3330
"contributors": [],
34-
"code": "#include<queue>\n#include<vector>\n#include<deque>\n\nstd::queue<int> vectorToQueue(const std::vector<int>& v) {\n return std::queue<int>(std::deque<int>(v.begin(), v.end()));\n}\n"
31+
"code": "#include<queue>\n#include<vector>\n#include<deque>\n\nstd::queue<int> vectorToQueue(const std::vector<int>& v) {\n return std::queue<int>(std::deque<int>(v.begin(), v.end()));\n}\n\nstd::vector<int> vec = { 1, 2, 3, 4, 5 };\nvectorToQueue(&vec); // Returns: std::queue<int> { 1, 2, 3, 4, 5 }\n"
3532
}
3633
]
3734
},
@@ -43,12 +40,11 @@
4340
"description": "Check if an integer is a prime number",
4441
"author": "MihneaMoso",
4542
"tags": [
46-
"cpp",
4743
"number",
4844
"prime"
4945
],
5046
"contributors": [],
51-
"code": "bool is_prime(int n) {\n if (n < 2) return false;\n if (n == 2 || n == 3) return true;\n if (n % 2 == 0) return false;\n for (int i = 3; i * i <= n; i += 2) {\n if (n % i == 0) return false;\n }\n return true;\n}\n\n// Usage\n#include <iostream>\n\nint main() {\n std::cout << is_prime(29) << std::endl; // Output: 1\n return 0;\n}\n"
47+
"code": "bool is_prime(int n) {\n if (n < 2) return false;\n if (n == 2 || n == 3) return true;\n if (n % 2 == 0) return false;\n for (int i = 3; i * i <= n; i += 2) {\n if (n % i == 0) return false;\n }\n return true;\n}\n\n// Usage:\nis_prime(29); // Returns: true\n"
5248
}
5349
]
5450
},
@@ -60,26 +56,22 @@
6056
"description": "Reverses the characters in a string.",
6157
"author": "Vaibhav-kesarwani",
6258
"tags": [
63-
"cpp",
6459
"array",
65-
"reverse",
66-
"utility"
60+
"reverse"
6761
],
6862
"contributors": [],
69-
"code": "#include <string>\n#include <algorithm>\n\nstd::string reverseString(const std::string& input) {\n std::string reversed = input;\n std::reverse(reversed.begin(), reversed.end());\n return reversed;\n}\n"
63+
"code": "#include <string>\n#include <algorithm>\n\nstd::string reverseString(const std::string& input) {\n std::string reversed = input;\n std::reverse(reversed.begin(), reversed.end());\n return reversed;\n}\n\nreverseString(\"quicksnip\"); // Returns: \"pinskciuq\"\n"
7064
},
7165
{
7266
"title": "Split String",
7367
"description": "Splits a string by a delimiter",
7468
"author": "saminjay",
7569
"tags": [
76-
"cpp",
7770
"string",
78-
"split",
79-
"utility"
71+
"split"
8072
],
8173
"contributors": [],
82-
"code": "#include <string>\n#include <vector>\n\nstd::vector<std::string> split_string(std::string str, std::string delim) {\n std::vector<std::string> splits;\n int i = 0, j;\n int inc = delim.length();\n while (j != std::string::npos) {\n j = str.find(delim, i);\n splits.push_back(str.substr(i, j - i));\n i = j + inc;\n }\n return splits;\n}\n"
74+
"code": "#include <string>\n#include <vector>\n\nstd::vector<std::string> split_string(std::string str, std::string delim) {\n std::vector<std::string> splits;\n int i = 0, j;\n int inc = delim.length();\n while (j != std::string::npos) {\n j = str.find(delim, i);\n splits.push_back(str.substr(i, j - i));\n i = j + inc;\n }\n return splits;\n}\n\n// Usage:\nsplit_string(\"quick_-snip\", \"_-\"); // Returns: std::vector<std::string> { \"quick\", \"snip\" }\n"
8375
}
8476
]
8577
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /