From 470a9e84ce3ff2b61a76f29c2bd3d0460cc5bed6 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 3 Jan 2025 22:59:23 +0000 Subject: [PATCH 1/4] Update consolidated snippets --- public/consolidated/cpp.json | 17 +++++++++++++++++ public/consolidated/javascript.json | 18 ++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/public/consolidated/cpp.json b/public/consolidated/cpp.json index e560e82d..6427f04f 100644 --- a/public/consolidated/cpp.json +++ b/public/consolidated/cpp.json @@ -32,6 +32,23 @@ } ] }, + { + "categoryName": "Debuging", + "snippets": [ + { + "title": "Vector Print", + "description": "Overloads the << operator to print the contents of a vector just like in python.", + "author": "Mohamed-faaris", + "tags": [ + "printing", + "debuging", + "vector" + ], + "contributors": [], + "code": "#include \n#include \n\ntemplate \nstd::ostream& operator<<(std::ostream& os, const std::vector& vec) {\n os << \"[\"; \n for (size_t i = 0; i < vec.size(); ++i) {\n os << vec[i]; // Print each vector element\n if (i != vec.size() - 1) {\n os << \", \"; // Add separator\n }\n }\n os << \"]\"; \n return os; // Return the stream\n}\n\n// Usage:\nstd::vector numbers = {1, 2, 3, 4, 5};\nstd::cout << numbers << std::endl; // Outputs: [1, 2, 3, 4, 5]\n\n" + } + ] + }, { "categoryName": "Math And Numbers", "snippets": [ diff --git a/public/consolidated/javascript.json b/public/consolidated/javascript.json index 99588330..c7b78ff8 100644 --- a/public/consolidated/javascript.json +++ b/public/consolidated/javascript.json @@ -85,10 +85,8 @@ "description": "Converts RGB color values to hexadecimal color code.", "author": "jjcantu", "tags": [ - "javascript", "color", - "conversion", - "utility" + "conversion" ], "contributors": [], "code": "function rgbToHex(r, g, b) {\n const toHex = (n) => {\n const hex = n.toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n };\n \n return '#' + toHex(r) + toHex(g) + toHex(b);\n}\n\n// Usage:\nconsole.log(rgbToHex(255, 128, 0)); // Output: \"#ff8000\"\nconsole.log(rgbToHex(0, 255, 0)); // Output: \"#00ff00\"\n" @@ -407,10 +405,8 @@ "description": "Converts bytes into human-readable file size format.", "author": "jjcantu", "tags": [ - "javascript", "format", - "size", - "utility" + "size" ], "contributors": [], "code": "function formatFileSize(bytes) {\n if (bytes === 0) return '0 Bytes';\n \n const k = 1024;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n \n return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];\n}\n\n// Usage:\nconsole.log(formatFileSize(1234)); // Output: \"1.21 KB\"\nconsole.log(formatFileSize(1234567)); // Output: \"1.18 MB\"\n" @@ -506,13 +502,11 @@ "description": "Creates a deep copy of an object or array without reference.", "author": "jjcantu", "tags": [ - "javascript", "object", - "clone", - "utility" + "clone" ], "contributors": [], - "code": "function deepClone(obj) {\n if (obj === null || typeof obj !== 'object') return obj;\n \n const clone = Array.isArray(obj) ? [] : {};\n \n for (let key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = deepClone(obj[key]);\n }\n }\n \n return clone;\n}\n\n// Usage:\nconst original = { a: 1, b: { c: 2 }, d: [1, 2, 3] };\nconst cloned = deepClone(original);\nconsole.log(cloned); // Output: { a: 1, b: { c: 2 }, d: [1, 2, 3] }\n" + "code": "function deepClone(obj) {\n if (obj === null || typeof obj !== 'object') return obj;\n \n const clone = Array.isArray(obj) ? [] : {};\n \n for (let key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = deepClone(obj[key]);\n }\n }\n \n return clone;\n}\n\n// Usage:\nconst original = { a: 1, b: { c: 2 }, d: [1, 2, 3] };\nconst cloned = deepClone(original);\nconsole.log(cloned); // Output: 'original' but cloned\n" }, { "title": "Filter Object", @@ -758,9 +752,9 @@ "description": "Generates a UUID (v4) string.", "author": "jjcantu", "tags": [ - "javascript", "uuid", - "utility" + "generate", + "string" ], "contributors": [], "code": "function generateUUID() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n const r = Math.random() * 16 | 0;\n const v = c === 'x' ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n}\n\n// Usage:\nconsole.log(generateUUID()); // Output: \"a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5\"\n" From ba6337fc8997ec0518dc483d882a9478b4a002b5 Mon Sep 17 00:00:00 2001 From: christianfuttrup Date: Sat, 4 Jan 2025 00:10:11 +0100 Subject: [PATCH 2/4] Refactored keyboard navigation --- src/hooks/useKeyboardNavigation.ts | 50 ++++++++++++++++++------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/hooks/useKeyboardNavigation.ts b/src/hooks/useKeyboardNavigation.ts index 7b814e78..46bda82c 100644 --- a/src/hooks/useKeyboardNavigation.ts +++ b/src/hooks/useKeyboardNavigation.ts @@ -9,6 +9,16 @@ interface UseKeyboardNavigationProps { onClose: () => void; } +const keyboardEventKeys = { + arrowDown: "ArrowDown", + arrowUp: "ArrowUp", + enter: "Enter", + escape: "Escape", +} as const; + +type KeyboardEventKeys = + (typeof keyboardEventKeys)[keyof typeof keyboardEventKeys]; + export const useKeyboardNavigation = ({ items, isOpen, @@ -20,25 +30,27 @@ export const useKeyboardNavigation = ({ const handleKeyDown = (event: React.KeyboardEvent) => { if (!isOpen) return; - switch (event.key) { - case "ArrowDown": - event.preventDefault(); - setFocusedIndex((prev) => (prev < items.length - 1 ? prev + 1 : 0)); - break; - case "ArrowUp": - event.preventDefault(); - setFocusedIndex((prev) => (prev > 0 ? prev - 1 : items.length - 1)); - break; - case "Enter": - event.preventDefault(); - if (focusedIndex >= 0) { - onSelect(items[focusedIndex]); - } - break; - case "Escape": - event.preventDefault(); - onClose(); - break; + const key = event.key as KeyboardEventKeys; + + if (Object.values(keyboardEventKeys).includes(key)) { + event.preventDefault(); + + switch (key) { + case "ArrowDown": + setFocusedIndex((prev) => (prev < items.length - 1 ? prev + 1 : 0)); + break; + case "ArrowUp": + setFocusedIndex((prev) => (prev > 0 ? prev - 1 : items.length - 1)); + break; + case "Enter": + if (focusedIndex >= 0) { + onSelect(items[focusedIndex]); + } + break; + case "Escape": + onClose(); + break; + } } }; From 2d59cca5615f36b0e1dc22f5c4f14216e7fa04e7 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 4 Jan 2025 18:57:19 +0000 Subject: [PATCH 3/4] Update consolidated snippets --- public/consolidated/c.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/consolidated/c.json b/public/consolidated/c.json index 1588cd69..a9258611 100644 --- a/public/consolidated/c.json +++ b/public/consolidated/c.json @@ -38,7 +38,7 @@ "numbers" ], "contributors": [], - "code": "#include\nvoid swap(int* num1,int* num2){\n *num1 = *num1 + *num2;\n *num2 = *num1 - *num2;\n *num1 = *num1 - *num2;\n}\n\n// Usage:\nint a = 3,b = 4;\nswap(&a,&b); // simply use printf after this to print swapped values\n" + "code": "#include\nvoid swap(int* num1,int* num2){\n *num1 = *num1 + *num2;\n *num2 = *num1 - *num2;\n *num1 = *num1 - *num2;\n}\n\n// Usage:\nint a = 3,b = 4;\nswap(&a,&b); // swaps the values of the a and b variables\n" } ] } From a92a93f23b828e7b6a59850f2a9481e202fc84b3 Mon Sep 17 00:00:00 2001 From: christianfuttrup Date: Sat, 4 Jan 2025 20:51:23 +0100 Subject: [PATCH 4/4] Revert "Update consolidated snippets" This reverts commit 2d59cca5615f36b0e1dc22f5c4f14216e7fa04e7. --- public/consolidated/c.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/consolidated/c.json b/public/consolidated/c.json index a9258611..1588cd69 100644 --- a/public/consolidated/c.json +++ b/public/consolidated/c.json @@ -38,7 +38,7 @@ "numbers" ], "contributors": [], - "code": "#include\nvoid swap(int* num1,int* num2){\n *num1 = *num1 + *num2;\n *num2 = *num1 - *num2;\n *num1 = *num1 - *num2;\n}\n\n// Usage:\nint a = 3,b = 4;\nswap(&a,&b); // swaps the values of the a and b variables\n" + "code": "#include\nvoid swap(int* num1,int* num2){\n *num1 = *num1 + *num2;\n *num2 = *num1 - *num2;\n *num1 = *num1 - *num2;\n}\n\n// Usage:\nint a = 3,b = 4;\nswap(&a,&b); // simply use printf after this to print swapped values\n" } ] }