Skip to content

Commit a959e95

Browse files
committed
Update consolidated snippets
1 parent 1dd6a8f commit a959e95

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

public/consolidated/cpp.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@
6161
}
6262
]
6363
},
64+
{
65+
"categoryName": "Debuging",
66+
"snippets": [
67+
{
68+
"title": "Vector Print",
69+
"description": "Overloads the << operator to print the contents of a vector just like in python.",
70+
"author": "Mohamed-faaris",
71+
"tags": [
72+
"printing",
73+
"debuging",
74+
"vector"
75+
],
76+
"contributors": [],
77+
"code": "#include <iostream> \n#include <vector> \n\ntemplate <typename T>\nstd::ostream& operator<<(std::ostream& os, const std::vector<T>& 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<int> numbers = {1, 2, 3, 4, 5};\nstd::cout << numbers << std::endl; // Outputs: [1, 2, 3, 4, 5]\n\n"
78+
}
79+
]
80+
},
6481
{
6582
"categoryName": "File Handling",
6683
"snippets": [

public/consolidated/javascript.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@
8585
"description": "Converts RGB color values to hexadecimal color code.",
8686
"author": "jjcantu",
8787
"tags": [
88-
"javascript",
8988
"color",
90-
"conversion",
91-
"utility"
89+
"conversion"
9290
],
9391
"contributors": [],
9492
"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 @@
407405
"description": "Converts bytes into human-readable file size format.",
408406
"author": "jjcantu",
409407
"tags": [
410-
"javascript",
411408
"format",
412-
"size",
413-
"utility"
409+
"size"
414410
],
415411
"contributors": [],
416412
"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 @@
506502
"description": "Creates a deep copy of an object or array without reference.",
507503
"author": "jjcantu",
508504
"tags": [
509-
"javascript",
510505
"object",
511-
"clone",
512-
"utility"
506+
"clone"
513507
],
514508
"contributors": [],
515-
"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"
509+
"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"
516510
},
517511
{
518512
"title": "Filter Object",
@@ -758,9 +752,9 @@
758752
"description": "Generates a UUID (v4) string.",
759753
"author": "jjcantu",
760754
"tags": [
761-
"javascript",
762755
"uuid",
763-
"utility"
756+
"generate",
757+
"string"
764758
],
765759
"contributors": [],
766760
"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"

0 commit comments

Comments
 (0)