Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
31051e3
add vitest package, update pre-commit scripts to include the test com…
barrymun Jan 2, 2025
374455c
Merge branch 'main' into feature/vitest-test-suite
barrymun Jan 2, 2025
7871367
Merge branch 'main' into feature/vitest-test-suite
barrymun Jan 3, 2025
f5ea3ed
moving all tests within the tests directory at the root of the project
barrymun Jan 3, 2025
3f42a75
Merge branch 'main' into feature/vitest-test-suite
barrymun Jan 3, 2025
ef33bf2
installing tsx, converting root level utils/ scripts to .ts files, ad…
barrymun Jan 3, 2025
05e49b3
Merge branch 'main' into feature/vitest-test-suite
barrymun Jan 3, 2025
607d314
update pre-commit checks and workflow scrips
barrymun Jan 3, 2025
7d1d241
move code prop to undo consolidation changes
barrymun Jan 3, 2025
ccc4cc0
remove duplicate code in script
barrymun Jan 3, 2025
411ccb8
testing tsx usage in workflow
barrymun Jan 3, 2025
8d63d17
prefix tsx calls with npx in workflows
barrymun Jan 3, 2025
f8d41da
install deps in check-snippets script
barrymun Jan 3, 2025
5dcad06
revert arg object structure conversion for the parseSnippet function
barrymun Jan 3, 2025
e0c04f2
Merge branch 'main' into feature/vitest-test-suite
barrymun Jan 9, 2025
4208ae8
update scripts
barrymun Jan 9, 2025
97adaaf
Merge branch 'main' into feature/vitest-test-suite
barrymun Jan 10, 2025
0167af2
remove unused file
barrymun Jan 10, 2025
d18a7b9
Merge branch 'main' into feature/vitest-test-suite
barrymun Jan 10, 2025
068c831
replace Array<> generic type with the shorthand []
barrymun Jan 10, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move code prop to undo consolidation changes
  • Loading branch information
