|
| 1 | +[ |
| 2 | + { |
| 3 | + "name": "Basics", |
| 4 | + "snippets": [ |
| 5 | + { |
| 6 | + "title": "Hello, World!", |
| 7 | + "description": "Prints Hello, World! to the terminal.", |
| 8 | + "author": "chaitanya-jvnm", |
| 9 | + "tags": ["printing", "hello-world"], |
| 10 | + "contributors": [], |
| 11 | + "code": "public class Program {\n public static void Main(string[] args) {\n System.Console.WriteLine(\"Hello, World!\");\n }\n}\n", |
| 12 | + "extension": "csharp" |
| 13 | + } |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "name": "Guid Utilities", |
| 18 | + "snippets": [ |
| 19 | + { |
| 20 | + "title": "Generate GUID", |
| 21 | + "description": "Generates a new GUID", |
| 22 | + "author": "chaitanya-jvnm", |
| 23 | + "tags": ["guid", "generate"], |
| 24 | + "contributors": [], |
| 25 | + "code": "public static string GenerateGuid() {\n return Guid.NewGuid().ToString();\n}\n\n// Usage:\nGenerateGuid(); // Returns: 1c4c38d8-64e4-431b-884a-c6eec2ab02cd (Uuid is random)\n", |
| 26 | + "extension": "csharp" |
| 27 | + }, |
| 28 | + { |
| 29 | + "title": "Validate GUID", |
| 30 | + "description": "Checks if a string is a valid GUID.", |
| 31 | + "author": "chaitanya-jvnm", |
| 32 | + "tags": ["guid", "validate"], |
| 33 | + "contributors": [], |
| 34 | + "code": "public static bool IsGuid(string str) {\n return Guid.TryParse(str, out _);\n}\n\n// Usage:\nIsGuid(\"1c4c38d8-64e4-431b-884a-c6eec2ab02cd\"); // Returns: true\nIsGuid(\"quicksnip\"); // Returns: false\n", |
| 35 | + "extension": "csharp" |
| 36 | + } |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "name": "Jwt Utilities", |
| 41 | + "snippets": [ |
| 42 | + { |
| 43 | + "title": "Decode JWT", |
| 44 | + "description": "Decodes a JWT.", |
| 45 | + "author": "chaitanya-jvnm", |
| 46 | + "tags": ["jwt", "decode"], |
| 47 | + "contributors": [], |
| 48 | + "code": "public static string DecodeJwt(string token) {\n return new JwtSecurityTokenHandler().ReadJwtToken(token).ToString();\n}\n\n// Usage:\nstring token = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\";\nDecodeJwt(token); // Returns: \"{\\\"alg\\\":\\\"HS256\\\",\\\"typ\\\":\\\"JWT\\\"}.{\\\"sub\\\":\\\"1234567890\\\",\\\"name\\\":\\\"John Doe\\\",\\\"iat\\\":1516239022}\"\n", |
| 49 | + "extension": "csharp" |
| 50 | + }, |
| 51 | + { |
| 52 | + "title": "Validate JWT", |
| 53 | + "description": "Validates a JWT.", |
| 54 | + "author": "chaitanya-jvnm", |
| 55 | + "tags": ["jwt", "validate"], |
| 56 | + "contributors": [], |
| 57 | + "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// Usage:\nstring JWT = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\";\nstring correctSecret = \"your-256-bit-secret\";\nstring wrongSecret = \"this-is-not-the-right-secret\";\n\nValidateJwt(JWT, correctSecret); // Returns: true\nValidateJwt(JWT, wrongSecret); // Returns: false\n", |
| 58 | + "extension": "csharp" |
| 59 | + } |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "name": "List Utilities", |
| 64 | + "snippets": [ |
| 65 | + { |
| 66 | + "title": "Swap items at index", |
| 67 | + "description": "Swaps two items at determined indexes", |
| 68 | + "author": "omegaleo", |
| 69 | + "tags": ["list", "swapping"], |
| 70 | + "contributors": [], |
| 71 | + "code": "public 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\nlist.Swap(0, 1); // Swaps \"Test\" and \"Test2\" in place\n", |
| 72 | + "extension": "csharp" |
| 73 | + } |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "name": "String Utilities", |
| 78 | + "snippets": [ |
| 79 | + { |
| 80 | + "title": "Capitalize first letter", |
| 81 | + "description": "Makes the first letter of a string uppercase.", |
| 82 | + "author": "chaitanya-jvnm", |
| 83 | + "tags": ["string", "capitalize"], |
| 84 | + "contributors": [], |
| 85 | + "code": "public static string Capitalize(this string str) {\n return str.Substring(0, 1).ToUpper() + str.Substring(1);\n}\n\n// Usage:\n\"quicksnip\".Capitalize(); // Returns: \"Quicksnip\"\n", |
| 86 | + "extension": "csharp" |
| 87 | + }, |
| 88 | + { |
| 89 | + "title": "Truncate String", |
| 90 | + "description": "Cut off a string once it reaches a determined amount of characters and add '...' to the end of the string", |
| 91 | + "author": "omegaleo", |
| 92 | + "tags": ["string", "truncate"], |
| 93 | + "contributors": [], |
| 94 | + "code": "public static string Truncate(this string value, int maxChars)\n{\n return value.Length <= maxChars ? value : value.Substring(0, maxChars) + \"...\";\n}\n\n// Usage:\n\"Quicksnip\".Truncate(5); // Returns: \"Quick...\"\n", |
| 95 | + "extension": "csharp" |
| 96 | + } |
| 97 | + ] |
| 98 | + } |
| 99 | +] |
0 commit comments