Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into snippets-c++
Browse files Browse the repository at this point in the history
  • Loading branch information
majvax committed Jan 3, 2025
2 parents d76dbfd + ef1eb88 commit c188670
Show file tree
Hide file tree
Showing 257 changed files with 3,572 additions and 1,939 deletions.
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
18 changes: 13 additions & 5 deletions .github/workflows/check-snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ jobs:
check-snippets:
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16"
node-version: 22

- name: Check if snippets are formated correctly
run: |
node utils/checkSnippetFormatting.js # Run the script located in the utils/ folder
uses: int128/comment-action@v1
with:
run: node utils/checkSnippetFormatting.js # Run the script located in the utils/ folder
post-on-failure: |
## :x: Snippet Format Error
${run.output}
9 changes: 5 additions & 4 deletions .github/workflows/consolidate-snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "16"
node-version: 22

- name: Install dependencies
run: |
Expand All @@ -34,5 +34,6 @@ jobs:
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
git add public/consolidated/*
git commit -m "Update consolidated snippets"
git add public/icons/*
git diff-index --quiet HEAD || git commit -m "Update consolidated snippets"
git push
31 changes: 31 additions & 0 deletions .github/workflows/pre-commit-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Pre-commit checks

on:
pull_request:
branches:
- '**'

jobs:
pre-commit-checks:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22

- name: Install dependencies
run: npm ci

- name: Run cspell
run: npm run cspell

- name: Run lint
run: npm run lint

- name: Run build
run: npm run build
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
npm run cspell
npm run lint
npm run build
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
dist
snippets
public
.vite
coverage
package-lock.json
Expand Down
38 changes: 38 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## QuickSnip Code of Conduct

QuickSnip is a welcoming and collaborative community for developers to organize, share, and discover code snippets. By participating in QuickSnip, you agree to uphold this code of conduct to maintain a friendly and inclusive environment.

### Short Version

- Be respectful to everyone in the community.
- Avoid harassment, trolling, or spamming.
- Ensure QuickSnip remains a safe and productive space for all.
- Report any inappropriate behavior to [me](mailto:[email protected]), the owner of QuickSnip, or our [Discord team](https://discord.gg/UtJJcnsN).
- No unauthorized bots without prior permission.

---

### Long Version

#### Harassment-Free Environment

We are committed to providing a harassment-free experience for everyone, regardless of gender, gender identity and expression, age, sexual orientation, disability, physical appearance, body size, race, ethnicity, national origin, or religion (or lack thereof). Examples of unacceptable behavior include:

- **Harassment:** Includes sexual language or imagery, deliberate intimidation, stalking, name-calling, unwelcome attention, libel, and malicious hacking or social engineering.
- **Trolling:** Posting inflammatory comments to provoke an emotional response or disrupt discussions.
- **Spamming:** Posting off-topic messages, promoting unrelated products, soliciting donations, advertising jobs or gigs, or flooding discussions with files or text.

#### Reporting Issues

If you experience or witness harassment, trolling, spamming, or any other inappropriate behavior, please report it to [me](mailto:[email protected]), the owner of QuickSnip, or our QuickSnip [Discord team](https://discord.gg/UtJJcnsN). Include details like screenshots and URLs, if possible, to help us address the issue effectively.

I, or the QuickSnip team will review all reports and take appropriate actions, which may include warnings, temporary bans, or permanent removal from the community.

#### Respectful Use of Bots

No bots are allowed within the QuickSnip community without prior written permission from the QuickSnip team. Unauthorized bots will be removed.

#### Final Notes

This code of conduct is inspired by [FreeCodeCamp’s approach](https://www.freecodecamp.org/news/code-of-conduct), emphasizing clarity and friendliness. Let’s work together to make QuickSnip a supportive and productive space for all developers!

101 changes: 78 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,76 +18,129 @@ 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:

```md
````md
---
title: Name of the snippet
description: A short explanation of what the snippet does
tags: tag1, tag2, tag3
author: your-github-username
---

```lang
// Your code here
```
````

Here’s an example for JavaScript:

```
````md
---
title: Format Date
description: Formats a date in 'YYYY-MM-DD' format.
author: dostonnabotov
tags: javascript,date,format,utility
tags: javascript,date,format
---

```js
const formatDate = (date) => date.toISOString().split('T')[0];

// Usage:
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.

![snippet code example in markdown file](https://github.com/user-attachments/assets/be650cfe-fd17-49e7-ae82-e1c88e30d4c9)
7. **Test your snippet:**
- Ensure your code runs as expected. \
To test that your snippets are formatted correctly use the `snippets:check` script:
```
$ npm run snippets:check
```
It will return nothing if they are well formatted, otherwise it will tell you what the error is.
6. **Test your snippet:**
- Ensure your code runs as expected.
---
To preview the snippets, you need to consolidate them, use the `snippets:consolidate` script:
```
$ npm run snippets:consolidate
```
It will update the snippets in the `/public` folder, making them available to the frontend.
Expected structure:
Expected file structure:
```txt
snippets
```md
/snippets
|- language
|- category
|- category-name
|- your-snippet-here.md
```

> Please do **NOT** add or edit anything in `/public` folder. It will be used for consolidating snippets.
### Editing a Existing Snippet

If you’d like to refine or improve an existing snippet:
Expand All @@ -96,7 +149,7 @@ If you’d like to refine or improve an existing snippet:

- Include your GitHub username under the `contributors` field in the metadata section.

```md
````md
---
title: Name of the snippet
description: A short explanation of what the snippet does
Expand All @@ -105,8 +158,10 @@ author: original-author
contributors: your-github-username
---

```
Updated code here
```
````

2. **Credit all contributors:**

Expand All @@ -118,9 +173,9 @@ contributors: contributor1, contributor2, your-github-username

3. **Document changes:**

Clearly indicate what you updated and why in your pull request description.
- Clearly indicate what you updated and why in your pull request description.

We want to make sure that original author and contributor(s) are credited for their work.
> We want to make sure that original author and contributor(s) are credited for their work.

### Adding a New Category
Expand All @@ -141,10 +196,10 @@ Example structure:

```md
/snippets
|_ python
|_ file-handling
|_ list-manipulation
|_ ....
|- python
|- file-handling
|- list-manipulation
|- ....
```

### Adding a New Language
Expand Down
Loading

0 comments on commit c188670

Please sign in to comment.