Skip to content

Commit 5d174d7

Browse files
Merge branch 'main' into Python
2 parents a428ac1 + 39ab2df commit 5d174d7

File tree

6 files changed

+257
-68
lines changed

6 files changed

+257
-68
lines changed

public/consolidated/all_snippets.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,78 @@
11
[
2+
{
3+
"language": "c",
4+
"categoryName": "Basics",
5+
"snippets": [
6+
{
7+
"title": "Hello, World!",
8+
"description": "Prints Hello, World! to the terminal.",
9+
"code": [
10+
"#include <stdio.h> // Includes the input/output library",
11+
"",
12+
"int main() { // Defines the main function",
13+
" printf(\"Hello, World!\\n\") // Outputs Hello, World! and a newline",
14+
"",
15+
" return 0; // indicate the program executed successfully",
16+
"}"
17+
],
18+
"tags": [
19+
"c",
20+
"printing",
21+
"hello-world",
22+
"utility"
23+
],
24+
"author": "0xHouss"
25+
}
26+
]
27+
},
28+
{
29+
"language": "c",
30+
"categoryName": "Mathematical Functions",
31+
"snippets": [
32+
{
33+
"title": "Factorial Function",
34+
"description": "Calculates the factorial of a number.",
35+
"code": [
36+
"int factorial(int x) {",
37+
" int y = 1;",
38+
"",
39+
" for (int i = 2; i <= x; i++)",
40+
" y *= i;",
41+
"",
42+
" return y;",
43+
"}"
44+
],
45+
"tags": [
46+
"c",
47+
"math",
48+
"factorial",
49+
"utility"
50+
],
51+
"author": "0xHouss"
52+
},
53+
{
54+
"title": "Power Function",
55+
"description": "Calculates the power of a number.",
56+
"code": [
57+
"int power(int x, int n) {",
58+
" int y = 1;",
59+
"",
60+
" for (int i = 0; i < n; i++)",
61+
" y *= x;",
62+
"",
63+
" return y;",
64+
"}"
65+
],
66+
"tags": [
67+
"c",
68+
"math",
69+
"power",
70+
"utility"
71+
],
72+
"author": "0xHouss"
73+
}
74+
]
75+
},
276
{
377
"language": "cpp",
478
"categoryName": "Basics",
@@ -748,6 +822,7 @@
748822
"console.log(countWords('Hello world! This is a test.')); // Output: 6"
749823
],
750824
"tags": [
825+
"javascript",
751826
"string",
752827
"manipulation",
753828
"word count",
@@ -767,6 +842,7 @@
767842
"console.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'"
768843
],
769844
"tags": [
845+
"javascript",
770846
"string",
771847
"whitespace"
772848
],
@@ -1461,6 +1537,7 @@
14611537
"code": [
14621538
"const debounce = (func, delay) => {",
14631539
" let timeout;",
1540+
"",
14641541
" return (...args) => {",
14651542
" clearTimeout(timeout);",
14661543
" timeout = setTimeout(() => func(...args), delay);",
@@ -1536,13 +1613,38 @@
15361613
"console.log(getContrastColor('#f4f')); // Output: #000000 (black)"
15371614
],
15381615
"tags": [
1616+
"javascript",
15391617
"color",
15401618
"hex",
15411619
"contrast",
15421620
"brightness",
15431621
"utility"
15441622
],
15451623
"author": "yaya12085"
1624+
},
1625+
{
1626+
"title": "Sleep Function",
1627+
"description": "Waits for a specified amount of milliseconds before resolving.",
1628+
"code": [
1629+
"const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));",
1630+
"",
1631+
"// Usage:",
1632+
"async function main() {",
1633+
" console.log('Hello');",
1634+
" await sleep(2000); // Waits for 2 seconds",
1635+
" console.log('World!');",
1636+
"}",
1637+
"",
1638+
"main();"
1639+
],
1640+
"tags": [
1641+
"javascript",
1642+
"sleep",
1643+
"delay",
1644+
"utility",
1645+
"promises"
1646+
],
1647+
"author": "0xHouss"
15461648
}
15471649
]
15481650
},

