Skip to content

Commit 94962ab

Browse files
committed
Update consolidated snippets
1 parent 2c77190 commit 94962ab

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

public/consolidated/csharp.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,110 @@
11
[
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": "Hello, World!",
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": "Hello, World!",
38+
"description": "Converts a GUID to a byte array.",
39+
"author": "chaitanya-jvnm",
40+
"tags": [
41+
"c#",
42+
"guid",
43+
"byte-array",
44+
"utility"
45+
],
46+
"contributors": [],
47+
"code": "public static byte[] GuidToByteArray(string guid) {\n return new Guid(guid).ToByteArray();\n}\n"
48+
},
49+
{
50+
"title": "Hello, World!",
51+
"description": "Checks if a string is a valid GUID.",
52+
"author": "chaitanya-jvnm",
53+
"tags": [
54+
"c#",
55+
"guid",
56+
"validate",
57+
"utility"
58+
],
59+
"contributors": [],
60+
"code": "public static bool IsGuid(string str) {\n return Guid.TryParse(str, out _);\n}\n"
61+
}
62+
]
63+
},
64+
{
65+
"categoryName": "Jwt Utilities",
66+
"snippets": [
67+
{
68+
"title": "Hello, World!",
69+
"description": "Decodes a JWT.",
70+
"author": "chaitanya-jvnm",
71+
"tags": [
72+
"c#",
73+
"jwt",
74+
"decode",
75+
"utility"
76+
],
77+
"contributors": [],
78+
"code": "public static string DecodeJwt(string token) {\n return new JwtSecurityTokenHandler().ReadJwtToken(token).ToString();\n}\n"
79+
},
80+
{
81+
"title": "Hello, World!",
82+
"description": "Generates a new JWT.",
83+
"author": "chaitanya-jvnm",
84+
"tags": [
85+
"c#",
86+
"jwt",
87+
"generate",
88+
"utility"
89+
],
90+
"contributors": [],
91+
"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"
92+
},
93+
{
94+
"title": "Hello, World!",
95+
"description": "Validates a JWT.",
96+
"author": "chaitanya-jvnm",
97+
"tags": [
98+
"c#",
99+
"jwt",
100+
"validate",
101+
"utility"
102+
],
103+
"contributors": [],
104+
"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"
105+
}
106+
]
107+
},
2108
{
3109
"categoryName": "List Utilities",
4110
"snippets": [
@@ -20,6 +126,32 @@
20126
{
21127
"categoryName": "String Utilities",
22128
"snippets": [
129+
{
130+
"title": "Hello, World!",
131+
"description": "Makes the first letter of a string uppercase.",
132+
"author": "chaitanya-jvnm",
133+
"tags": [
134+
"c#",
135+
"string",
136+
"capitalize",
137+
"utility"
138+
],
139+
"contributors": [],
140+
"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"
141+
},
142+
{
143+
"title": "Hello, World!",
144+
"description": "Splits a string by a delimiter.",
145+
"author": "chaitanya-jvnm",
146+
"tags": [
147+
"c#",
148+
"string",
149+
"split",
150+
"utility"
151+
],
152+
"contributors": [],
153+
"code": "public static string[] SplitString(string str, string delimiter) {\n return str.Split(delimiter);\n}\n"
154+
},
23155
{
24156
"title": "Truncate a String",
25157
"description": "Cut off a string once it reaches a determined amount of characters and add '...' to the end of the string",

0 commit comments

Comments
 (0)