diff --git a/public/data/_index.json b/public/data/_index.json index fc56fcd9..5dc86960 100644 --- a/public/data/_index.json +++ b/public/data/_index.json @@ -23,6 +23,10 @@ "lang": "CPP", "icon": "/icons/cpp.svg" }, + { + "lang": "C", + "icon": "/icons/c.svg" + }, { "lang": "Rust", "icon": "/icons/rust.svg" diff --git a/public/data/c.json b/public/data/c.json new file mode 100644 index 00000000..1c2e98f9 --- /dev/null +++ b/public/data/c.json @@ -0,0 +1,59 @@ +[ + { + "categoryName": "Basics", + "snippets": [ + { + "title": "Hello, World!", + "description": "Prints Hello, World! to the terminal.", + "code": [ + "#include // Includes the input/output library", + "", + "int main() { // Defines the main function", + " printf(\"Hello, World!\\n\") // Outputs Hello, World! and a newline", + "", + " return 0; // indicate the program executed successfully", + "}" + ], + "tags": ["c", "printing", "hello-world", "utility"], + "author": "0xHouss" + } + ] + }, + { + "categoryName": "Mathematical Functions", + "snippets": [ + { + "title": "Factorial Function", + "description": "Calculates the factorial of a number.", + "code": [ + "int factorial(int x) {", + " int y = 1;", + "", + " for (int i = 2; i <= x; i++)", + " y *= i;", + "", + " return y;", + "}" + ], + "tags": ["c", "math", "factorial", "utility"], + "author": "0xHouss" + }, + { + "title": "Power Function", + "description": "Calculates the power of a number.", + "code": [ + "int power(int x, int n) {", + " int y = 1;", + "", + " for (int i = 0; i < n; i++)", + " y *= x;", + "", + " return y;", + "}" + ], + "tags": ["c", "math", "power", "utility"], + "author": "0xHouss" + } + ] + } +] \ No newline at end of file diff --git a/public/data/javascript.json b/public/data/javascript.json index 49481bf3..7ee15b3a 100644 --- a/public/data/javascript.json +++ b/public/data/javascript.json @@ -168,7 +168,7 @@ "// Example usage:", "console.log(countWords('Hello world! This is a test.')); // Output: 6" ], - "tags": ["string", "manipulation", "word count", "count"], + "tags": ["javascript", "string", "manipulation", "word count", "count"], "author": "axorax" }, { @@ -182,7 +182,7 @@ "// Example usage:", "console.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'" ], - "tags": ["string", "whitespace"], + "tags": ["javascript", "string", "whitespace"], "author": "axorax" }, { @@ -608,15 +608,7 @@ "console.log(timeAgoOrAhead(new Date())); // just now", "console.log(timeAgoOrAhead(futureDate)); // in x years" ], - "tags": [ - "javascript", - "date", - "time", - "relative", - "future", - "past", - "utility" - ], + "tags": ["javascript", "date", "time", "relative", "future", "past", "utility"], "author": "Yugveer06" }, { @@ -732,6 +724,7 @@ "code": [ "const debounce = (func, delay) => {", " let timeout;", + "", " return (...args) => {", " clearTimeout(timeout);", " timeout = setTimeout(() => func(...args), delay);", @@ -774,32 +767,49 @@ "tags": ["javascript", "utility", "throttle", "performance"], "author": "dostonnabotov" }, - { - "title": "Get Contrast Color", - "description": "Returns either black or white text color based on the brightness of the provided hex color.", - "code": [ - "const getContrastColor = (hexColor) => {", - " // Expand short hex color to full format", - " if (hexColor.length === 4) {", - " hexColor = `#${hexColor[1]}${hexColor[1]}${hexColor[2]}${hexColor[2]}${hexColor[3]}${hexColor[3]}`;", - " }", - " const r = parseInt(hexColor.slice(1, 3), 16);", - " const g = parseInt(hexColor.slice(3, 5), 16);", - " const b = parseInt(hexColor.slice(5, 7), 16);", - " const brightness = (r * 299 + g * 587 + b * 114) / 1000;", - " return brightness >= 128 ? \"#000000\" : \"#FFFFFF\";", - "};", - "", - "// Usage:", - "console.log(getContrastColor('#fff')); // Output: #000000 (black)", - "console.log(getContrastColor('#123456')); // Output: #FFFFFF (white)", - "console.log(getContrastColor('#ff6347')); // Output: #000000 (black)", - "console.log(getContrastColor('#f4f')); // Output: #000000 (black)" - ], - "tags": ["color", "hex", "contrast", "brightness", "utility"], - "author": "yaya12085" -} - + { + "title": "Get Contrast Color", + "description": "Returns either black or white text color based on the brightness of the provided hex color.", + "code": [ + "const getContrastColor = (hexColor) => {", + " // Expand short hex color to full format", + " if (hexColor.length === 4) {", + " hexColor = `#${hexColor[1]}${hexColor[1]}${hexColor[2]}${hexColor[2]}${hexColor[3]}${hexColor[3]}`;", + " }", + " const r = parseInt(hexColor.slice(1, 3), 16);", + " const g = parseInt(hexColor.slice(3, 5), 16);", + " const b = parseInt(hexColor.slice(5, 7), 16);", + " const brightness = (r * 299 + g * 587 + b * 114) / 1000;", + " return brightness >= 128 ? \"#000000\" : \"#FFFFFF\";", + "};", + "", + "// Usage:", + "console.log(getContrastColor('#fff')); // Output: #000000 (black)", + "console.log(getContrastColor('#123456')); // Output: #FFFFFF (white)", + "console.log(getContrastColor('#ff6347')); // Output: #000000 (black)", + "console.log(getContrastColor('#f4f')); // Output: #000000 (black)" + ], + "tags": ["javascript", "color", "hex", "contrast", "brightness", "utility"], + "author": "yaya12085" + }, + { + "title": "Sleep Function", + "description": "Waits for a specified amount of milliseconds before resolving.", + "code": [ + "const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));", + "", + "// Usage:", + "async function main() {", + " console.log('Hello');", + " await sleep(2000); // Waits for 2 seconds", + " console.log('World!');", + "}", + "", + "main();" + ], + "tags": ["javascript", "sleep", "delay", "utility", "promises"], + "author": "0xHouss" + } ] }, { @@ -886,32 +896,31 @@ } ] }, -{ - "categoryName": "Number Formatting", - "snippets": [ - { - "title": "Number Formatter", - "description": "Formats a number with suffixes (K, M, B, etc.).", - "code": [ - "const nFormatter = (num) => {", - " if (!num) return;", - " num = parseFloat(num.toString().replace(/[^0-9.]/g, ''));", - " const suffixes = ['', 'K', 'M', 'B', 'T', 'P', 'E'];", - " let index = 0;", - " while (num >= 1000 && index < suffixes.length - 1) {", - " num /= 1000;", - " index++;", - " }", - " return num.toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + suffixes[index];", - "};", - "", - "// Usage:", - "console.log(nFormatter(1234567)); // Output: '1.23M'" - ], - "tags": ["javascript", "number", "format", "utility"], - "author": "realvishalrana" - } - ] -} - + { + "categoryName": "Number Formatting", + "snippets": [ + { + "title": "Number Formatter", + "description": "Formats a number with suffixes (K, M, B, etc.).", + "code": [ + "const nFormatter = (num) => {", + " if (!num) return;", + " num = parseFloat(num.toString().replace(/[^0-9.]/g, ''));", + " const suffixes = ['', 'K', 'M', 'B', 'T', 'P', 'E'];", + " let index = 0;", + " while (num >= 1000 && index < suffixes.length - 1) {", + " num /= 1000;", + " index++;", + " }", + " return num.toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + suffixes[index];", + "};", + "", + "// Usage:", + "console.log(nFormatter(1234567)); // Output: '1.23M'" + ], + "tags": ["javascript", "number", "format", "utility"], + "author": "realvishalrana" + } + ] + } ] diff --git a/public/data/rust.json b/public/data/rust.json index 75648018..5e53632c 100644 --- a/public/data/rust.json +++ b/public/data/rust.json @@ -1,7 +1,7 @@ [ { - "categoryName": "Basics", - "snippets": [ + "categoryName": "Basics", + "snippets": [ { "title": "Hello, World!", "description": "Prints Hello, World! to the terminal.", diff --git a/public/icons/c.svg b/public/icons/c.svg new file mode 100644 index 00000000..94ebe6d9 --- /dev/null +++ b/public/icons/c.svg @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file