Skip to content

Commit 0f9342c

Browse files
committed
Merge branch 'main' into feature/spellcheck
2 parents d4a7d5f + 750abfe commit 0f9342c

Some content is hidden

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

58 files changed

+1480
-44
lines changed

.github/workflows/consolidate-snippets.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ jobs:
3434
git config --global user.name "GitHub Action"
3535
git config --global user.email "[email protected]"
3636
git add public/consolidated/*
37+
git add public/icons/*
3738
git commit -m "Update consolidated snippets"
3839
git push

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
node_modules
22
dist
3+
snippets
4+
public
35
.vite
46
coverage
57
package-lock.json

CONTRIBUTING.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ Expected file structure:
8585

8686
```md
8787
/snippets
88-
|- language
89-
|- category-name
90-
|- your-snippet-here.md
88+
|- language
89+
|- category-name
90+
|- your-snippet-here.md
9191
```
9292

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

9597
If you’d like to refine or improve an existing snippet:
@@ -122,9 +124,9 @@ contributors: contributor1, contributor2, your-github-username
122124

123125
3. **Document changes:**
124126

125-
Clearly indicate what you updated and why in your pull request description.
127+
- Clearly indicate what you updated and why in your pull request description.
126128

127-
We want to make sure that original author and contributor(s) are credited for their work.
129+
> We want to make sure that original author and contributor(s) are credited for their work.
128130
129131

130132
### Adding a New Category
@@ -145,10 +147,10 @@ Example structure:
145147

146148
```md
147149
/snippets
148-
|- python
149-
|- file-handling
150-
|- list-manipulation
151-
|- ....
150+
|- python
151+
|- file-handling
152+
|- list-manipulation
153+
|- ....
152154
```
153155

154156
### Adding a New Language

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ Expected file structure:
7373

7474
```md
7575
/snippets
76-
|- language
77-
|- category-name
78-
|- your-snippet-here.md
76+
|- language
77+
|- category-name
78+
|- your-snippet-here.md
7979
```
8080

81+
> Please do **NOT** add or edit anything in `/public` folder. It will be used for consolidating snippets.
82+
8183
For more details about adding new categories or programming languages, check out the [CONTRIBUTING.md](/CONTRIBUTING.md) file.
8284

8385
## Guidelines for Contributions

package-lock.json

Lines changed: 38 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"cspell": "cspell --config cspell.json \"**/*.{ts,tsx,js,jsx,json,html}\""
1515
},
1616
"dependencies": {
17+
"framer-motion": "^11.15.0",
1718
"prismjs": "^1.29.0",
1819
"react": "^18.3.1",
1920
"react-dom": "^18.3.1",

public/consolidated/_index.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
"lang": "CPP",
88
"icon": "/icons/cpp.svg"
99
},
10+
{
11+
"lang": "CSHARP",
12+
"icon": "/icons/csharp.svg"
13+
},
1014
{
1115
"lang": "CSS",
1216
"icon": "/icons/css.svg"
1317
},
18+
{
19+
"lang": "HASKELL",
20+
"icon": "/icons/haskell.svg"
21+
},
1422
{
1523
"lang": "HTML",
1624
"icon": "/icons/html.svg"

public/consolidated/cpp.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@
1717
}
1818
]
1919
},
20+
{
21+
"categoryName": "Data Structure Conversion",
22+
"snippets": [
23+
{
24+
"title": "Vector to Queue",
25+
"description": "Convert vector into queue quickly",
26+
"author": "mrityunjay2003",
27+
"tags": [
28+
"cpp",
29+
"data structures",
30+
"queue",
31+
"vector"
32+
],
33+
"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"
35+
}
36+
]
37+
},
38+
{
39+
"categoryName": "Math And Numbers",
40+
"snippets": [
41+
{
42+
"title": "Check Prime Number",
43+
"description": "Check if an integer is a prime number",
44+
"author": "MihneaMoso",
45+
"tags": [
46+
"cpp",
47+
"number",
48+
"prime"
49+
],
50+
"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"
52+
}
53+
]
54+
},
2055
{
2156
"categoryName": "String Manipulation",
2257
"snippets": [

public/consolidated/csharp.json

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
[
2+
{
3+
"categoryName": "Basics",
4+
"snippets": [
5+
{
6+
"title": "Hello, World!",
7+
"description": "Prints Hello, World! to the terminal.",
8+
"author": "chaitanya-jvnm",
9+
"tags": [
10+
"c#",
11+
"printing",
12+
"hello-world",
13+
"utility"
14+
],
15+
"contributors": [],
16+
"code": "public class Program {\n public static void Main(string[] args) {\n System.Console.WriteLine(\"Hello, World!\");\n }\n}\n"
17+
}
18+
]
19+
},
20+
{
21+
"categoryName": "Guid Utilities",
22+
"snippets": [
23+
{
24+
"title": "Generate GUID",
25+
"description": "Generates a new GUID",
26+
"author": "chaitanya-jvnm",
27+
"tags": [
28+
"c#",
29+
"guid",
30+
"generate",
31+
"utility"
32+
],
33+
"contributors": [],
34+
"code": "public static string GenerateGuid() {\n return Guid.NewGuid().ToString();\n}\n"
35+
},
36+
{
37+
"title": "Validate GUID",
38+
"description": "Checks if a string is a valid GUID.",
39+
"author": "chaitanya-jvnm",
40+
"tags": [
41+
"c#",
42+
"guid",
43+
"validate",
44+
"utility"
45+
],
46+
"contributors": [],
47+
"code": "public static bool IsGuid(string str) {\n return Guid.TryParse(str, out _);\n}\n"
48+
}
49+
]
50+
},
51+
{
52+
"categoryName": "Jwt Utilities",
53+
"snippets": [
54+
{
55+
"title": "Decode JWT",
56+
"description": "Decodes a JWT.",
57+
"author": "chaitanya-jvnm",
58+
"tags": [
59+
"c#",
60+
"jwt",
61+
"decode",
62+
"utility"
63+
],
64+
"contributors": [],
65+
"code": "/// <summary>\n/// Decodes the JWT\n/// <summary>\npublic static string DecodeJwt(string token) {\n return new JwtSecurityTokenHandler().ReadJwtToken(token).ToString();\n}\n\n//Example\nstring token = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\";\n\nstring decodedJwt = DecodeJwt(token);\n\nConsole.WriteLine(decodedJwt); //Prints {\"alg\":\"HS256\",\"typ\":\"JWT\"}.{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}\n"
66+
},
67+
{
68+
"title": "Generate JWT",
69+
"description": "Generates a new JWT.",
70+
"author": "chaitanya-jvnm",
71+
"tags": [
72+
"c#",
73+
"jwt",
74+
"generate",
75+
"utility"
76+
],
77+
"contributors": [],
78+
"code": "public static string GenerateJwt(string secret, string issuer, string audience, int expirationMinutes) {\n var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secret));\n var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);\n var token = new JwtSecurityToken(issuer, audience, null, expires: DateTime.UtcNow.AddMinutes(expirationMinutes), signingCredentials: credentials);\n return new JwtSecurityTokenHandler().WriteToken(token);\n}\n"
79+
},
80+
{
81+
"title": "Validate JWT",
82+
"description": "Validates a JWT.",
83+
"author": "chaitanya-jvnm",
84+
"tags": [
85+
"c#",
86+
"jwt",
87+
"validate",
88+
"utility"
89+
],
90+
"contributors": [],
91+
"code": "public static bool ValidateJwt(string token, string secret) {\n var tokenHandler = new JwtSecurityTokenHandler();\n var validationParameters = new TokenValidationParameters {\n ValidateIssuerSigningKey = true,\n IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secret)),\n ValidateIssuer = false,\n ValidateAudience = false\n };\n try {\n tokenHandler.ValidateToken(token, validationParameters, out _);\n return true;\n }\n catch {\n return false\n }\n}\n\n//Example\nstring JWT = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\";\n\nstring correctSecret = \"your-256-bit-secret\";\nstring wrongSecret = \"this-is-not-the-right-secret\";\n\nConsole.WriteLine(ValidateJwt(JWT, correctSecret)) // returns True\nConsole.WriteLine(ValidateJwt(JWT, wrongSecret)) // returns False\n\n"
92+
}
93+
]
94+
},
95+
{
96+
"categoryName": "List Utilities",
97+
"snippets": [
98+
{
99+
"title": "Swap two items at determined indexes",
100+
"description": "Swaps two items at determined indexes",
101+
"author": "omegaleo",
102+
"tags": [
103+
"csharp",
104+
"c#",
105+
"list",
106+
"utility"
107+
],
108+
"contributors": [],
109+
"code": "/// <summary>\n/// Swaps the position of 2 elements inside of a List\n/// </summary>\n/// <returns>List with swapped elements</returns>\npublic static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB)\n{\n (list[indexA], list[indexB]) = (list[indexB], list[indexA]);\n return list;\n}\n\nvar list = new List<string>() {\"Test\", \"Test2\"};\n\nConsole.WriteLine(list[0]); // Outputs: Test\nConsole.WriteLine(list[1]); // Outputs: Test2\n\nlist = list.Swap(0, 1).ToList();\n\nConsole.WriteLine(list[0]); // Outputs: Test2\nConsole.WriteLine(list[1]); // Outputs: Test\n"
110+
}
111+
]
112+
},
113+
{
114+
"categoryName": "String Utilities",
115+
"snippets": [
116+
{
117+
"title": "Capitalize first letter",
118+
"description": "Makes the first letter of a string uppercase.",
119+
"author": "chaitanya-jvnm",
120+
"tags": [
121+
"c#",
122+
"string",
123+
"capitalize",
124+
"utility"
125+
],
126+
"contributors": [],
127+
"code": "/// <summary>\n/// Capitalize the first character of the string\n/// <summary>\npublic static string Capitalize(this string str) {\n return str.Substring(0, 1).ToUpper() + str.Substring(1);\n}\n\n//Example\nstring example = \"hello\";\nstring captializedExample = example.Capitalize();\nConsole.WriteLine(captializedExample); // prints \"Hello\"\n"
128+
},
129+
{
130+
"title": "Truncate a String",
131+
"description": "Cut off a string once it reaches a determined amount of characters and add '...' to the end of the string",
132+
"author": "omegaleo",
133+
"tags": [
134+
"csharp",
135+
"c#",
136+
"list",
137+
"utility"
138+
],
139+
"contributors": [],
140+
"code": "/// <summary>\n/// Cut off a string once it reaches a <paramref name=\"maxChars\"/> amount of characters and add '...' to the end of the string\n/// </summary>\npublic static string Truncate(this string value, int maxChars)\n{\n return value.Length <= maxChars ? value : value.Substring(0, maxChars) + \"...\";\n}\n\nvar str = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tristique rhoncus bibendum. Vivamus laoreet tortor vel neque lacinia, nec rhoncus ligula pellentesque. Nullam eu ornare nibh. Donec tincidunt viverra nulla.\";\n\nConsole.WriteLine(str); // Outputs the full string\nConsole.WriteLine(str.Truncate(5)); // Outputs Lorem...\n"
141+
}
142+
]
143+
}
144+
]

0 commit comments

Comments
 (0)