Skip to content

New guidelines for snippets #144

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

Merged
merged 10 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text eol=lf
4 changes: 3 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!-- **ANY PULL REQUEST NOT FOLLOWING GUIDELINES OR NOT INCLUDING A DESCRIPTION WILL BE CLOSED !** -->

# Description

<!-- Please include a summary of your changes. -->
<!-- Include a summary of your changes. -->

## Type of Change

Expand Down
51 changes: 44 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,65 @@ If you have a feature request or want to fix a bug, feel free to:

---

## Snippets Guidelines

### Snippet Tags

Tags must describe the snippet with simple word. \
For example a snippet that capitalize a word would have `string` and `capitalize` as tags. \
**! Do not add the language you are using as a tag, nor some generic keyword like `utility` !**

### Snippet Format

**All** snippets should follow the following structure:
- A `code` segment, containing a function with the actual snippet functionnality
- An `example` segement, containing one or more examples of use

Example in javascript:
```js
function example(x) {
return x * 2;
}

// Usage:
example(5) // Returns: 10
```
If your function doesn't return anything just show how to use it. \
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.

### Snippet boundaries

To **check if your snippet will not get refused** ask yourself those 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 ?**
- **Could it be split into separate parts to be better understood ?**

If one of question is true, then your snippet will most likely get refused !

---

## Adding Snippets

### Adding a New Snippet

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

1. **Navigate to the relevant folder:**
2. **Navigate to the relevant folder:**

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

2. **Choose the correct category:**
3. **Choose the correct category:**

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

3. **Create a markdown file:**
4. **Create a markdown file:**

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

4. **Add your snippet:**
5. **Add your snippet:**

- Use the following format to structure your snippet:

Expand Down Expand Up @@ -74,11 +111,11 @@ console.log(formatDate(new Date())); // Output: '2024-12-10'
```
````

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

6. **Test your snippet:**
7. **Test your snippet:**
- Ensure your code runs as expected. \
To test that your snippets are formatted correctly use the `snippets:check` script:
```
Expand Down
1 change: 1 addition & 0 deletions cspell-dict.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
quicksnip
slugifyed
23 changes: 3 additions & 20 deletions public/consolidated/c.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"description": "Prints Hello, World! to the terminal.",
"author": "0xHouss",
"tags": [
"c",
"printing",
"hello-world",
"utility"
"hello-world"
],
"contributors": [],
"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"
Expand All @@ -25,26 +23,11 @@
"description": "Calculates the factorial of a number.",
"author": "0xHouss",
"tags": [
"c",
"math",
"factorial",
"utility"
"factorial"
],
"contributors": [],
"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"
},
{
"title": "Power Function",
"description": "Calculates the power of a number.",
"author": "0xHouss",
"tags": [
"c",
"math",
"power",
"utility"
],
"contributors": [],
"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"
"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"
}
]
}
Expand Down
22 changes: 7 additions & 15 deletions public/consolidated/cpp.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"description": "Prints Hello, World! to the terminal.",
"author": "James-Beans",
"tags": [
"cpp",
"printing",
"hello-world",
"utility"
"hello-world"
],
"contributors": [],
"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"
Expand All @@ -25,13 +23,12 @@
"description": "Convert vector into queue quickly",
"author": "mrityunjay2003",
"tags": [
"cpp",
"data structures",
"queue",
"vector"
],
"contributors": [],
"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"
"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"
}
]
},
Expand All @@ -43,12 +40,11 @@
"description": "Check if an integer is a prime number",
"author": "MihneaMoso",
"tags": [
"cpp",
"number",
"prime"
],
"contributors": [],
"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"
"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"
}
]
},
Expand All @@ -60,26 +56,22 @@
"description": "Reverses the characters in a string.",
"author": "Vaibhav-kesarwani",
"tags": [
"cpp",
"array",
"reverse",
"utility"
"reverse"
],
"contributors": [],
"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"
"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"
},
{
"title": "Split String",
"description": "Splits a string by a delimiter",
"author": "saminjay",
"tags": [
"cpp",
"string",
"split",
"utility"
"split"
],
"contributors": [],
"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"
"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"
}
]
}
Expand Down
Loading