You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"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"
"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"
0 commit comments