public/data/_index.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"lang": "CPP",
2424
"icon": "/icons/cpp.svg"
2525
},
26+
{
27+
"lang": "C",
28+
"icon": "/icons/c.svg"
29+
},
2630
{
2731
"lang": "Rust",
2832
"icon": "/icons/rust.svg"

public/data/c.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[
2+
{
3+
"categoryName": "Basics",
4+
"snippets": [
5+
{
6+
"title": "Hello, World!",
7+
"description": "Prints Hello, World! to the terminal.",
8+
"code": [
9+
"#include <stdio.h> // Includes the input/output library",
10+
"",
11+
"int main() { // Defines the main function",
12+
" printf(\"Hello, World!\\n\") // Outputs Hello, World! and a newline",
13+
"",
14+
" return 0; // indicate the program executed successfully",
15+
"}"
16+
],
17+
"tags": ["c", "printing", "hello-world", "utility"],
18+
"author": "0xHouss"
19+
}
20+
]
21+
},
22+
{
23+
"categoryName": "Mathematical Functions",
24+
"snippets": [
25+
{
26+
"title": "Factorial Function",
27+
"description": "Calculates the factorial of a number.",
28+
"code": [
29+
"int factorial(int x) {",
30+
" int y = 1;",
31+
"",
32+
" for (int i = 2; i <= x; i++)",
33+
" y *= i;",
34+
"",
35+
" return y;",
36+
"}"
37+
],
38+
"tags": ["c", "math", "factorial", "utility"],
39+
"author": "0xHouss"
40+
},
41+
{
42+
"title": "Power Function",
43+
"description": "Calculates the power of a number.",
44+
"code": [
45+
"int power(int x, int n) {",
46+
" int y = 1;",
47+
"",
48+
" for (int i = 0; i < n; i++)",
49+
" y *= x;",
50+
"",
51+
" return y;",
52+
"}"
53+
],
54+
"tags": ["c", "math", "power", "utility"],
55+
"author": "0xHouss"
56+
}
57+
]
58+
}
59+
]

public/data/javascript.json

Lines changed: 75 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"// Example usage:",
169169
"console.log(countWords('Hello world! This is a test.')); // Output: 6"
170170
],
171-
"tags": ["string", "manipulation", "word count", "count"],
171+
"tags": ["javascript", "string", "manipulation", "word count", "count"],
172172
"author": "axorax"
173173
},
174174
{
@@ -182,7 +182,7 @@
182182
"// Example usage:",
183183
"console.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'"
184184
],
185-
"tags": ["string", "whitespace"],
185+
"tags": ["javascript", "string", "whitespace"],
186186
"author": "axorax"
187187
},
188188
{
@@ -608,15 +608,7 @@
608608
"console.log(timeAgoOrAhead(new Date())); // just now",
609609
"console.log(timeAgoOrAhead(futureDate)); // in x years"
610610
],
611-
"tags": [
612-
"javascript",
613-
"date",
614-
"time",
615-
"relative",
616-
"future",
617-
"past",
618-
"utility"
619-
],
611+
"tags": ["javascript", "date", "time", "relative", "future", "past", "utility"],
620612
"author": "Yugveer06"
621613
},
622614
{
@@ -732,6 +724,7 @@
732724
"code": [
733725
"const debounce = (func, delay) => {",
734726
" let timeout;",
727+
"",
735728
" return (...args) => {",
736729
" clearTimeout(timeout);",
737730
" timeout = setTimeout(() => func(...args), delay);",
@@ -774,32 +767,49 @@
774767
"tags": ["javascript", "utility", "throttle", "performance"],
775768
"author": "dostonnabotov"
776769
},
777-
{
778-
"title": "Get Contrast Color",
779-
"description": "Returns either black or white text color based on the brightness of the provided hex color.",
780-
"code": [
781-
"const getContrastColor = (hexColor) => {",
782-
" // Expand short hex color to full format",
783-
" if (hexColor.length === 4) {",
784-
" hexColor = `#${hexColor[1]}${hexColor[1]}${hexColor[2]}${hexColor[2]}${hexColor[3]}${hexColor[3]}`;",
785-
" }",
786-
" const r = parseInt(hexColor.slice(1, 3), 16);",
787-
" const g = parseInt(hexColor.slice(3, 5), 16);",
788-
" const b = parseInt(hexColor.slice(5, 7), 16);",
789-
" const brightness = (r * 299 + g * 587 + b * 114) / 1000;",
790-
" return brightness >= 128 ? \"#000000\" : \"#FFFFFF\";",
791-
"};",
792-
"",
793-
"// Usage:",
794-
"console.log(getContrastColor('#fff')); // Output: #000000 (black)",
795-
"console.log(getContrastColor('#123456')); // Output: #FFFFFF (white)",
796-
"console.log(getContrastColor('#ff6347')); // Output: #000000 (black)",
797-
"console.log(getContrastColor('#f4f')); // Output: #000000 (black)"
798-
],
799-
"tags": ["color", "hex", "contrast", "brightness", "utility"],
800-
"author": "yaya12085"
801-
}
802-
770+
{
771+
"title": "Get Contrast Color",
772+
"description": "Returns either black or white text color based on the brightness of the provided hex color.",
773+
"code": [
774+
"const getContrastColor = (hexColor) => {",
775+
" // Expand short hex color to full format",
776+
" if (hexColor.length === 4) {",
777+
" hexColor = `#${hexColor[1]}${hexColor[1]}${hexColor[2]}${hexColor[2]}${hexColor[3]}${hexColor[3]}`;",
778+
" }",
779+
" const r = parseInt(hexColor.slice(1, 3), 16);",
780+
" const g = parseInt(hexColor.slice(3, 5), 16);",
781+
" const b = parseInt(hexColor.slice(5, 7), 16);",
782+
" const brightness = (r * 299 + g * 587 + b * 114) / 1000;",
783+
" return brightness >= 128 ? \"#000000\" : \"#FFFFFF\";",
784+
"};",
785+
"",
786+
"// Usage:",
787+
"console.log(getContrastColor('#fff')); // Output: #000000 (black)",
788+
"console.log(getContrastColor('#123456')); // Output: #FFFFFF (white)",
789+
"console.log(getContrastColor('#ff6347')); // Output: #000000 (black)",
790+
"console.log(getContrastColor('#f4f')); // Output: #000000 (black)"
791+
],
792+
"tags": ["javascript", "color", "hex", "contrast", "brightness", "utility"],
793+
"author": "yaya12085"
794+
},
795+
{
796+
"title": "Sleep Function",
797+
"description": "Waits for a specified amount of milliseconds before resolving.",
798+
"code": [
799+
"const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));",
800+
"",
801+
"// Usage:",
802+
"async function main() {",
803+
" console.log('Hello');",
804+
" await sleep(2000); // Waits for 2 seconds",
805+
" console.log('World!');",
806+
"}",
807+
"",
808+
"main();"
809+
],
810+
"tags": ["javascript", "sleep", "delay", "utility", "promises"],
811+
"author": "0xHouss"
812+
}
803813
]
804814
},
805815
{
@@ -886,32 +896,31 @@
886896
}
887897
]
888898
},
889-
{
890-
"categoryName": "Number Formatting",
891-
"snippets": [
892-
{
893-
"title": "Number Formatter",
894-
"description": "Formats a number with suffixes (K, M, B, etc.).",
895-
"code": [
896-
"const nFormatter = (num) => {",
897-
" if (!num) return;",
898-
" num = parseFloat(num.toString().replace(/[^0-9.]/g, ''));",
899-
" const suffixes = ['', 'K', 'M', 'B', 'T', 'P', 'E'];",
900-
" let index = 0;",
901-
" while (num >= 1000 && index < suffixes.length - 1) {",
902-
" num /= 1000;",
903-
" index++;",
904-
" }",
905-
" return num.toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + suffixes[index];",
906-
"};",
907-
"",
908-
"// Usage:",
909-
"console.log(nFormatter(1234567)); // Output: '1.23M'"
910-
],
911-
"tags": ["javascript", "number", "format", "utility"],
912-
"author": "realvishalrana"
913-
}
914-
]
915-
}
916-
917-
]
899+
{
900+
"categoryName": "Number Formatting",
901+
"snippets": [
902+
{
903+
"title": "Number Formatter",
904+
"description": "Formats a number with suffixes (K, M, B, etc.).",
905+
"code": [
906+
"const nFormatter = (num) => {",
907+
" if (!num) return;",
908+
" num = parseFloat(num.toString().replace(/[^0-9.]/g, ''));",
909+
" const suffixes = ['', 'K', 'M', 'B', 'T', 'P', 'E'];",
910+
" let index = 0;",
911+
" while (num >= 1000 && index < suffixes.length - 1) {",
912+
" num /= 1000;",
913+
" index++;",
914+
" }",
915+
" return num.toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + suffixes[index];",
916+
"};",
917+
"",
918+
"// Usage:",
919+
"console.log(nFormatter(1234567)); // Output: '1.23M'"
920+
],
921+
"tags": ["javascript", "number", "format", "utility"],
922+
"author": "realvishalrana"
923+
}
924+
]
925+
}
926+
]

0 commit comments

Comments
 (0)