barrymun committed Jan 3, 2025
commit 7d1d241ede5cb0c831dbaab13d9b3380e7848886
8 changes: 4 additions & 4 deletions public/consolidated/c.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"title": "Hello, World!",
"description": "Prints Hello, World! to the terminal.",
"author": "0xHouss",
"code": "#include <stdio.h> // Includes the input/output library\n\nint main() { // Defines the main function\n printf(\"Hello, World!\\n\") // Outputs Hello, World! and a newline\n\n return 0; // indicate the program executed successfully\n}\n",
"tags": [
"printing",
"hello-world"
],
"contributors": []
"contributors": [],
"code": "#include <stdio.h> // Includes the input/output library\n\nint main() { // Defines the main function\n printf(\"Hello, World!\\n\") // Outputs Hello, World! and a newline\n\n return 0; // indicate the program executed successfully\n}\n"
}
]
},
Expand All @@ -22,12 +22,12 @@
"title": "Factorial Function",
"description": "Calculates the factorial of a number.",
"author": "0xHouss",
"code": "int factorial(int x) {\n int y = 1;\n\n for (int i = 2; i <= x; i++)\n y *= i;\n\n return y;\n}\n\n// Usage:\nfactorial(4); // Returns: 24\n",
"tags": [
"math",
"factorial"
],
"contributors": []
"contributors": [],
"code": "int factorial(int x) {\n int y = 1;\n\n for (int i = 2; i <= x; i++)\n y *= i;\n\n return y;\n}\n\n// Usage:\nfactorial(4); // Returns: 24\n"
}
]
}
Expand Down
20 changes: 10 additions & 10 deletions public/consolidated/cpp.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"title": "Hello, World!",
"description": "Prints Hello, World! to the terminal.",
"author": "James-Beans",
"code": "#include <iostream> // Includes the input/output stream library\n\nint main() { // Defines the main function\n std::cout << \"Hello, World!\" << std::endl; // Outputs Hello, World! and a newline\n return 0; // indicate the program executed successfully\n}\n",
"tags": [
"printing",
"hello-world"
],
"contributors": []
"contributors": [],
"code": "#include <iostream> // Includes the input/output stream library\n\nint main() { // Defines the main function\n std::cout << \"Hello, World!\" << std::endl; // Outputs Hello, World! and a newline\n return 0; // indicate the program executed successfully\n}\n"
}
]
},
Expand All @@ -22,13 +22,13 @@
"title": "Vector to Queue",
"description": "Convert vector into queue quickly",
"author": "mrityunjay2003",
"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\nstd::vector<int> vec = { 1, 2, 3, 4, 5 };\nvectorToQueue(&vec); // Returns: std::queue<int> { 1, 2, 3, 4, 5 }\n",
"tags": [
"data structures",
"queue",
"vector"
],
"contributors": []
"contributors": [],
"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\nstd::vector<int> vec = { 1, 2, 3, 4, 5 };\nvectorToQueue(&vec); // Returns: std::queue<int> { 1, 2, 3, 4, 5 }\n"
}
]
},
Expand All @@ -39,12 +39,12 @@
"title": "Check Prime Number",
"description": "Check if an integer is a prime number",
"author": "MihneaMoso",
"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:\nis_prime(29); // Returns: true\n",
"tags": [
"number",
"prime"
],
"contributors": []
"contributors": [],
"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:\nis_prime(29); // Returns: true\n"
}
]
},
Expand All @@ -55,23 +55,23 @@
"title": "Reverse String",
"description": "Reverses the characters in a string.",
"author": "Vaibhav-kesarwani",
"code": "#include <string>\n#include <algorithm>\n\nstd::string reverseString(const std::string& input) {\n std::string reversed = input;\n std::reverse(reversed.begin(), reversed.end());\n return reversed;\n}\n\nreverseString(\"quicksnip\"); // Returns: \"pinskciuq\"\n",
"tags": [
"array",
"reverse"
],
"contributors": []
"contributors": [],
"code": "#include <string>\n#include <algorithm>\n\nstd::string reverseString(const std::string& input) {\n std::string reversed = input;\n std::reverse(reversed.begin(), reversed.end());\n return reversed;\n}\n\nreverseString(\"quicksnip\"); // Returns: \"pinskciuq\"\n"
},
{
"title": "Split String",
"description": "Splits a string by a delimiter",
"author": "saminjay",
"code": "#include <string>\n#include <vector>\n\nstd::vector<std::string> split_string(std::string str, std::string delim) {\n std::vector<std::string> splits;\n int i = 0, j;\n int inc = delim.length();\n while (j != std::string::npos) {\n j = str.find(delim, i);\n splits.push_back(str.substr(i, j - i));\n i = j + inc;\n }\n return splits;\n}\n\n// Usage:\nsplit_string(\"quick_-snip\", \"_-\"); // Returns: std::vector<std::string> { \"quick\", \"snip\" }\n",
"tags": [
"string",
"split"
],
"contributors": []
"contributors": [],
"code": "#include <string>\n#include <vector>\n\nstd::vector<std::string> split_string(std::string str, std::string delim) {\n std::vector<std::string> splits;\n int i = 0, j;\n int inc = delim.length();\n while (j != std::string::npos) {\n j = str.find(delim, i);\n splits.push_back(str.substr(i, j - i));\n i = j + inc;\n }\n return splits;\n}\n\n// Usage:\nsplit_string(\"quick_-snip\", \"_-\"); // Returns: std::vector<std::string> { \"quick\", \"snip\" }\n"
}
]
}
Expand Down
32 changes: 16 additions & 16 deletions public/consolidated/csharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"title": "Hello, World!",
"description": "Prints Hello, World! to the terminal.",
"author": "chaitanya-jvnm",
"code": "public class Program {\n public static void Main(string[] args) {\n System.Console.WriteLine(\"Hello, World!\");\n }\n}\n",
"tags": [
"printing",
"hello-world"
],
"contributors": []
"contributors": [],
"code": "public class Program {\n public static void Main(string[] args) {\n System.Console.WriteLine(\"Hello, World!\");\n }\n}\n"
}
]
},
Expand All @@ -22,23 +22,23 @@
"title": "Generate GUID",
"description": "Generates a new GUID",
"author": "chaitanya-jvnm",
"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",
"tags": [
"guid",
"generate"
],
"contributors": []
"contributors": [],
"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"
},
{
"title": "Validate GUID",
"description": "Checks if a string is a valid GUID.",
"author": "chaitanya-jvnm",
"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",
"tags": [
"guid",
"validate"
],
"contributors": []
"contributors": [],
"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"
}
]
},
Expand All @@ -49,23 +49,23 @@
"title": "Decode JWT",
"description": "Decodes a JWT.",
"author": "chaitanya-jvnm",
"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",
"tags": [
"jwt",
"decode"
],
"contributors": []
"contributors": [],
"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"
},
{
"title": "Validate JWT",
"description": "Validates a JWT.",
"author": "chaitanya-jvnm",
"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",
"tags": [
"jwt",
"validate"
],
"contributors": []
"contributors": [],
"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"
}
]
},
Expand All @@ -76,12 +76,12 @@
"title": "Swap items at index",
"description": "Swaps two items at determined indexes",
"author": "omegaleo",
"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",
"tags": [
"list",
"swapping"
],
"contributors": []
"contributors": [],
"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"
}
]
},
Expand All @@ -92,23 +92,23 @@
"title": "Capitalize first letter",
"description": "Makes the first letter of a string uppercase.",
"author": "chaitanya-jvnm",
"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",
"tags": [
"string",
"capitalize"
],
"contributors": []
"contributors": [],
"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"
},
{
"title": "Truncate String",
"description": "Cut off a string once it reaches a determined amount of characters and add '...' to the end of the string",
"author": "omegaleo",
"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",
"tags": [
"string",
"truncate"
],
"contributors": []
"contributors": [],
"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"
}
]
}
Expand Down
Loading
Loading