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 5726f2b

Browse files
Update consolidated snippets
1 parent 48c441c commit 5726f2b

File tree

1 file changed

+9
-35
lines changed

1 file changed

+9
-35
lines changed

‎public/consolidated/csharp.json‎

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"categoryName": "Guid Utilities",
2222
"snippets": [
2323
{
24-
"title": "Hello, World!",
24+
"title": "Generate GUID",
2525
"description": "Generates a new GUID",
2626
"author": "chaitanya-jvnm",
2727
"tags": [
@@ -34,20 +34,7 @@
3434
"code": "public static string GenerateGuid() {\n return Guid.NewGuid().ToString();\n}\n"
3535
},
3636
{
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!",
37+
"title": "Validate GUID",
5138
"description": "Checks if a string is a valid GUID.",
5239
"author": "chaitanya-jvnm",
5340
"tags": [
@@ -65,7 +52,7 @@
6552
"categoryName": "Jwt Utilities",
6653
"snippets": [
6754
{
68-
"title": "Hello, World!",
55+
"title": "Decode JWT",
6956
"description": "Decodes a JWT.",
7057
"author": "chaitanya-jvnm",
7158
"tags": [
@@ -75,10 +62,10 @@
7562
"utility"
7663
],
7764
"contributors": [],
78-
"code": "public static string DecodeJwt(string token) {\n return new JwtSecurityTokenHandler().ReadJwtToken(token).ToString();\n}\n"
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"
7966
},
8067
{
81-
"title": "Hello, World!",
68+
"title": "Generate JWT",
8269
"description": "Generates a new JWT.",
8370
"author": "chaitanya-jvnm",
8471
"tags": [
@@ -91,7 +78,7 @@
9178
"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"
9279
},
9380
{
94-
"title": "Hello, World!",
81+
"title": "Validate JWT",
9582
"description": "Validates a JWT.",
9683
"author": "chaitanya-jvnm",
9784
"tags": [
@@ -101,7 +88,7 @@
10188
"utility"
10289
],
10390
"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"
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"
10592
}
10693
]
10794
},
@@ -127,7 +114,7 @@
127114
"categoryName": "String Utilities",
128115
"snippets": [
129116
{
130-
"title": "Hello, World!",
117+
"title": "Capitalize first letter",
131118
"description": "Makes the first letter of a string uppercase.",
132119
"author": "chaitanya-jvnm",
133120
"tags": [
@@ -137,20 +124,7 @@
137124
"utility"
138125
],
139126
"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"
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"
154128
},
155129
{
156130
"title": "Truncate a String",

0 commit comments

Comments
(0)

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