Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/data/_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"lang": "CPP",
"icon": "/icons/cpp.svg"
},
{
"lang": "C",
"icon": "/icons/c.svg"
},
{
"lang": "Rust",
"icon": "/icons/rust.svg"
Expand Down
59 changes: 59 additions & 0 deletions public/data/c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[
{
"categoryName": "Basics",
"snippets": [
{
"title": "Hello, World!",
"description": "Prints Hello, World! to the terminal.",
"code": [
"#include <stdio.h> // 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"
}
]
}
]
139 changes: 74 additions & 65 deletions public/data/javascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand All @@ -182,7 +182,7 @@
"// Example usage:",
"console.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'"
],
"tags": ["string", "whitespace"],
"tags": ["javascript", "string", "whitespace"],
"author": "axorax"
}
]
Expand Down Expand Up @@ -318,15 +318,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"
}
]
Expand Down Expand Up @@ -357,6 +349,7 @@
"code": [
"const debounce = (func, delay) => {",
" let timeout;",
"",
" return (...args) => {",
" clearTimeout(timeout);",
" timeout = setTimeout(() => func(...args), delay);",
Expand Down Expand Up @@ -399,32 +392,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"
}
]
},
{
Expand Down Expand Up @@ -511,32 +521,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"
}
]
}
]
4 changes: 2 additions & 2 deletions public/data/rust.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"categoryName": "Basics",
"snippets": [
"categoryName": "Basics",
"snippets": [
{
"title": "Hello, World!",
"description": "Prints Hello, World! to the terminal.",
Expand Down
15 changes: 15 additions & 0 deletions public/icons/c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.