Skip to content

Added support for regex snippets #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 4, 2025
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/consolidated/_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"lang": "PYTHON",
"icon": "/icons/python.svg"
},
{
"lang": "REGEX",
"icon": "/icons/regex.svg"
},
{
"lang": "RUST",
"icon": "/icons/rust.svg"
Expand Down
17 changes: 17 additions & 0 deletions public/consolidated/cpp.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"
}
]
},
{
"categoryName": "Math And Numbers",
"snippets": [
Expand Down
18 changes: 6 additions & 12 deletions public/consolidated/javascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
74 changes: 74 additions & 0 deletions public/consolidated/regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"categoryName": "Miscellaneous",
"snippets": [
{
"title": "Hexadecimal Color",
"description": "Matches hex color codes",
"author": "majvax",
"tags": [
"color",
"hexadecimal"
],
"contributors": [],
"code": "^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$\n\n\n-> Usage:\n#FFF1 βœ—\n#FFF βœ“\n#FFF000 βœ“\n"
},
{
"title": "IPv4",
"description": "Matches IPv4 address",
"author": "majvax",
"tags": [
"ipv4",
"networking"
],
"contributors": [],
"code": "^((25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})\\.){3}(25[0-5]|2[0-4]\\d|1\\d{2}|\\d{1,2})$\n\n\n-> Usage:\n123.300.0.101 βœ—\n127.0.0.1 βœ“\n192.168.0.1 βœ“\n"
},
{
"title": "Unintentional Duplication",
"description": "Matches duplicated word in a text.",
"author": "majvax",
"tags": [
"duplication"
],
"contributors": [],
"code": "\\b(\\w+)\\s+\\1\\b\n\n\n-> Usage:\nI need to finish this task βœ—\nI need to to finish this task βœ“\n"
},
{
"title": "Whitespace Trimmer",
"description": "Matches leading and/or trailing whitespace.",
"author": "majvax",
"tags": [
"trim"
],
"contributors": [],
"code": "^\\s+|\\s+$\n\n\n-> Usage:\n(don't account for the quotation marks, it just to visualize whitespace)\n\"Hello World\" βœ—\n\" Hello World\" βœ“\n\"Hello World \" βœ“\n\" Hello World \" βœ“\n"
}
]
},
{
"categoryName": "Validation pattern",
"snippets": [
{
"title": "Email Address",
"description": "Match any email address",
"author": "majvax",
"tags": [
"email"
],
"contributors": [],
"code": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$\n\n-> Usage:\nexample.name@domain.com.ru βœ“\nname.surname@gmail.com βœ“\n"
},
{
"title": "Strong Password",
"description": "Match password with at least 12 characters, one uppercased letter, one number, and one special character.",
"author": "majvax",
"tags": [
"password"
],
"contributors": [],
"code": "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{12,}$\n\n-> Usage:\nlongpassword βœ—\nlongpassw0rd βœ—\nlongp@ssw0rd βœ—\nLongp@ssw0rd βœ“\n"
}
]
}
]
6 changes: 6 additions & 0 deletions public/icons/regex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions snippets/regex/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions snippets/regex/miscellaneous/hexadecimal-color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
Title: Hexadecimal Color
Description: Matches hex color codes
Author: majvax
Tags: color,hexadecimal
---


```regex
^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$


-> Usage:
#FFF1 βœ—
#FFF βœ“
#FFF000 βœ“
```
17 changes: 17 additions & 0 deletions snippets/regex/miscellaneous/ipv4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
Title: IPv4
Description: Matches IPv4 address
Author: majvax
Tags: ipv4,networking
---


```regex
^((25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})\.){3}(25[0-5]|2[0-4]\d|1\d{2}|\d{1,2})$


-> Usage:
123.300.0.101 βœ—
127.0.0.1 βœ“
192.168.0.1 βœ“
```
16 changes: 16 additions & 0 deletions snippets/regex/miscellaneous/unintentional-duplication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
Title: Unintentional Duplication
Description: Matches duplicated word in a text.
Author: majvax
Tags: duplication
---


```regex
\b(\w+)\s+\1\b


-> Usage:
I need to finish this task βœ—
I need to to finish this task βœ“
```
19 changes: 19 additions & 0 deletions snippets/regex/miscellaneous/whitespace-trimmer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
Title: Whitespace Trimmer
Description: Matches leading and/or trailing whitespace.
Author: majvax
Tags: trim
---


```regex
^\s+|\s+$


-> Usage:
(don't account for the quotation marks, it just to visualize whitespace)
"Hello World" βœ—
" Hello World" βœ“
"Hello World " βœ“
" Hello World " βœ“
```
15 changes: 15 additions & 0 deletions snippets/regex/validation pattern/email-address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
Title: Email Address
Description: Match any email address
Author: majvax
Tags: email
---


```regex
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

-> Usage:
example.name@domain.com.ru βœ“
name.surname@gmail.com βœ“
```
17 changes: 17 additions & 0 deletions snippets/regex/validation pattern/strong-password.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
Title: Strong Password
Description: Match password with at least 12 characters, one uppercased letter, one number, and one special character.
Author: majvax
Tags: password
---


```regex
^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,}$

-> Usage:
longpassword βœ—
longpassw0rd βœ—
longp@ssw0rd βœ—
Longp@ssw0rd βœ“
```