diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e0a9d686..5fc28481 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -7,7 +7,7 @@ /src/ @psychlone77 @saminjay # Snippets maintainers -/public/data @Mathys-Gasnier +/snippets @Mathys-Gasnier # ---------- What is a maintainer ---------- diff --git a/.github/workflows/check-snippets.yml b/.github/workflows/check-snippets.yml new file mode 100644 index 00000000..5fb67bd7 --- /dev/null +++ b/.github/workflows/check-snippets.yml @@ -0,0 +1,23 @@ +name: Checks snippets syntax + +on: + pull_request: + paths: + - 'snippets/**' + +jobs: + check-snippets: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "16" + + - name: Check if snippets are formated correctly + run: | + node utils/checkSnippetFormatting.js # Run the script located in the utils/ folder diff --git a/.github/workflows/consolidate-snippets.yml b/.github/workflows/consolidate-snippets.yml index a95f7780..507a51bd 100644 --- a/.github/workflows/consolidate-snippets.yml +++ b/.github/workflows/consolidate-snippets.yml @@ -3,7 +3,7 @@ name: Consolidate JSON Files on: push: paths: - - "public/data/**" + - "snippets/**" permissions: contents: write @@ -25,14 +25,14 @@ jobs: run: | npm install - - name: Consolidate JSON files + - name: Consolidate Snippets run: | - node utils/consolidate.js # Run the script located in the utils/ folder + node utils/consolidateSnippets.js # Run the script located in the utils/ folder - name: Commit and push changes run: | git config --global user.name "GitHub Action" git config --global user.email "action@github.com" - git add public/consolidated/all_snippets.json + git add public/consolidated/* git commit -m "Update consolidated snippets" git push diff --git a/public/data/_index.json b/public/consolidated/_index.json similarity index 100% rename from public/data/_index.json rename to public/consolidated/_index.json diff --git a/public/consolidated/all_snippets.json b/public/consolidated/all_snippets.json deleted file mode 100644 index f49d955d..00000000 --- a/public/consolidated/all_snippets.json +++ /dev/null @@ -1,2557 +0,0 @@ -[ - { - "language": "c", - "categoryName": "Basics", - "snippets": [ - { - "title": "Hello, World!", - "description": "Prints Hello, World! to the terminal.", - "author": "0xHouss", - "tags": [ - "c", - "printing", - "hello-world", - "utility" - ], - "contributors": [], - "code": "#include // Includes the input/output library\n\nint main() { // Defines the main function\n printf(\"Hello, World!\\n\") // Outputs Hello, World! and a newline\n\n return 0; // indicate the program executed successfully\n}\n" - } - ] - }, - { - "language": "c", - "categoryName": "Mathematical Functions", - "snippets": [ - { - "title": "Factorial Function", - "description": "Calculates the factorial of a number.", - "author": "0xHouss", - "tags": [ - "c", - "math", - "factorial", - "utility" - ], - "contributors": [], - "code": "int factorial(int x) {\n int y = 1;\n\n for (int i = 2; i <= x; i++)\n y *= i;\n\n return y;\n}\n" - }, - { - "title": "Power Function", - "description": "Calculates the power of a number.", - "author": "0xHouss", - "tags": [ - "c", - "math", - "power", - "utility" - ], - "contributors": [], - "code": "int power(int x, int n) {\n int y = 1;\n\n for (int i = 0; i < n; i++)\n y *= x;\n\n return y;\n}\n" - } - ] - }, - { - "language": "cpp", - "categoryName": "Basics", - "snippets": [ - { - "title": "Hello, World!", - "description": "Prints Hello, World! to the terminal.", - "author": "James-Beans", - "tags": [ - "cpp", - "printing", - "hello-world", - "utility" - ], - "contributors": [], - "code": "#include // Includes the input/output stream library\n\nint main() { // Defines the main function\n std::cout << \"Hello, World!\" << std::endl; // Outputs Hello, World! and a newline\n return 0; // indicate the program executed successfully\n}\n" - } - ] - }, - { - "language": "cpp", - "categoryName": "String Manipulation", - "snippets": [ - { - "title": "Reverse String", - "description": "Reverses the characters in a string.", - "author": "Vaibhav-kesarwani", - "tags": [ - "cpp", - "array", - "reverse", - "utility" - ], - "contributors": [], - "code": "#include \n#include \n\nstd::string reverseString(const std::string& input) {\n std::string reversed = input;\n std::reverse(reversed.begin(), reversed.end());\n return reversed;\n}\n" - }, - { - "title": "Split String", - "description": "Splits a string by a delimiter", - "author": "saminjay", - "tags": [ - "cpp", - "string", - "split", - "utility" - ], - "contributors": [], - "code": "#include \n#include \n\nstd::vector split_string(std::string str, std::string delim) {\n std::vector splits;\n int i = 0, j;\n int inc = delim.length();\n while (j != std::string::npos) {\n j = str.find(delim, i);\n splits.push_back(str.substr(i, j - i));\n i = j + inc;\n }\n return splits;\n}\n" - } - ] - }, - { - "language": "css", - "categoryName": "Buttons", - "snippets": [ - { - "title": "3D Button Effect", - "description": "Adds a 3D effect to a button when clicked.", - "author": "dostonnabotov", - "tags": [ - "css", - "button", - "3D", - "effect" - ], - "contributors": [], - "code": ".button {\n background-color: #28a745;\n color: white;\n padding: 10px 20px;\n border: none;\n border-radius: 5px;\n box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);\n transition: transform 0.1s;\n}\n\n.button:active {\n transform: translateY(2px);\n box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);\n}\n" - }, - { - "title": "Button Hover Effect", - "description": "Creates a hover effect with a color transition.", - "author": "dostonnabotov", - "tags": [ - "css", - "button", - "hover", - "transition" - ], - "contributors": [], - "code": ".button {\n background-color: #007bff;\n color: white;\n padding: 10px 20px;\n border: none;\n border-radius: 5px;\n cursor: pointer;\n transition: background-color 0.3s ease;\n}\n\n.button:hover {\n background-color: #0056b3;\n}\n" - }, - { - "title": "MacOS Button", - "description": "A macOS-like button style, with hover and shading effects.", - "author": "e3nviction", - "tags": [ - "css", - "button", - "macos", - "hover", - "transition" - ], - "contributors": [], - "code": ".button {\n font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,;\n background: #0a85ff;\n color: #fff;\n padding: 8px 12px;\n border: none;\n margin: 4px;\n border-radius: 10px;\n cursor: pointer;\n box-shadow: inset 0 1px 1px #fff2, 0px 2px 3px -2px rgba(0, 0, 0, 0.3) !important; /*This is really performance heavy*/\n font-size: 14px;\n display: flex;\n align-items: center;\n justify-content: center;\n text-decoration: none;\n transition: all 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275);\n}\n.button:hover {\n background: #0974ee;\n color: #fff\n}\n" - } - ] - }, - { - "language": "css", - "categoryName": "Effects", - "snippets": [ - { - "title": "Blur Background", - "description": "Applies a blur effect to the background of an element.", - "author": "dostonnabotov", - "tags": [ - "css", - "blur", - "background", - "effects" - ], - "contributors": [], - "code": ".blur-background {\n backdrop-filter: blur(10px);\n background: rgba(255, 255, 255, 0.5);\n}\n" - }, - { - "title": "Hover Glow Effect", - "description": "Adds a glowing effect on hover.", - "author": "dostonnabotov", - "tags": [ - "css", - "hover", - "glow", - "effects" - ], - "contributors": [], - "code": ".glow {\n background-color: #f39c12;\n padding: 10px 20px;\n border-radius: 5px;\n transition: box-shadow 0.3s ease;\n}\n\n.glow:hover {\n box-shadow: 0 0 15px rgba(243, 156, 18, 0.8);\n}\n" - }, - { - "title": "Hover to Reveal Color", - "description": "A card with an image that transitions from grayscale to full color on hover.", - "author": "Haider-Mukhtar", - "tags": [ - "css", - "hover", - "image", - "effects" - ], - "contributors": [], - "code": ".card {\n height: 300px;\n width: 200px;\n border-radius: 5px;\n overflow: hidden;\n}\n\n.card img{\n height: 100%;\n width: 100%;\n object-fit: cover;\n filter: grayscale(100%);\n transition: all 0.3s;\n transition-duration: 200ms;\n cursor: pointer;\n}\n\n.card:hover img {\n filter: grayscale(0%);\n scale: 1.05;\n}\n" - } - ] - }, - { - "language": "css", - "categoryName": "Layouts", - "snippets": [ - { - "title": "CSS Reset", - "description": "Resets some default browser styles, ensuring consistency across browsers.", - "author": "AmeerMoustafa", - "tags": [ - "css", - "reset", - "browser", - "layout" - ], - "contributors": [], - "code": "* {\n margin: 0;\n padding: 0;\n box-sizing: border-box\n}\n" - }, - { - "title": "Equal-Width Columns", - "description": "Creates columns with equal widths using flexbox.", - "author": "dostonnabotov", - "tags": [ - "css", - "flexbox", - "columns", - "layout" - ], - "contributors": [], - "code": ".columns {\n display: flex;\n justify-content: space-between;\n}\n\n.column {\n flex: 1;\n margin: 0 10px;\n}\n" - }, - { - "title": "Grid layout", - "description": "Equal sized items in a responsive grid", - "author": "xshubhamg", - "tags": [ - "css", - "layout", - "grid" - ], - "contributors": [], - "code": ".grid-container {\n display: grid\n grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));\n/* Explanation:\n- `auto-fit`: Automatically fits as many columns as possible within the container.\n- `minmax(250px, 1fr)`: Defines a minimum column size of 250px and a maximum size of 1fr (fraction of available space).\n*/\n}\n" - }, - { - "title": "Responsive Design", - "description": "The different responsive breakpoints.", - "author": "kruimol", - "tags": [ - "css", - "responsive" - ], - "contributors": [], - "code": "/* Phone */\n.element {\n margin: 0 10%\n}\n\n/* Tablet */\n@media (min-width: 640px) {\n .element {\n margin: 0 20%\n }\n}\n\n/* Desktop base */\n@media (min-width: 768px) {\n .element {\n margin: 0 30%\n }\n}\n\n/* Desktop large */\n@media (min-width: 1024px) {\n .element {\n margin: 0 40%\n }\n}\n\n/* Desktop extra large */\n@media (min-width: 1280px) {\n .element {\n margin: 0 60%\n }\n}\n\n/* Desktop bige */\n@media (min-width: 1536px) {\n .element {\n margin: 0 80%\n }\n}\n" - }, - { - "title": "Sticky Footer", - "description": "Ensures the footer always stays at the bottom of the page.", - "author": "dostonnabotov", - "tags": [ - "css", - "layout", - "footer", - "sticky" - ], - "contributors": [], - "code": "body {\n display: flex;\n flex-direction: column;\n min-height: 100vh;\n}\n\nfooter {\n margin-top: auto;\n}\n" - } - ] - }, - { - "language": "css", - "categoryName": "Typography", - "snippets": [ - { - "title": "Letter Spacing", - "description": "Adds space between letters for better readability.", - "author": "dostonnabotov", - "tags": [ - "css", - "typography", - "spacing" - ], - "contributors": [], - "code": "p {\n letter-spacing: 0.05em;\n}\n" - }, - { - "title": "Responsive Font Sizing", - "description": "Adjusts font size based on viewport width.", - "author": "dostonnabotov", - "tags": [ - "css", - "font", - "responsive", - "typography" - ], - "contributors": [], - "code": "h1 {\n font-size: calc(1.5rem + 2vw);\n}\n" - } - ] - }, - { - "language": "html", - "categoryName": "Basic Layouts", - "snippets": [ - { - "title": "Grid Layout with Navigation", - "description": "Full-height grid layout with header navigation using nesting syntax.", - "author": "GreenMan36", - "tags": [ - "html", - "css", - "layout", - "sticky", - "grid", - "full-height" - ], - "contributors": [], - "code": "\n\n \n \n \n \n
\n Header\n \n
\n
Main Content
\n
Footer
\n \n\n" - }, - { - "title": "Sticky Header-Footer Layout", - "description": "Full-height layout with sticky header and footer, using modern viewport units and flexbox.", - "author": "GreenMan36", - "tags": [ - "html", - "css", - "layout", - "sticky", - "flexbox", - "viewport" - ], - "contributors": [], - "code": "\n\n \n \n \n \n
header
\n
body/content
\n
footer
\n \n\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Array Manipulation", - "snippets": [ - { - "title": "Flatten Array", - "description": "Flattens a multi-dimensional array.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "array", - "flatten", - "utility" - ], - "contributors": [], - "code": "const flattenArray = (arr) => arr.flat(Infinity);\n\n// Usage:\nconst nestedArray = [1, [2, [3, [4]]]];\nconsole.log(flattenArray(nestedArray)); // Output: [1, 2, 3, 4]\n" - }, - { - "title": "Remove Duplicates", - "description": "Removes duplicate values from an array.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "array", - "deduplicate", - "utility" - ], - "contributors": [], - "code": "const removeDuplicates = (arr) => [...new Set(arr)];\n\n// Usage:\nconst numbers = [1, 2, 2, 3, 4, 4, 5];\nconsole.log(removeDuplicates(numbers)); // Output: [1, 2, 3, 4, 5]\n" - }, - { - "title": "Shuffle Array", - "description": "Shuffles an Array.", - "author": "loxt-nixo", - "tags": [ - "javascript", - "array", - "shuffle", - "utility" - ], - "contributors": [], - "code": "function shuffleArray(array) {\n for (let i = array.length - 1; i >= 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [array[i], array[j]] = [array[j], array[i]];\n }\n}\n" - }, - { - "title": "Zip Arrays", - "description": "Combines two arrays by pairing corresponding elements from each array.", - "author": "Swaraj-Singh-30", - "tags": [ - "javascript", - "array", - "utility", - "map" - ], - "contributors": [], - "code": "const zip = (arr1, arr2) => arr1.map((value, index) => [value, arr2[index]]);\n\n// Usage:\nconst arr1 = ['a', 'b', 'c'];\nconst arr2 = [1, 2, 3];\nconsole.log(zip(arr1, arr2)); // Output: [['a', 1], ['b', 2], ['c', 3]]\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Basics", - "snippets": [ - { - "title": "Hello, World!", - "description": "Prints Hello, World! to the terminal.", - "author": "James-Beans", - "tags": [ - "javascript", - "printing", - "hello-world", - "utility" - ], - "contributors": [], - "code": "console.log(\"Hello, World!\"); // Prints Hello, World! to the console\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Date And Time", - "snippets": [ - { - "title": "Add Days to a Date", - "description": "Adds a specified number of days to a given date.", - "author": "axorax", - "tags": [ - "javascript", - "date", - "add-days", - "utility" - ], - "contributors": [], - "code": "const addDays = (date, days) => {\n const result = new Date(date);\n result.setDate(result.getDate() + days);\n return result;\n};\n\n// Usage:\nconst today = new Date();\nconsole.log(addDays(today, 10)); // Output: Date object 10 days ahead\n" - }, - { - "title": "Check Leap Year", - "description": "Determines if a given year is a leap year.", - "author": "axorax", - "tags": [ - "javascript", - "date", - "leap-year", - "utility" - ], - "contributors": [], - "code": "const isLeapYear = (year) => (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n\n// Usage:\nconsole.log(isLeapYear(2024)); // Output: true\nconsole.log(isLeapYear(2023)); // Output: false\n" - }, - { - "title": "Convert to Unix Timestamp", - "description": "Converts a date to a Unix timestamp in seconds.", - "author": "Yugveer06", - "tags": [ - "javascript", - "date", - "unix", - "timestamp", - "utility" - ], - "contributors": [], - "code": "/**\n * Converts a date string or Date object to Unix timestamp in seconds.\n *\n * @param {string|Date} input - A valid date string or Date object.\n * @returns {number} - The Unix timestamp in seconds.\n * @throws {Error} - Throws an error if the input is invalid.\n */\nfunction convertToUnixSeconds(input) {\n if (typeof input === 'string') {\n if (!input.trim()) {\n throw new Error('Date string cannot be empty or whitespace');\n }\n } else if (!input) {\n throw new Error('Input is required');\n }\n\n let date;\n\n if (typeof input === 'string') {\n date = new Date(input);\n } else if (input instanceof Date) {\n date = input;\n } else {\n throw new Error('Input must be a valid date string or Date object');\n }\n\n if (isNaN(date.getTime())) {\n throw new Error('Invalid date provided');\n }\n\n return Math.floor(date.getTime() / 1000);\n}\n\n// Usage\nconsole.log(convertToUnixSeconds('2025-01-01T12:00:00Z')); // 1735732800\nconsole.log(convertToUnixSeconds(new Date('2025-01-01T12:00:00Z'))); // 1735732800\nconsole.log(convertToUnixSeconds(new Date())); //Current Unix timestamp in seconds (varies depending on execution time)\n" - }, - { - "title": "Format Date", - "description": "Formats a date in 'YYYY-MM-DD' format.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "date", - "format", - "utility" - ], - "contributors": [], - "code": "const formatDate = (date) => date.toISOString().split('T')[0];\n\n// Usage:\nconsole.log(formatDate(new Date())); // Output: '2024-12-10'\n" - }, - { - "title": "Get Current Timestamp", - "description": "Retrieves the current timestamp in milliseconds since January 1, 1970.", - "author": "axorax", - "tags": [ - "javascript", - "date", - "timestamp", - "utility" - ], - "contributors": [], - "code": "const getCurrentTimestamp = () => Date.now();\n\n// Usage:\nconsole.log(getCurrentTimestamp()); // Output: 1691825935839 (example)\n" - }, - { - "title": "Get Day of the Year", - "description": "Calculates the day of the year (1-365 or 1-366 for leap years) for a given date.", - "author": "axorax", - "tags": [ - "javascript", - "date", - "day-of-year", - "utility" - ], - "contributors": [], - "code": "const getDayOfYear = (date) => {\n const startOfYear = new Date(date.getFullYear(), 0, 0);\n const diff = date - startOfYear + (startOfYear.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000;\n return Math.floor(diff / (1000 * 60 * 60 * 24));\n};\n\n// Usage:\nconst today = new Date('2024-12-31');\nconsole.log(getDayOfYear(today)); // Output: 366 (in a leap year)\n" - }, - { - "title": "Get Days in Month", - "description": "Calculates the number of days in a specific month of a given year.", - "author": "axorax", - "tags": [ - "javascript", - "date", - "days-in-month", - "utility" - ], - "contributors": [], - "code": "const getDaysInMonth = (year, month) => new Date(year, month + 1, 0).getDate();\n\n// Usage:\nconsole.log(getDaysInMonth(2024, 1)); // Output: 29 (February in a leap year)\nconsole.log(getDaysInMonth(2023, 1)); // Output: 28\n" - }, - { - "title": "Get Time Difference", - "description": "Calculates the time difference in days between two dates.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "date", - "time-difference", - "utility" - ], - "contributors": [], - "code": "const getTimeDifference = (date1, date2) => {\n const diff = Math.abs(date2 - date1);\n return Math.ceil(diff / (1000 * 60 * 60 * 24));\n};\n\n// Usage:\nconst date1 = new Date('2024-01-01');\nconst date2 = new Date('2024-12-31');\nconsole.log(getTimeDifference(date1, date2)); // Output: 365\n" - }, - { - "title": "Relative Time Formatter", - "description": "Displays how long ago a date occurred or how far in the future a date is.", - "author": "Yugveer06", - "tags": [ - "javascript", - "date", - "time", - "relative", - "future", - "past", - "utility" - ], - "contributors": [], - "code": "const getRelativeTime = (date) => {\n const now = Date.now();\n const diff = date.getTime() - now;\n const seconds = Math.abs(Math.floor(diff / 1000));\n const minutes = Math.abs(Math.floor(seconds / 60));\n const hours = Math.abs(Math.floor(minutes / 60));\n const days = Math.abs(Math.floor(hours / 24));\n const years = Math.abs(Math.floor(days / 365));\n\n if (Math.abs(diff) < 1000) return 'just now';\n\n const isFuture = diff > 0;\n\n if (years > 0) return `${isFuture ? 'in ' : ''}${years} ${years === 1 ? 'year' : 'years'}${isFuture ? '' : ' ago'}`;\n if (days > 0) return `${isFuture ? 'in ' : ''}${days} ${days === 1 ? 'day' : 'days'}${isFuture ? '' : ' ago'}`;\n if (hours > 0) return `${isFuture ? 'in ' : ''}${hours} ${hours === 1 ? 'hour' : 'hours'}${isFuture ? '' : ' ago'}`;\n if (minutes > 0) return `${isFuture ? 'in ' : ''}${minutes} ${minutes === 1 ? 'minute' : 'minutes'}${isFuture ? '' : ' ago'}`;\n\n return `${isFuture ? 'in ' : ''}${seconds} ${seconds === 1 ? 'second' : 'seconds'}${isFuture ? '' : ' ago'}`;\n}\n\n// usage\nconst pastDate = new Date('2021-12-29 13:00:00');\nconst futureDate = new Date('2026-12-29 13:00:00');\nconsole.log(getRelativeTime(pastDate)); // x years ago\nconsole.log(getRelativeTime(new Date())); // just now\nconsole.log(getRelativeTime(futureDate)); // in x years\n" - }, - { - "title": "Start of the Day", - "description": "Returns the start of the day (midnight) for a given date.", - "author": "axorax", - "tags": [ - "javascript", - "date", - "start-of-day", - "utility" - ], - "contributors": [], - "code": "const startOfDay = (date) => new Date(date.setHours(0, 0, 0, 0));\n\n// Usage:\nconst today = new Date();\nconsole.log(startOfDay(today)); // Output: Date object for midnight\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Dom Manipulation", - "snippets": [ - { - "title": "Change Element Style", - "description": "Changes the inline style of an element.", - "author": "axorax", - "tags": [ - "javascript", - "dom", - "style", - "utility" - ], - "contributors": [], - "code": "const changeElementStyle = (element, styleObj) => {\n Object.entries(styleObj).forEach(([property, value]) => {\n element.style[property] = value;\n });\n};\n\n// Usage:\nconst element = document.querySelector('.my-element');\nchangeElementStyle(element, { color: 'red', backgroundColor: 'yellow' });\n" - }, - { - "title": "Get Element Position", - "description": "Gets the position of an element relative to the viewport.", - "author": "axorax", - "tags": [ - "javascript", - "dom", - "position", - "utility" - ], - "contributors": [], - "code": "const getElementPosition = (element) => {\n const rect = element.getBoundingClientRect();\n return { x: rect.left, y: rect.top };\n};\n\n// Usage:\nconst element = document.querySelector('.my-element');\nconst position = getElementPosition(element);\nconsole.log(position); // { x: 100, y: 150 }\n" - }, - { - "title": "Remove Element", - "description": "Removes a specified element from the DOM.", - "author": "axorax", - "tags": [ - "javascript", - "dom", - "remove", - "utility" - ], - "contributors": [], - "code": "const removeElement = (element) => {\n if (element && element.parentNode) {\n element.parentNode.removeChild(element);\n }\n};\n\n// Usage:\nconst element = document.querySelector('.my-element');\nremoveElement(element);\n" - }, - { - "title": "Smooth Scroll to Element", - "description": "Scrolls smoothly to a specified element.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "dom", - "scroll", - "ui" - ], - "contributors": [], - "code": "const smoothScroll = (element) => {\n element.scrollIntoView({ behavior: 'smooth' });\n};\n\n// Usage:\nconst target = document.querySelector('#target');\nsmoothScroll(target);\n" - }, - { - "title": "Toggle Class", - "description": "Toggles a class on an element.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "dom", - "class", - "utility" - ], - "contributors": [], - "code": "const toggleClass = (element, className) => {\n element.classList.toggle(className);\n};\n\n// Usage:\nconst element = document.querySelector('.my-element');\ntoggleClass(element, 'active');\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Function Utilities", - "snippets": [ - { - "title": "Compose Functions", - "description": "Composes multiple functions into a single function, where the output of one function becomes the input of the next.", - "author": "axorax", - "tags": [ - "javascript", - "function", - "compose", - "utility" - ], - "contributors": [], - "code": "const compose = (...funcs) => (initialValue) => {\n return funcs.reduce((acc, func) => func(acc), initialValue);\n};\n\n// Usage:\nconst add2 = (x) => x + 2;\nconst multiply3 = (x) => x * 3;\nconst composed = compose(multiply3, add2);\nconsole.log(composed(5)); // Output: 21 ((5 + 2) * 3)\n" - }, - { - "title": "Curry Function", - "description": "Transforms a function into its curried form.", - "author": "axorax", - "tags": [ - "javascript", - "curry", - "function", - "utility" - ], - "contributors": [], - "code": "const curry = (func) => {\n const curried = (...args) => {\n if (args.length >= func.length) {\n return func(...args);\n }\n return (...nextArgs) => curried(...args, ...nextArgs);\n };\n return curried;\n};\n\n// Usage:\nconst add = (a, b, c) => a + b + c;\nconst curriedAdd = curry(add);\nconsole.log(curriedAdd(1)(2)(3)); // Output: 6\nconsole.log(curriedAdd(1, 2)(3)); // Output: 6\n" - }, - { - "title": "Debounce Function", - "description": "Delays a function execution until after a specified time.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "utility", - "debounce", - "performance" - ], - "contributors": [], - "code": "const debounce = (func, delay) => {\n let timeout;\n\n return (...args) => {\n clearTimeout(timeout);\n timeout = setTimeout(() => func(...args), delay);\n };\n};\n\n// Usage:\nwindow.addEventListener('resize', debounce(() => console.log('Resized!'), 500));\n" - }, - { - "title": "Get Contrast Color", - "description": "Returns either black or white text color based on the brightness of the provided hex color.", - "author": "yaya12085", - "tags": [ - "javascript", - "color", - "hex", - "contrast", - "brightness", - "utility" - ], - "contributors": [], - "code": "const getContrastColor = (hexColor) => {\n // Expand short hex color to full format\n if (hexColor.length === 4) {\n hexColor = `#${hexColor[1]}${hexColor[1]}${hexColor[2]}${hexColor[2]}${hexColor[3]}${hexColor[3]}`;\n }\n const r = parseInt(hexColor.slice(1, 3), 16);\n const g = parseInt(hexColor.slice(3, 5), 16);\n const b = parseInt(hexColor.slice(5, 7), 16);\n const brightness = (r * 299 + g * 587 + b * 114) / 1000;\n return brightness >= 128 ? \"#000000\" : \"#FFFFFF\";\n};\n\n// Usage:\nconsole.log(getContrastColor('#fff')); // Output: #000000 (black)\nconsole.log(getContrastColor('#123456')); // Output: #FFFFFF (white)\nconsole.log(getContrastColor('#ff6347')); // Output: #000000 (black)\nconsole.log(getContrastColor('#f4f')); // Output: #000000 (black)\n" - }, - { - "title": "Memoize Function", - "description": "Caches the result of a function based on its arguments to improve performance.", - "author": "axorax", - "tags": [ - "javascript", - "memoization", - "optimization", - "utility" - ], - "contributors": [], - "code": "const memoize = (func) => {\n const cache = new Map();\n return (...args) => {\n const key = JSON.stringify(args);\n if (cache.has(key)) {\n return cache.get(key);\n }\n const result = func(...args);\n cache.set(key, result);\n return result;\n };\n};\n\n// Usage:\nconst factorial = memoize((n) => (n <= 1 ? 1 : n * factorial(n - 1)));\nconsole.log(factorial(5)); // Output: 120\nconsole.log(factorial(5)); // Output: 120 (retrieved from cache)\n" - }, - { - "title": "Once Function", - "description": "Ensures a function is only called once.", - "author": "axorax", - "tags": [ - "javascript", - "function", - "once", - "utility" - ], - "contributors": [], - "code": "const once = (func) => {\n let called = false;\n return (...args) => {\n if (!called) {\n called = true;\n return func(...args);\n }\n };\n};\n\n// Usage:\nconst initialize = once(() => console.log('Initialized!'));\ninitialize(); // Output: Initialized!\ninitialize(); // No output\n" - }, - { - "title": "Rate Limit Function", - "description": "Limits how often a function can be executed within a given time window.", - "author": "axorax", - "tags": [ - "javascript", - "function", - "rate-limiting", - "utility" - ], - "contributors": [], - "code": "const rateLimit = (func, limit, timeWindow) => {\n let queue = [];\n setInterval(() => {\n if (queue.length) {\n const next = queue.shift();\n func(...next.args);\n }\n }, timeWindow);\n return (...args) => {\n if (queue.length < limit) {\n queue.push({ args });\n }\n };\n};\n\n// Usage:\nconst fetchData = () => console.log('Fetching data...');\nconst rateLimitedFetch = rateLimit(fetchData, 2, 1000);\nsetInterval(() => rateLimitedFetch(), 200); // Only calls fetchData twice every second\n" - }, - { - "title": "Repeat Function Invocation", - "description": "Invokes a function a specified number of times.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "function", - "repeat", - "utility" - ], - "contributors": [], - "code": "const times = (func, n) => {\n Array.from(Array(n)).forEach(() => {\n func();\n });\n};\n\n// Usage:\nconst randomFunction = () => console.log('Function called!');\ntimes(randomFunction, 3); // Logs 'Function called!' three times\n" - }, - { - "title": "Sleep Function", - "description": "Waits for a specified amount of milliseconds before resolving.", - "author": "0xHouss", - "tags": [ - "javascript", - "sleep", - "delay", - "utility", - "promises" - ], - "contributors": [], - "code": "const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));\n\n// Usage:\nasync function main() {\n console.log('Hello');\n await sleep(2000); // Waits for 2 seconds\n console.log('World!');\n}\n\nmain();\n" - }, - { - "title": "Throttle Function", - "description": "Limits a function execution to once every specified time interval.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "utility", - "throttle", - "performance" - ], - "contributors": [], - "code": "const throttle = (func, limit) => {\n let lastFunc;\n let lastRan;\n return (...args) => {\n const context = this;\n if (!lastRan) {\n func.apply(context, args);\n lastRan = Date.now();\n } else {\n clearTimeout(lastFunc);\n lastFunc = setTimeout(() => {\n if (Date.now() - lastRan >= limit) {\n func.apply(context, args);\n lastRan = Date.now();\n }\n }, limit - (Date.now() - lastRan));\n }\n };\n};\n\n// Usage:\ndocument.addEventListener('scroll', throttle(() => console.log('Scrolled!'), 1000));\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Local Storage", - "snippets": [ - { - "title": "Add Item to localStorage", - "description": "Stores a value in localStorage under the given key.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "localStorage", - "storage", - "utility" - ], - "contributors": [], - "code": "const addToLocalStorage = (key, value) => {\n localStorage.setItem(key, JSON.stringify(value));\n};\n\n// Usage:\naddToLocalStorage('user', { name: 'John', age: 30 });\n" - }, - { - "title": "Check if Item Exists in localStorage", - "description": "Checks if a specific item exists in localStorage.", - "author": "axorax", - "tags": [ - "javascript", - "localStorage", - "storage", - "utility" - ], - "contributors": [], - "code": "const isItemInLocalStorage = (key) => {\n return localStorage.getItem(key) !== null;\n};\n\n// Usage:\nconsole.log(isItemInLocalStorage('user')); // Output: true or false\n" - }, - { - "title": "Clear All localStorage", - "description": "Clears all data from localStorage.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "localStorage", - "storage", - "utility" - ], - "contributors": [], - "code": "const clearLocalStorage = () => {\n localStorage.clear();\n};\n\n// Usage:\nclearLocalStorage(); // Removes all items from localStorage\n" - }, - { - "title": "Retrieve Item from localStorage", - "description": "Retrieves a value from localStorage by key and parses it.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "localStorage", - "storage", - "utility" - ], - "contributors": [], - "code": "const getFromLocalStorage = (key) => {\n const item = localStorage.getItem(key);\n return item ? JSON.parse(item) : null;\n};\n\n// Usage:\nconst user = getFromLocalStorage('user');\nconsole.log(user); // Output: { name: 'John', age: 30 }\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Number Formatting", - "snippets": [ - { - "title": "Convert Number to Currency", - "description": "Converts a number to a currency format with a specific locale.", - "author": "axorax", - "tags": [ - "javascript", - "number", - "currency", - "utility" - ], - "contributors": [], - "code": "const convertToCurrency = (num, locale = 'en-US', currency = 'USD') => {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: currency\n }).format(num);\n};\n\n// Usage:\nconsole.log(convertToCurrency(1234567.89)); // Output: '$1,234,567.89'\nconsole.log(convertToCurrency(987654.32, 'de-DE', 'EUR')); // Output: '987.654,32 €'\n" - }, - { - "title": "Convert Number to Roman Numerals", - "description": "Converts a number to Roman numeral representation.", - "author": "axorax", - "tags": [ - "javascript", - "number", - "roman", - "utility" - ], - "contributors": [], - "code": "const numberToRoman = (num) => {\n const romanNumerals = {\n 1: 'I', 4: 'IV', 5: 'V', 9: 'IX', 10: 'X', 40: 'XL', 50: 'L',\n 90: 'XC', 100: 'C', 400: 'CD', 500: 'D', 900: 'CM', 1000: 'M'\n };\n let result = '';\n Object.keys(romanNumerals).reverse().forEach(value => {\n while (num >= value) {\n result += romanNumerals[value];\n num -= value;\n }\n });\n return result;\n};\n\n// Usage:\nconsole.log(numberToRoman(1994)); // Output: 'MCMXCIV'\nconsole.log(numberToRoman(58)); // Output: 'LVIII'\n" - }, - { - "title": "Convert to Scientific Notation", - "description": "Converts a number to scientific notation.", - "author": "axorax", - "tags": [ - "javascript", - "number", - "scientific", - "utility" - ], - "contributors": [], - "code": "const toScientificNotation = (num) => {\n if (isNaN(num)) {\n throw new Error('Input must be a number');\n }\n if (num === 0) {\n return '0e+0';\n }\n const exponent = Math.floor(Math.log10(Math.abs(num)));\n const mantissa = num / Math.pow(10, exponent);\n return `${mantissa.toFixed(2)}e${exponent >= 0 ? '+' : ''}${exponent}`;\n};\n\n// Usage:\nconsole.log(toScientificNotation(12345)); // Output: '1.23e+4'\nconsole.log(toScientificNotation(0.0005678)); // Output: '5.68e-4'\nconsole.log(toScientificNotation(1000)); // Output: '1.00e+3'\nconsole.log(toScientificNotation(0)); // Output: '0e+0'\nconsole.log(toScientificNotation(-54321)); // Output: '-5.43e+4'\n" - }, - { - "title": "Format Number with Commas", - "description": "Formats a number with commas for better readability (e.g., 1000 -> 1,000).", - "author": "axorax", - "tags": [ - "javascript", - "number", - "format", - "utility" - ], - "contributors": [], - "code": "const formatNumberWithCommas = (num) => {\n return num.toString().replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\n};\n\n// Usage:\nconsole.log(formatNumberWithCommas(1000)); // Output: '1,000'\nconsole.log(formatNumberWithCommas(1234567)); // Output: '1,234,567'\nconsole.log(formatNumberWithCommas(987654321)); // Output: '987,654,321'\n" - }, - { - "title": "Number Formatter", - "description": "Formats a number with suffixes (K, M, B, etc.).", - "author": "realvishalrana", - "tags": [ - "javascript", - "number", - "format", - "utility" - ], - "contributors": [], - "code": "const nFormatter = (num) => {\n if (!num) return;\n num = parseFloat(num.toString().replace(/[^0-9.]/g, ''));\n const suffixes = ['', 'K', 'M', 'B', 'T', 'P', 'E'];\n let index = 0;\n while (num >= 1000 && index < suffixes.length - 1) {\n num /= 1000;\n index++;\n }\n return num.toFixed(2).replace(/\\.0+$|(\\.[0-9]*[1-9])0+$/, '$1') + suffixes[index];\n};\n\n// Usage:\nconsole.log(nFormatter(1234567)); // Output: '1.23M'\n" - }, - { - "title": "Number to Words Converter", - "description": "Converts a number to its word representation in English.", - "author": "axorax", - "tags": [ - "javascript", - "number", - "words", - "utility" - ], - "contributors": [], - "code": "const numberToWords = (num) => {\n const below20 = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen'];\n const tens = ['', '', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'];\n const above1000 = ['Hundred', 'Thousand', 'Million', 'Billion'];\n if (num < 20) return below20[num];\n let words = '';\n for (let i = 0; num > 0; i++) {\n if (i > 0 && num % 1000 !== 0) words = above1000[i] + ' ' + words;\n if (num % 100 >= 20) {\n words = tens[Math.floor(num / 10)] + ' ' + words;\n num %= 10;\n }\n if (num < 20) words = below20[num] + ' ' + words;\n num = Math.floor(num / 100);\n }\n return words.trim();\n};\n\n// Usage:\nconsole.log(numberToWords(123)); // Output: 'One Hundred Twenty Three'\nconsole.log(numberToWords(2045)); // Output: 'Two Thousand Forty Five'\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Object Manipulation", - "snippets": [ - { - "title": "Check if Object is Empty", - "description": "Checks whether an object has no own enumerable properties.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "check", - "empty" - ], - "contributors": [], - "code": "function isEmptyObject(obj) {\n return Object.keys(obj).length === 0;\n}\n\n// Usage:\nconsole.log(isEmptyObject({})); // Output: true\nconsole.log(isEmptyObject({ a: 1 })); // Output: false\n" - }, - { - "title": "Clone Object Shallowly", - "description": "Creates a shallow copy of an object.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "clone", - "shallow" - ], - "contributors": [], - "code": "function shallowClone(obj) {\n return { ...obj };\n}\n\n// Usage:\nconst obj = { a: 1, b: 2 };\nconst clone = shallowClone(obj);\nconsole.log(clone); // Output: { a: 1, b: 2 }\n" - }, - { - "title": "Compare Two Objects Shallowly", - "description": "Compares two objects shallowly and returns whether they are equal.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "compare", - "shallow" - ], - "contributors": [], - "code": "function shallowEqual(obj1, obj2) {\n const keys1 = Object.keys(obj1);\n const keys2 = Object.keys(obj2);\n if (keys1.length !== keys2.length) return false;\n return keys1.every(key => obj1[key] === obj2[key]);\n}\n\n// Usage:\nconst obj1 = { a: 1, b: 2 };\nconst obj2 = { a: 1, b: 2 };\nconst obj3 = { a: 1, b: 3 };\nconsole.log(shallowEqual(obj1, obj2)); // Output: true\nconsole.log(shallowEqual(obj1, obj3)); // Output: false\n" - }, - { - "title": "Convert Object to Query String", - "description": "Converts an object to a query string for use in URLs.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "query string", - "url" - ], - "contributors": [], - "code": "function toQueryString(obj) {\n return Object.entries(obj)\n .map(([key, value]) => encodeURIComponent(key) + '=' + encodeURIComponent(value))\n .join('&');\n}\n\n// Usage:\nconst params = { search: 'test', page: 1 };\nconsole.log(toQueryString(params)); // Output: 'search=test&page=1'\n" - }, - { - "title": "Count Properties in Object", - "description": "Counts the number of own properties in an object.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "count", - "properties" - ], - "contributors": [], - "code": "function countProperties(obj) {\n return Object.keys(obj).length;\n}\n\n// Usage:\nconst obj = { a: 1, b: 2, c: 3 };\nconsole.log(countProperties(obj)); // Output: 3\n" - }, - { - "title": "Filter Object", - "description": "Filter out entries in an object where the value is falsy, including empty strings, empty objects, null, and undefined.", - "author": "realvishalrana", - "tags": [ - "javascript", - "object", - "filter", - "utility" - ], - "contributors": [], - "code": "export const filterObject = (object = {}) =>\n Object.fromEntries(\n Object.entries(object)\n .filter(([key, value]) => value !== null && value !== undefined && value !== '' && (typeof value !== 'object' || Object.keys(value).length > 0))\n );\n\n// Usage:\nconst obj1 = { a: 1, b: null, c: undefined, d: 4, e: '', f: {} };\nconsole.log(filterObject(obj1)); // Output: { a: 1, d: 4 }\n\nconst obj2 = { x: 0, y: false, z: 'Hello', w: [] };\nconsole.log(filterObject(obj2)); // Output: { z: 'Hello' }\n\nconst obj3 = { name: 'John', age: null, address: { city: 'New York' }, phone: '' };\nconsole.log(filterObject(obj3)); // Output: { name: 'John', address: { city: 'New York' } }\n\nconst obj4 = { a: 0, b: '', c: false, d: {}, e: 'Valid' };\nconsole.log(filterObject(obj4)); // Output: { e: 'Valid' }\n" - }, - { - "title": "Flatten Nested Object", - "description": "Flattens a nested object into a single-level object with dot notation for keys.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "flatten", - "utility" - ], - "contributors": [], - "code": "function flattenObject(obj, prefix = '') {\n return Object.keys(obj).reduce((acc, key) => {\n const fullPath = prefix ? `${prefix}.${key}` : key;\n if (typeof obj[key] === 'object' && obj[key] !== null) {\n Object.assign(acc, flattenObject(obj[key], fullPath));\n } else {\n acc[fullPath] = obj[key];\n }\n return acc;\n }, {});\n}\n\n// Usage:\nconst nestedObj = { a: { b: { c: 1 }, d: 2 }, e: 3 };\nconsole.log(flattenObject(nestedObj)); // Output: { 'a.b.c': 1, 'a.d': 2, e: 3 }\n" - }, - { - "title": "Freeze Object", - "description": "Freezes an object to make it immutable.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "freeze", - "immutable" - ], - "contributors": [], - "code": "function freezeObject(obj) {\n return Object.freeze(obj);\n}\n\n// Usage:\nconst obj = { a: 1, b: 2 };\nconst frozenObj = freezeObject(obj);\nfrozenObj.a = 42; // This will fail silently in strict mode.\nconsole.log(frozenObj.a); // Output: 1\n" - }, - { - "title": "Get Nested Value", - "description": "Retrieves the value at a given path in a nested object.", - "author": "realvishalrana", - "tags": [ - "javascript", - "object", - "nested", - "utility" - ], - "contributors": [], - "code": "const getNestedValue = (obj, path) => {\n const keys = path.split('.');\n return keys.reduce((currentObject, key) => {\n return currentObject && typeof currentObject === 'object' ? currentObject[key] : undefined;\n }, obj);\n};\n\n// Usage:\nconst obj = { a: { b: { c: 42 } } };\nconsole.log(getNestedValue(obj, 'a.b.c')); // Output: 42\n" - }, - { - "title": "Invert Object Keys and Values", - "description": "Creates a new object by swapping keys and values of the given object.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "invert", - "utility" - ], - "contributors": [], - "code": "function invertObject(obj) {\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [value, key])\n );\n}\n\n// Usage:\nconst obj = { a: 1, b: 2, c: 3 };\nconsole.log(invertObject(obj)); // Output: { '1': 'a', '2': 'b', '3': 'c' }\n" - }, - { - "title": "Merge Objects Deeply", - "description": "Deeply merges two or more objects, including nested properties.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "merge", - "deep" - ], - "contributors": [], - "code": "function deepMerge(...objects) {\n return objects.reduce((acc, obj) => {\n Object.keys(obj).forEach(key => {\n if (typeof obj[key] === 'object' && obj[key] !== null) {\n acc[key] = deepMerge(acc[key] || {}, obj[key]);\n } else {\n acc[key] = obj[key];\n }\n });\n return acc;\n }, {});\n}\n\n// Usage:\nconst obj1 = { a: 1, b: { c: 2 } };\nconst obj2 = { b: { d: 3 }, e: 4 };\nconsole.log(deepMerge(obj1, obj2)); // Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }\n" - }, - { - "title": "Omit Keys from Object", - "description": "Creates a new object with specific keys omitted.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "omit", - "utility" - ], - "contributors": [], - "code": "function omitKeys(obj, keys) {\n return Object.fromEntries(\n Object.entries(obj).filter(([key]) => !keys.includes(key))\n );\n}\n\n// Usage:\nconst obj = { a: 1, b: 2, c: 3 };\nconsole.log(omitKeys(obj, ['b', 'c'])); // Output: { a: 1 }\n" - }, - { - "title": "Pick Keys from Object", - "description": "Creates a new object with only the specified keys.", - "author": "axorax", - "tags": [ - "javascript", - "object", - "pick", - "utility" - ], - "contributors": [], - "code": "function pickKeys(obj, keys) {\n return Object.fromEntries(\n Object.entries(obj).filter(([key]) => keys.includes(key))\n );\n}\n\n// Usage:\nconst obj = { a: 1, b: 2, c: 3 };\nconsole.log(pickKeys(obj, ['a', 'c'])); // Output: { a: 1, c: 3 }\n" - }, - { - "title": "Unique By Key", - "description": "Filters an array of objects to only include unique objects by a specified key.", - "author": "realvishalrana", - "tags": [ - "javascript", - "array", - "unique", - "utility" - ], - "contributors": [], - "code": "const uniqueByKey = (key, arr) =>\n arr.filter((obj, index, self) => index === self.findIndex((t) => t?.[key] === obj?.[key]));\n\n// Usage:\nconst arr = [\n { id: 1, name: 'John' },\n { id: 2, name: 'Jane' },\n { id: 1, name: 'John' }\n];\nconsole.log(uniqueByKey('id', arr)); // Output: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "Regular Expression", - "snippets": [ - { - "title": "Regex Match Utility Function", - "description": "Enhanced regular expression matching utility.", - "author": "aumirza", - "tags": [ - "javascript", - "regex" - ], - "contributors": [], - "code": "/**\n* @param {string | number} input\n* The input string to match\n* @param {regex | string} expression\n* Regular expression\n* @param {string} flags\n* Optional Flags\n*\n* @returns {array}\n* [{\n* match: '...',\n* matchAtIndex: 0,\n* capturedGroups: [ '...', '...' ]\n* }]\n*/\nfunction regexMatch(input, expression, flags = 'g') {\n let regex =\n expression instanceof RegExp\n ? expression\n : new RegExp(expression, flags);\n let matches = input.matchAll(regex);\n matches = [...matches];\n return matches.map((item) => {\n return {\n match: item[0],\n matchAtIndex: item.index,\n capturedGroups: item.length > 1 ? item.slice(1) : undefined,\n };\n });\n}\n" - } - ] - }, - { - "language": "javascript", - "categoryName": "String Manipulation", - "snippets": [ - { - "title": "Capitalize String", - "description": "Capitalizes the first letter of a string.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "string", - "capitalize", - "utility" - ], - "contributors": [], - "code": "const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);\n\n// Usage:\nconsole.log(capitalize('hello')); // Output: 'Hello'\n" - }, - { - "title": "Check if String is a Palindrome", - "description": "Checks whether a given string is a palindrome.", - "author": "axorax", - "tags": [ - "javascript", - "check", - "palindrome", - "string" - ], - "contributors": [], - "code": "function isPalindrome(str) {\n const cleanStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();\n return cleanStr === cleanStr.split('').reverse().join('');\n}\n\n// Example usage:\nconsole.log(isPalindrome('A man, a plan, a canal, Panama')); // Output: true\n" - }, - { - "title": "Convert String to Camel Case", - "description": "Converts a given string into camelCase.", - "author": "aumirza", - "tags": [ - "string", - "case", - "camelCase" - ], - "contributors": [], - "code": "function toCamelCase(str) {\n return str.replace(/\\W+(.)/g, (match, chr) => chr.toUpperCase());\n}\n\n// Example usage:\nconsole.log(toCamelCase('hello world test')); // Output: 'helloWorldTest'\n" - }, - { - "title": "Convert String to Param Case", - "description": "Converts a given string into param-case.", - "author": "aumirza", - "tags": [ - "string", - "case", - "paramCase" - ], - "contributors": [], - "code": "function toParamCase(str) {\n return str.toLowerCase().replace(/\\s+/g, '-');\n}\n\n// Example usage:\nconsole.log(toParamCase('Hello World Test')); // Output: 'hello-world-test'\n" - }, - { - "title": "Convert String to Pascal Case", - "description": "Converts a given string into Pascal Case.", - "author": "aumirza", - "tags": [ - "string", - "case", - "pascalCase" - ], - "contributors": [], - "code": "function toPascalCase(str) {\n return str.replace(/\\b\\w/g, (s) => s.toUpperCase()).replace(/\\W+(.)/g, (match, chr) => chr.toUpperCase());\n}\n\n// Example usage:\nconsole.log(toPascalCase('hello world test')); // Output: 'HelloWorldTest'\n" - }, - { - "title": "Convert String to Snake Case", - "description": "Converts a given string into snake_case.", - "author": "axorax", - "tags": [ - "string", - "case", - "snake_case" - ], - "contributors": [], - "code": "function toSnakeCase(str) {\n return str.replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/\\s+/g, '_')\n .toLowerCase();\n}\n\n// Example usage:\nconsole.log(toSnakeCase('Hello World Test')); // Output: 'hello_world_test'\n" - }, - { - "title": "Convert String to Title Case", - "description": "Converts a given string into Title Case.", - "author": "aumirza", - "tags": [ - "string", - "case", - "titleCase" - ], - "contributors": [], - "code": "function toTitleCase(str) {\n return str.toLowerCase().replace(/\\b\\w/g, (s) => s.toUpperCase());\n}\n\n// Example usage:\nconsole.log(toTitleCase('hello world test')); // Output: 'Hello World Test'\n" - }, - { - "title": "Convert Tabs to Spaces", - "description": "Converts all tab characters in a string to spaces.", - "author": "axorax", - "tags": [ - "string", - "tabs", - "spaces" - ], - "contributors": [], - "code": "function tabsToSpaces(str, spacesPerTab = 4) {\n return str.replace(/\\t/g, ' '.repeat(spacesPerTab));\n}\n\n// Example usage:\nconsole.log(tabsToSpaces('Hello\\tWorld', 2)); // Output: 'Hello World'\n" - }, - { - "title": "Count Words in a String", - "description": "Counts the number of words in a string.", - "author": "axorax", - "tags": [ - "javascript", - "string", - "manipulation", - "word count", - "count" - ], - "contributors": [], - "code": "function countWords(str) {\n return str.trim().split(/\\s+/).length;\n}\n\n// Example usage:\nconsole.log(countWords('Hello world! This is a test.')); // Output: 6\n" - }, - { - "title": "Data with Prefix", - "description": "Adds a prefix and postfix to data, with a fallback value.", - "author": "realvishalrana", - "tags": [ - "javascript", - "data", - "utility" - ], - "contributors": [], - "code": "const dataWithPrefix = (data, fallback = '-', prefix = '', postfix = '') => {\n return data ? `${prefix}${data}${postfix}` : fallback;\n};\n\n// Usage:\nconsole.log(dataWithPrefix('123', '-', '(', ')')); // Output: '(123)'\nconsole.log(dataWithPrefix('', '-', '(', ')')); // Output: '-'\nconsole.log(dataWithPrefix('Hello', 'N/A', 'Mr. ', '')); // Output: 'Mr. Hello'\nconsole.log(dataWithPrefix(null, 'N/A', 'Mr. ', '')); // Output: 'N/A'\n" - }, - { - "title": "Extract Initials from Name", - "description": "Extracts and returns the initials from a full name.", - "author": "axorax", - "tags": [ - "string", - "initials", - "name" - ], - "contributors": [], - "code": "function getInitials(name) {\n return name.split(' ').map(part => part.charAt(0).toUpperCase()).join('');\n}\n\n// Example usage:\nconsole.log(getInitials('John Doe')); // Output: 'JD'\n" - }, - { - "title": "Mask Sensitive Information", - "description": "Masks parts of a sensitive string, like a credit card or email address.", - "author": "axorax", - "tags": [ - "string", - "mask", - "sensitive" - ], - "contributors": [], - "code": "function maskSensitiveInfo(str, visibleCount = 4, maskChar = '*') {\n return str.slice(0, visibleCount) + maskChar.repeat(Math.max(0, str.length - visibleCount));\n}\n\n// Example usage:\nconsole.log(maskSensitiveInfo('123456789', 4)); // Output: '1234*****'\nconsole.log(maskSensitiveInfo('example@mail.com', 2, '#')); // Output: 'ex#############'\n" - }, - { - "title": "Pad String on Both Sides", - "description": "Pads a string on both sides with a specified character until it reaches the desired length.", - "author": "axorax", - "tags": [ - "string", - "pad", - "manipulation" - ], - "contributors": [], - "code": "function padString(str, length, char = ' ') {\n const totalPad = length - str.length;\n const padStart = Math.floor(totalPad / 2);\n const padEnd = totalPad - padStart;\n return char.repeat(padStart) + str + char.repeat(padEnd);\n}\n\n// Example usage:\nconsole.log(padString('hello', 10, '*')); // Output: '**hello***'\n" - }, - { - "title": "Random string", - "description": "Generates a random string of characters of a certain length", - "author": "kruimol", - "tags": [ - "javascript", - "function", - "random" - ], - "contributors": [], - "code": "function makeid(length, characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {\n return Array.from({ length }, () => characters.charAt(Math.floor(Math.random() * characters.length))).join('');\n}\n\nconsole.log(makeid(5, \"1234\" /* (optional) */));\n" - }, - { - "title": "Remove All Whitespace", - "description": "Removes all whitespace from a string.", - "author": "axorax", - "tags": [ - "javascript", - "string", - "whitespace" - ], - "contributors": [], - "code": "function removeWhitespace(str) {\n return str.replace(/\\s+/g, '');\n}\n\n// Example usage:\nconsole.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'\n" - }, - { - "title": "Remove Vowels from a String", - "description": "Removes all vowels from a given string.", - "author": "axorax", - "tags": [ - "string", - "remove", - "vowels" - ], - "contributors": [], - "code": "function removeVowels(str) {\n return str.replace(/[aeiouAEIOU]/g, '');\n}\n\n// Example usage:\nconsole.log(removeVowels('Hello World')); // Output: 'Hll Wrld'\n" - }, - { - "title": "Reverse String", - "description": "Reverses the characters in a string.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "string", - "reverse", - "utility" - ], - "contributors": [], - "code": "const reverseString = (str) => str.split('').reverse().join('');\n\n// Usage:\nconsole.log(reverseString('hello')); // Output: 'olleh'\n" - }, - { - "title": "Slugify String", - "description": "Converts a string into a URL-friendly slug format.", - "author": "dostonnabotov", - "tags": [ - "javascript", - "string", - "slug", - "utility" - ], - "contributors": [], - "code": "const slugify = (string, separator = \"-\") => {\n return string\n .toString() // Cast to string (optional)\n .toLowerCase() // Convert the string to lowercase letters\n .trim() // Remove whitespace from both sides of a string (optional)\n .replace(/\\s+/g, separator) // Replace spaces with {separator}\n .replace(/[^\\w\\-]+/g, \"\") // Remove all non-word chars\n .replace(/\\_/g, separator) // Replace _ with {separator}\n .replace(/\\-\\-+/g, separator) // Replace multiple - with single {separator}\n .replace(/\\-$/g, \"\"); // Remove trailing -\n};\n\n// Usage:\nconst title = \"Hello, World! This is a Test.\";\nconsole.log(slugify(title)); // Output: 'hello-world-this-is-a-test'\nconsole.log(slugify(title, \"_\")); // Output: 'hello_world_this_is_a_test'\n" - }, - { - "title": "Truncate Text", - "description": "Truncates the text to a maximum length and appends '...' if the text exceeds the maximum length.", - "author": "realvishalrana", - "tags": [ - "javascript", - "string", - "truncate", - "utility", - "text" - ], - "contributors": [], - "code": "const truncateText = (text = '', maxLength = 50) => {\n return `${text.slice(0, maxLength)}${text.length >= maxLength ? '...' : ''}`;\n};\n\n// Usage:\nconst title = \"Hello, World! This is a Test.\";\nconsole.log(truncateText(title)); // Output: 'Hello, World! This is a Test.'\nconsole.log(truncateText(title, 10)); // Output: 'Hello, Wor...'\n" - } - ] - }, - { - "language": "python", - "categoryName": "Basics", - "snippets": [ - { - "title": "Hello, World!", - "description": "Prints Hello, World! to the terminal.", - "author": "James-Beans", - "tags": [ - "python", - "printing", - "hello-world", - "utility" - ], - "contributors": [], - "code": "print(\"Hello, World!\") # Prints Hello, World! to the terminal.\n" - } - ] - }, - { - "language": "python", - "categoryName": "Datetime Utilities", - "snippets": [ - { - "title": "Calculate Date Difference in Milliseconds", - "description": "Calculates the difference between two dates in milliseconds.", - "author": "e3nviction", - "tags": [ - "python", - "datetime", - "utility" - ], - "contributors": [], - "code": "from datetime import datetime\n\ndef date_difference_in_millis(date1, date2):\n delta = date2 - date1\n return delta.total_seconds() * 1000\n\n# Usage:\nd1 = datetime(2023, 1, 1, 12, 0, 0)\nd2 = datetime(2023, 1, 1, 12, 1, 0)\nprint(date_difference_in_millis(d1, d2))\n" - }, - { - "title": "Check if Date is a Weekend", - "description": "Checks whether a given date falls on a weekend.", - "author": "axorax", - "tags": [ - "python", - "datetime", - "weekend", - "utility" - ], - "contributors": [], - "code": "from datetime import datetime\n\ndef is_weekend(date):\n try:\n return date.weekday() >= 5 # Saturday = 5, Sunday = 6\n except AttributeError:\n raise TypeError(\"Input must be a datetime object\")\n\n# Usage:\ndate = datetime(2023, 1, 1)\nweekend = is_weekend(date)\nprint(weekend) # Output: True (Sunday)\n" - }, - { - "title": "Determine Day of the Week", - "description": "Calculates the day of the week for a given date.", - "author": "axorax", - "tags": [ - "python", - "datetime", - "weekday", - "utility" - ], - "contributors": [], - "code": "from datetime import datetime\n\ndef get_day_of_week(date):\n days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']\n try:\n return days[date.weekday()]\n except IndexError:\n raise ValueError(\"Invalid date\")\n\n# Usage:\ndate = datetime(2023, 1, 1)\nday = get_day_of_week(date)\nprint(day) # Output: 'Sunday'\n" - }, - { - "title": "Generate Date Range List", - "description": "Generates a list of dates between two given dates.", - "author": "axorax", - "tags": [ - "python", - "datetime", - "range", - "utility" - ], - "contributors": [], - "code": "from datetime import datetime, timedelta\n\ndef generate_date_range(start_date, end_date):\n if start_date > end_date:\n raise ValueError(\"start_date must be before end_date\")\n\n current_date = start_date\n date_list = []\n while current_date <= end_date:\n date_list.append(current_date)\n current_date += timedelta(days=1)\n\n return date_list\n\n# Usage:\nstart = datetime(2023, 1, 1)\nend = datetime(2023, 1, 5)\ndates = generate_date_range(start, end)\nfor d in dates:\n print(d.strftime('%Y-%m-%d'))\n# Output: '2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05'\n" - }, - { - "title": "Get Current Date and Time String", - "description": "Fetches the current date and time as a formatted string.", - "author": "e3nviction", - "tags": [ - "python", - "datetime", - "utility" - ], - "contributors": [], - "code": "from datetime import datetime\n\ndef get_current_datetime_string():\n return datetime.now().strftime('%Y-%m-%d %H:%M:%S')\n\n# Usage:\nprint(get_current_datetime_string()) # Output: '2023-01-01 12:00:00'\n" - }, - { - "title": "Get Number of Days in a Month", - "description": "Determines the number of days in a specific month and year.", - "author": "axorax", - "tags": [ - "python", - "datetime", - "calendar", - "utility" - ], - "contributors": [], - "code": "from calendar import monthrange\nfrom datetime import datetime\n\ndef get_days_in_month(year, month):\n try:\n return monthrange(year, month)[1]\n except ValueError as e:\n raise ValueError(f\"Invalid month or year: {e}\")\n\n# Usage:\ndays = get_days_in_month(2023, 2)\nprint(days) # Output: 28 (for non-leap year February)\n" - } - ] - }, - { - "language": "python", - "categoryName": "Error Handling", - "snippets": [ - { - "title": "Handle File Not Found Error", - "description": "Attempts to open a file and handles the case where the file does not exist.", - "author": "axorax", - "tags": [ - "python", - "error-handling", - "file", - "utility" - ], - "contributors": [], - "code": "def read_file_safe(filepath):\n try:\n with open(filepath, 'r') as file:\n return file.read()\n except FileNotFoundError:\n return \"File not found!\"\n\n# Usage:\nprint(read_file_safe('nonexistent.txt')) # Output: 'File not found!'\n" - }, - { - "title": "Retry Function Execution on Exception", - "description": "Retries a function execution a specified number of times if it raises an exception.", - "author": "axorax", - "tags": [ - "python", - "error-handling", - "retry", - "utility" - ], - "contributors": [], - "code": "import time\n\ndef retry(func, retries=3, delay=1):\n for attempt in range(retries):\n try:\n return func()\n except Exception as e:\n print(f\"Attempt {attempt + 1} failed: {e}\")\n time.sleep(delay)\n raise Exception(\"All retry attempts failed\")\n\n# Usage:\ndef unstable_function():\n raise ValueError(\"Simulated failure\")\n\n# Retry 3 times with 2 seconds delay:\ntry:\n retry(unstable_function, retries=3, delay=2)\nexcept Exception as e:\n print(e) # Output: All retry attempts failed\n" - }, - { - "title": "Safe Division", - "description": "Performs division with error handling.", - "author": "e3nviction", - "tags": [ - "python", - "error-handling", - "division", - "utility" - ], - "contributors": [], - "code": "def safe_divide(a, b):\n try:\n return a / b\n except ZeroDivisionError:\n return 'Cannot divide by zero!'\n\n# Usage:\nprint(safe_divide(10, 2)) # Output: 5.0\nprint(safe_divide(10, 0)) # Output: 'Cannot divide by zero!'\n" - }, - { - "title": "Validate Input with Exception Handling", - "description": "Validates user input and handles invalid input gracefully.", - "author": "axorax", - "tags": [ - "python", - "error-handling", - "validation", - "utility" - ], - "contributors": [], - "code": "def validate_positive_integer(input_value):\n try:\n value = int(input_value)\n if value < 0:\n raise ValueError(\"The number must be positive\")\n return value\n except ValueError as e:\n return f\"Invalid input: {e}\"\n\n# Usage:\nprint(validate_positive_integer('10')) # Output: 10\nprint(validate_positive_integer('-5')) # Output: Invalid input: The number must be positive\nprint(validate_positive_integer('abc')) # Output: Invalid input: invalid literal for int() with base 10: 'abc'\n" - } - ] - }, - { - "language": "python", - "categoryName": "File Handling", - "snippets": [ - { - "title": "Append to File", - "description": "Appends content to the end of a file.", - "author": "axorax", - "tags": [ - "python", - "file", - "append", - "utility" - ], - "contributors": [], - "code": "def append_to_file(filepath, content):\n with open(filepath, 'a') as file:\n file.write(content + '\\n')\n\n# Usage:\nappend_to_file('example.txt', 'This is an appended line.')\n" - }, - { - "title": "Check if File Exists", - "description": "Checks if a file exists at the specified path.", - "author": "axorax", - "tags": [ - "python", - "file", - "exists", - "check", - "utility" - ], - "contributors": [], - "code": "import os\n\ndef file_exists(filepath):\n return os.path.isfile(filepath)\n\n# Usage:\nprint(file_exists('example.txt')) # Output: True or False\n" - }, - { - "title": "Copy File", - "description": "Copies a file from source to destination.", - "author": "axorax", - "tags": [ - "python", - "file", - "copy", - "utility" - ], - "contributors": [], - "code": "import shutil\n\ndef copy_file(src, dest):\n shutil.copy(src, dest)\n\n# Usage:\ncopy_file('example.txt', 'copy_of_example.txt')\n" - }, - { - "title": "Delete File", - "description": "Deletes a file at the specified path.", - "author": "axorax", - "tags": [ - "python", - "file", - "delete", - "utility" - ], - "contributors": [], - "code": "import os\n\ndef delete_file(filepath):\n if os.path.exists(filepath):\n os.remove(filepath)\n print(f'File {filepath} deleted.')\n else:\n print(f'File {filepath} does not exist.')\n\n# Usage:\ndelete_file('example.txt')\n" - }, - { - "title": "Find Files", - "description": "Finds all files of the specified type within a given directory.", - "author": "Jackeastern", - "tags": [ - "python", - "os", - "filesystem", - "file_search" - ], - "contributors": [], - "code": "import os\n\ndef find_files(directory, file_type):\n file_type = file_type.lower() # Convert file_type to lowercase\n found_files = []\n\n for root, _, files in os.walk(directory):\n for file in files:\n file_ext = os.path.splitext(file)[1].lower()\n if file_ext == file_type:\n full_path = os.path.join(root, file)\n found_files.append(full_path)\n\n return found_files\n\n# Example Usage:\npdf_files = find_files('/path/to/your/directory', '.pdf')\nprint(pdf_files)\n" - }, - { - "title": "Get File Extension", - "description": "Gets the extension of a file.", - "author": "axorax", - "tags": [ - "python", - "file", - "extension", - "utility" - ], - "contributors": [], - "code": "import os\n\ndef get_file_extension(filepath):\n return os.path.splitext(filepath)[1]\n\n# Usage:\nprint(get_file_extension('example.txt')) # Output: '.txt'\n" - }, - { - "title": "List Files in Directory", - "description": "Lists all files in a specified directory.", - "author": "axorax", - "tags": [ - "python", - "file", - "list", - "directory", - "utility" - ], - "contributors": [], - "code": "import os\n\ndef list_files(directory):\n return [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]\n\n# Usage:\nfiles = list_files('/path/to/directory')\nprint(files)\n" - }, - { - "title": "Read File in Chunks", - "description": "Reads a file in chunks of a specified size.", - "author": "axorax", - "tags": [ - "python", - "file", - "read", - "chunks", - "utility" - ], - "contributors": [], - "code": "def read_file_in_chunks(filepath, chunk_size):\n with open(filepath, 'r') as file:\n while chunk := file.read(chunk_size):\n yield chunk\n\n# Usage:\nfor chunk in read_file_in_chunks('example.txt', 1024):\n print(chunk)\n" - }, - { - "title": "Read File Lines", - "description": "Reads all lines from a file and returns them as a list.", - "author": "dostonnabotov", - "tags": [ - "python", - "file", - "read", - "utility" - ], - "contributors": [], - "code": "def read_file_lines(filepath):\n with open(filepath, 'r') as file:\n return file.readlines()\n\n# Usage:\nlines = read_file_lines('example.txt')\nprint(lines)\n" - }, - { - "title": "Write to File", - "description": "Writes content to a file.", - "author": "dostonnabotov", - "tags": [ - "python", - "file", - "write", - "utility" - ], - "contributors": [], - "code": "def write_to_file(filepath, content):\n with open(filepath, 'w') as file:\n file.write(content)\n\n# Usage:\nwrite_to_file('example.txt', 'Hello, World!')\n" - } - ] - }, - { - "language": "python", - "categoryName": "Json Manipulation", - "snippets": [ - { - "title": "Filter JSON Data", - "description": "Filters a JSON object based on a condition and returns the filtered data.", - "author": "axorax", - "tags": [ - "python", - "json", - "filter", - "data" - ], - "contributors": [], - "code": "import json\n\ndef filter_json_data(filepath, condition):\n with open(filepath, 'r') as file:\n data = json.load(file)\n\n # Filter data based on the provided condition\n filtered_data = [item for item in data if condition(item)]\n\n return filtered_data\n\n# Usage:\ncondition = lambda x: x['age'] > 25\nfiltered = filter_json_data('data.json', condition)\nprint(filtered)\n" - }, - { - "title": "Flatten Nested JSON", - "description": "Flattens a nested JSON object into a flat dictionary.", - "author": "axorax", - "tags": [ - "python", - "json", - "flatten", - "nested" - ], - "contributors": [], - "code": "def flatten_json(nested_json, prefix=''):\n flat_dict = {}\n for key, value in nested_json.items():\n if isinstance(value, dict):\n flat_dict.update(flatten_json(value, prefix + key + '.'))\n else:\n flat_dict[prefix + key] = value\n return flat_dict\n\n# Usage:\nnested_json = {'name': 'John', 'address': {'city': 'New York', 'zip': '10001'}}\nflattened = flatten_json(nested_json)\nprint(flattened) # Output: {'name': 'John', 'address.city': 'New York', 'address.zip': '10001'}\n" - }, - { - "title": "Merge Multiple JSON Files", - "description": "Merges multiple JSON files into one and writes the merged data into a new file.", - "author": "axorax", - "tags": [ - "python", - "json", - "merge", - "file" - ], - "contributors": [], - "code": "import json\n\ndef merge_json_files(filepaths, output_filepath):\n merged_data = []\n\n # Read each JSON file and merge their data\n for filepath in filepaths:\n with open(filepath, 'r') as file:\n data = json.load(file)\n merged_data.extend(data)\n\n # Write the merged data into a new file\n with open(output_filepath, 'w') as file:\n json.dump(merged_data, file, indent=4)\n\n# Usage:\nfiles_to_merge = ['file1.json', 'file2.json']\nmerge_json_files(files_to_merge, 'merged.json')\n" - }, - { - "title": "Read JSON File", - "description": "Reads a JSON file and parses its content.", - "author": "e3nviction", - "tags": [ - "python", - "json", - "file", - "read" - ], - "contributors": [], - "code": "import json\n\ndef read_json(filepath):\n with open(filepath, 'r') as file:\n return json.load(file)\n\n# Usage:\ndata = read_json('data.json')\nprint(data)\n" - }, - { - "title": "Update JSON File", - "description": "Updates an existing JSON file with new data or modifies the existing values.", - "author": "axorax", - "tags": [ - "python", - "json", - "update", - "file" - ], - "contributors": [], - "code": "import json\n\ndef update_json(filepath, new_data):\n # Read the existing JSON data\n with open(filepath, 'r') as file:\n data = json.load(file)\n\n # Update the data with the new content\n data.update(new_data)\n\n # Write the updated data back to the JSON file\n with open(filepath, 'w') as file:\n json.dump(data, file, indent=4)\n\n# Usage:\nnew_data = {'age': 31}\nupdate_json('data.json', new_data)\n" - }, - { - "title": "Validate JSON Schema", - "description": "Validates a JSON object against a predefined schema.", - "author": "axorax", - "tags": [ - "python", - "json", - "validation", - "schema" - ], - "contributors": [], - "code": "import jsonschema\nfrom jsonschema import validate\n\ndef validate_json_schema(data, schema):\n try:\n validate(instance=data, schema=schema)\n return True # Data is valid\n except jsonschema.exceptions.ValidationError as err:\n return False # Data is invalid\n\n# Usage:\nschema = {\n 'type': 'object',\n 'properties': {\n 'name': {'type': 'string'},\n 'age': {'type': 'integer'}\n },\n 'required': ['name', 'age']\n}\ndata = {'name': 'John', 'age': 30}\nis_valid = validate_json_schema(data, schema)\nprint(is_valid) # Output: True\n" - }, - { - "title": "Write JSON File", - "description": "Writes a dictionary to a JSON file.", - "author": "e3nviction", - "tags": [ - "python", - "json", - "file", - "write" - ], - "contributors": [], - "code": "import json\n\ndef write_json(filepath, data):\n with open(filepath, 'w') as file:\n json.dump(data, file, indent=4)\n\n# Usage:\ndata = {'name': 'John', 'age': 30}\nwrite_json('data.json', data)\n" - } - ] - }, - { - "language": "python", - "categoryName": "List Manipulation", - "snippets": [ - { - "title": "Find Duplicates in a List", - "description": "Identifies duplicate elements in a list.", - "author": "axorax", - "tags": [ - "python", - "list", - "duplicates", - "utility" - ], - "contributors": [], - "code": "def find_duplicates(lst):\n seen = set()\n duplicates = set()\n for item in lst:\n if item in seen:\n duplicates.add(item)\n else:\n seen.add(item)\n return list(duplicates)\n\n# Usage:\ndata = [1, 2, 3, 2, 4, 5, 1]\nprint(find_duplicates(data)) # Output: [1, 2]\n" - }, - { - "title": "Find Intersection of Two Lists", - "description": "Finds the common elements between two lists.", - "author": "axorax", - "tags": [ - "python", - "list", - "intersection", - "utility" - ], - "contributors": [], - "code": "def list_intersection(lst1, lst2):\n return [item for item in lst1 if item in lst2]\n\n# Usage:\nlist_a = [1, 2, 3, 4]\nlist_b = [3, 4, 5, 6]\nprint(list_intersection(list_a, list_b)) # Output: [3, 4]\n" - }, - { - "title": "Find Maximum Difference in List", - "description": "Finds the maximum difference between any two elements in a list.", - "author": "axorax", - "tags": [ - "python", - "list", - "difference", - "utility" - ], - "contributors": [], - "code": "def max_difference(lst):\n if not lst or len(lst) < 2:\n return 0\n return max(lst) - min(lst)\n\n# Usage:\ndata = [10, 3, 5, 20, 7]\nprint(max_difference(data)) # Output: 17\n" - }, - { - "title": "Flatten Nested List", - "description": "Flattens a multi-dimensional list into a single list.", - "author": "dostonnabotov", - "tags": [ - "python", - "list", - "flatten", - "utility" - ], - "contributors": [], - "code": "def flatten_list(lst):\n return [item for sublist in lst for item in sublist]\n\n# Usage:\nnested_list = [[1, 2], [3, 4], [5]]\nprint(flatten_list(nested_list)) # Output: [1, 2, 3, 4, 5]\n" - }, - { - "title": "Flatten Unevenly Nested Lists", - "description": "Converts unevenly nested lists of any depth into a single flat list.", - "author": "agilarasu", - "tags": [ - "python", - "list", - "flattening", - "nested-lists", - "depth", - "utilities" - ], - "contributors": [], - "code": "def flatten(nested_list):\n \"\"\"\n Flattens unevenly nested lists of any depth into a single flat list.\n \"\"\"\n for item in nested_list:\n if isinstance(item, list):\n yield from flatten(item)\n else:\n yield item\n\n# Usage:\nnested_list = [1, [2, [3, 4]], 5]\nflattened = list(flatten(nested_list))\nprint(flattened) # Output: [1, 2, 3, 4, 5]\n" - }, - { - "title": "Partition List", - "description": "Partitions a list into sublists of a given size.", - "author": "axorax", - "tags": [ - "python", - "list", - "partition", - "utility" - ], - "contributors": [], - "code": "def partition_list(lst, size):\n for i in range(0, len(lst), size):\n yield lst[i:i + size]\n\n# Usage:\ndata = [1, 2, 3, 4, 5, 6, 7]\npartitions = list(partition_list(data, 3))\nprint(partitions) # Output: [[1, 2, 3], [4, 5, 6], [7]]\n" - }, - { - "title": "Remove Duplicates", - "description": "Removes duplicate elements from a list while maintaining order.", - "author": "dostonnabotov", - "tags": [ - "python", - "list", - "duplicates", - "utility" - ], - "contributors": [], - "code": "def remove_duplicates(lst):\n return list(dict.fromkeys(lst))\n\n# Usage:\nprint(remove_duplicates([1, 2, 2, 3, 4, 4, 5])) # Output: [1, 2, 3, 4, 5]\n" - } - ] - }, - { - "language": "python", - "categoryName": "Math And Numbers", - "snippets": [ - { - "title": "Calculate Compound Interest", - "description": "Calculates compound interest for a given principal amount, rate, and time period.", - "author": "axorax", - "tags": [ - "python", - "math", - "compound interest", - "finance" - ], - "contributors": [], - "code": "def compound_interest(principal, rate, time, n=1):\n return principal * (1 + rate / n) ** (n * time)\n\n# Usage:\nprint(compound_interest(1000, 0.05, 5)) # Output: 1276.2815625000003\nprint(compound_interest(1000, 0.05, 5, 12)) # Output: 1283.68\n" - }, - { - "title": "Check Perfect Square", - "description": "Checks if a number is a perfect square.", - "author": "axorax", - "tags": [ - "python", - "math", - "perfect square", - "check" - ], - "contributors": [], - "code": "def is_perfect_square(n):\n if n < 0:\n return False\n root = int(n**0.5)\n return root * root == n\n\n# Usage:\nprint(is_perfect_square(16)) # Output: True\nprint(is_perfect_square(20)) # Output: False\n" - }, - { - "title": "Check Prime Number", - "description": "Checks if a number is a prime number.", - "author": "dostonnabotov", - "tags": [ - "python", - "math", - "prime", - "check" - ], - "contributors": [], - "code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\n# Usage:\nprint(is_prime(17)) # Output: True\n" - }, - { - "title": "Convert Binary to Decimal", - "description": "Converts a binary string to its decimal equivalent.", - "author": "axorax", - "tags": [ - "python", - "math", - "binary", - "decimal", - "conversion" - ], - "contributors": [], - "code": "def binary_to_decimal(binary_str):\n return int(binary_str, 2)\n\n# Usage:\nprint(binary_to_decimal('1010')) # Output: 10\nprint(binary_to_decimal('1101')) # Output: 13\n" - }, - { - "title": "Find Factorial", - "description": "Calculates the factorial of a number.", - "author": "dostonnabotov", - "tags": [ - "python", - "math", - "factorial", - "utility" - ], - "contributors": [], - "code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)\n\n# Usage:\nprint(factorial(5)) # Output: 120\n" - }, - { - "title": "Find LCM (Least Common Multiple)", - "description": "Calculates the least common multiple (LCM) of two numbers.", - "author": "axorax", - "tags": [ - "python", - "math", - "lcm", - "gcd", - "utility" - ], - "contributors": [], - "code": "def lcm(a, b):\n return abs(a * b) // gcd(a, b)\n\n# Usage:\nprint(lcm(12, 15)) # Output: 60\nprint(lcm(7, 5)) # Output: 35\n" - }, - { - "title": "Solve Quadratic Equation", - "description": "Solves a quadratic equation ax^2 + bx + c = 0 and returns the roots.", - "author": "axorax", - "tags": [ - "python", - "math", - "quadratic", - "equation", - "solver" - ], - "contributors": [], - "code": "import cmath\n\ndef solve_quadratic(a, b, c):\n discriminant = cmath.sqrt(b**2 - 4 * a * c)\n root1 = (-b + discriminant) / (2 * a)\n root2 = (-b - discriminant) / (2 * a)\n return root1, root2\n\n# Usage:\nprint(solve_quadratic(1, -3, 2)) # Output: ((2+0j), (1+0j))\nprint(solve_quadratic(1, 2, 5)) # Output: ((-1+2j), (-1-2j))\n" - } - ] - }, - { - "language": "python", - "categoryName": "Sqlite Database", - "snippets": [ - { - "title": "Create SQLite Database Table", - "description": "Creates a table in an SQLite database with a dynamic schema.", - "author": "e3nviction", - "tags": [ - "python", - "sqlite", - "database", - "table" - ], - "contributors": [], - "code": "import sqlite3\n\ndef create_table(db_name, table_name, schema):\n conn = sqlite3.connect(db_name)\n cursor = conn.cursor()\n schema_string = ', '.join([f'{col} {dtype}' for col, dtype in schema.items()])\n cursor.execute(f'''\n CREATE TABLE IF NOT EXISTS {table_name} (\n {schema_string}\n )''')\n conn.commit()\n conn.close()\n\n# Usage:\ndb_name = 'example.db'\ntable_name = 'users'\nschema = {\n 'id': 'INTEGER PRIMARY KEY',\n 'name': 'TEXT',\n 'age': 'INTEGER',\n 'email': 'TEXT'\n}\ncreate_table(db_name, table_name, schema)\n" - }, - { - "title": "Insert Data into Sqlite Table", - "description": "Inserts a row into a specified SQLite table using a dictionary of fields and values.", - "author": "e3nviction", - "tags": [ - "python", - "sqlite", - "database", - "utility" - ], - "contributors": [], - "code": "import sqlite3\n\ndef insert_into_table(db_path, table_name, data):\n with sqlite3.connect(db_path) as conn:\n columns = ', '.join(data.keys())\n placeholders = ', '.join(['?'] * len(data))\n sql = f\"INSERT INTO {table_name} ({columns}) VALUES ({placeholders})\"\n conn.execute(sql, tuple(data.values()))\n conn.commit()\n\n# Usage:\ndb_path = 'example.db'\ntable_name = 'users'\ndata = {\n 'name': 'John Doe',\n 'email': 'john@example.com',\n 'age': 30\n}\ninsert_into_table(db_path, table_name, data)\n" - } - ] - }, - { - "language": "python", - "categoryName": "String Manipulation", - "snippets": [ - { - "title": "Capitalize Words", - "description": "Capitalizes the first letter of each word in a string.", - "author": "axorax", - "tags": [ - "python", - "string", - "capitalize", - "utility" - ], - "contributors": [], - "code": "def capitalize_words(s):\n return ' '.join(word.capitalize() for word in s.split())\n\n# Usage:\nprint(capitalize_words('hello world')) # Output: 'Hello World'\n" - }, - { - "title": "Check Anagram", - "description": "Checks if two strings are anagrams of each other.", - "author": "SteliosGee", - "tags": [ - "python", - "string", - "anagram", - "check", - "utility" - ], - "contributors": [], - "code": "def is_anagram(s1, s2):\n return sorted(s1) == sorted(s2)\n\n# Usage:\nprint(is_anagram('listen', 'silent')) # Output: True\n" - }, - { - "title": "Check Palindrome", - "description": "Checks if a string is a palindrome.", - "author": "dostonnabotov", - "tags": [ - "python", - "string", - "palindrome", - "utility" - ], - "contributors": [], - "code": "def is_palindrome(s):\n s = s.lower().replace(' ', '')\n return s == s[::-1]\n\n# Usage:\nprint(is_palindrome('A man a plan a canal Panama')) # Output: True\n" - }, - { - "title": "Convert Snake Case to Camel Case", - "description": "Converts a snake_case string to camelCase.", - "author": "axorax", - "tags": [ - "python", - "string", - "snake-case", - "camel-case", - "convert", - "utility" - ], - "contributors": [], - "code": "def snake_to_camel(s):\n parts = s.split('_')\n return parts[0] + ''.join(word.capitalize() for word in parts[1:])\n\n# Usage:\nprint(snake_to_camel('hello_world')) # Output: 'helloWorld'\n" - }, - { - "title": "Convert String to ASCII", - "description": "Converts a string into its ASCII representation.", - "author": "axorax", - "tags": [ - "python", - "string", - "ascii", - "convert", - "utility" - ], - "contributors": [], - "code": "def string_to_ascii(s):\n return [ord(char) for char in s]\n\n# Usage:\nprint(string_to_ascii('hello')) # Output: [104, 101, 108, 108, 111]\n" - }, - { - "title": "Count Character Frequency", - "description": "Counts the frequency of each character in a string.", - "author": "axorax", - "tags": [ - "python", - "string", - "character-frequency", - "utility" - ], - "contributors": [], - "code": "from collections import Counter\n\ndef char_frequency(s):\n return dict(Counter(s))\n\n# Usage:\nprint(char_frequency('hello')) # Output: {'h': 1, 'e': 1, 'l': 2, 'o': 1}\n" - }, - { - "title": "Count Vowels", - "description": "Counts the number of vowels in a string.", - "author": "SteliosGee", - "tags": [ - "python", - "string", - "vowels", - "count", - "utility" - ], - "contributors": [], - "code": "def count_vowels(s):\n vowels = 'aeiou'\n return len([char for char in s.lower() if char in vowels])\n\n# Usage:\nprint(count_vowels('hello')) # Output: 2\n" - }, - { - "title": "Count Words", - "description": "Counts the number of words in a string.", - "author": "axorax", - "tags": [ - "python", - "string", - "word-count", - "utility" - ], - "contributors": [], - "code": "def count_words(s):\n return len(s.split())\n\n# Usage:\nprint(count_words('The quick brown fox')) # Output: 4\n" - }, - { - "title": "Find All Substrings", - "description": "Finds all substrings of a given string.", - "author": "axorax", - "tags": [ - "python", - "string", - "substring", - "find", - "utility" - ], - "contributors": [], - "code": "def find_substrings(s):\n substrings = []\n for i in range(len(s)):\n for j in range(i + 1, len(s) + 1):\n substrings.append(s[i:j])\n return substrings\n\n# Usage:\nprint(find_substrings('abc')) # Output: ['a', 'ab', 'abc', 'b', 'bc', 'c']\n" - }, - { - "title": "Find Longest Word", - "description": "Finds the longest word in a string.", - "author": "axorax", - "tags": [ - "python", - "string", - "longest-word", - "utility" - ], - "contributors": [], - "code": "def find_longest_word(s):\n words = s.split()\n return max(words, key=len) if words else ''\n\n# Usage:\nprint(find_longest_word('The quick brown fox')) # Output: 'quick'\n" - }, - { - "title": "Find Unique Characters", - "description": "Finds all unique characters in a string.", - "author": "axorax", - "tags": [ - "python", - "string", - "unique", - "characters", - "utility" - ], - "contributors": [], - "code": "def find_unique_chars(s):\n return ''.join(sorted(set(s)))\n\n# Usage:\nprint(find_unique_chars('banana')) # Output: 'abn'\n" - }, - { - "title": "Remove Duplicate Characters", - "description": "Removes duplicate characters from a string while maintaining the order.", - "author": "axorax", - "tags": [ - "python", - "string", - "duplicates", - "remove", - "utility" - ], - "contributors": [], - "code": "def remove_duplicate_chars(s):\n seen = set()\n return ''.join(char for char in s if not (char in seen or seen.add(char)))\n\n# Usage:\nprint(remove_duplicate_chars('programming')) # Output: 'progamin'\n" - }, - { - "title": "Remove Punctuation", - "description": "Removes punctuation from a string.", - "author": "SteliosGee", - "tags": [ - "python", - "string", - "punctuation", - "remove", - "utility" - ], - "contributors": [], - "code": "import string\n\ndef remove_punctuation(s):\n return s.translate(str.maketrans('', '', string.punctuation))\n\n# Usage:\nprint(remove_punctuation('Hello, World!')) # Output: 'Hello World'\n" - }, - { - "title": "Remove Specific Characters", - "description": "Removes specific characters from a string.", - "author": "axorax", - "tags": [ - "python", - "string", - "remove", - "characters", - "utility" - ], - "contributors": [], - "code": "def remove_chars(s, chars):\n return ''.join(c for c in s if c not in chars)\n\n# Usage:\nprint(remove_chars('hello world', 'eo')) # Output: 'hll wrld'\n" - }, - { - "title": "Remove Whitespace", - "description": "Removes all whitespace from a string.", - "author": "axorax", - "tags": [ - "python", - "string", - "whitespace", - "remove", - "utility" - ], - "contributors": [], - "code": "def remove_whitespace(s):\n return ''.join(s.split())\n\n# Usage:\nprint(remove_whitespace('hello world')) # Output: 'helloworld'\n" - }, - { - "title": "Reverse String", - "description": "Reverses the characters in a string.", - "author": "dostonnabotov", - "tags": [ - "python", - "string", - "reverse", - "utility" - ], - "contributors": [], - "code": "def reverse_string(s):\n return s[::-1]\n\n# Usage:\nprint(reverse_string('hello')) # Output: 'olleh'\n" - }, - { - "title": "Split Camel Case", - "description": "Splits a camel case string into separate words.", - "author": "axorax", - "tags": [ - "python", - "string", - "camel-case", - "split", - "utility" - ], - "contributors": [], - "code": "import re\n\ndef split_camel_case(s):\n return ' '.join(re.findall(r'[A-Z][a-z]*|[a-z]+', s))\n\n# Usage:\nprint(split_camel_case('camelCaseString')) # Output: 'camel Case String'\n" - }, - { - "title": "Truncate String", - "description": "Truncates a string to a specified length and adds an ellipsis.", - "author": "axorax", - "tags": [ - "python", - "string", - "truncate", - "utility" - ], - "contributors": [], - "code": "def truncate_string(s, length):\n return s[:length] + '...' if len(s) > length else s\n\n# Usage:\nprint(truncate_string('This is a long string', 10)) # Output: 'This is a ...'\n" - } - ] - }, - { - "language": "python", - "categoryName": "Utilities", - "snippets": [ - { - "title": "Convert Bytes to Human-Readable Format", - "description": "Converts a size in bytes to a human-readable format.", - "author": "axorax", - "tags": [ - "python", - "bytes", - "format", - "utility" - ], - "contributors": [], - "code": "def bytes_to_human_readable(num):\n for unit in ['B', 'KB', 'MB', 'GB', 'TB', 'PB']:\n if num < 1024:\n return f\"{num:.2f} {unit}\"\n num /= 1024\n\n# Usage:\nprint(bytes_to_human_readable(123456789)) # Output: '117.74 MB'\n" - }, - { - "title": "Generate Random String", - "description": "Generates a random alphanumeric string.", - "author": "dostonnabotov", - "tags": [ - "python", - "random", - "string", - "utility" - ], - "contributors": [], - "code": "import random\nimport string\n\ndef random_string(length):\n letters_and_digits = string.ascii_letters + string.digits\n return ''.join(random.choice(letters_and_digits) for _ in range(length))\n\n# Usage:\nprint(random_string(10)) # Output: Random 10-character string\n" - }, - { - "title": "Measure Execution Time", - "description": "Measures the execution time of a code block.", - "author": "dostonnabotov", - "tags": [ - "python", - "time", - "execution", - "utility" - ], - "contributors": [], - "code": "import time\n\ndef measure_time(func, *args):\n start = time.time()\n result = func(*args)\n end = time.time()\n print(f'Execution time: {end - start:.6f} seconds')\n return result\n\n# Usage:\ndef slow_function():\n time.sleep(2)\n\nmeasure_time(slow_function)\n" - } - ] - }, - { - "language": "rust", - "categoryName": "Basics", - "snippets": [ - { - "title": "Hello, World!", - "description": "Prints Hello, World! to the terminal.", - "author": "James-Beans", - "tags": [ - "rust", - "printing", - "hello-world", - "utility" - ], - "contributors": [], - "code": "fn main() { // Defines the main running function\n println!(\"Hello, World!\"); // Prints Hello, World! to the terminal.\n}\n" - } - ] - }, - { - "language": "rust", - "categoryName": "File Handling", - "snippets": [ - { - "title": "Find Files", - "description": "Finds all files of the specified extension within a given directory.", - "author": "Mathys-Gasnier", - "tags": [ - "rust", - "file", - "search" - ], - "contributors": [], - "code": "fn find_files(directory: &str, file_type: &str) -> std::io::Result> {\n let mut result = vec![];\n\n for entry in std::fs::read_dir(directory)? {\n let dir = entry?;\n let path = dir.path();\n if dir.file_type().is_ok_and(|t| !t.is_file()) &&\n path.extension().is_some_and(|ext| ext != file_type) {\n continue;\n }\n result.push(path)\n }\n\n Ok(result)\n}\n\n// Usage:\nlet files = find_files(\"/path/to/your/directory\", \".pdf\")\n" - }, - { - "title": "Read File Lines", - "description": "Reads all lines from a file and returns them as a vector of strings.", - "author": "Mathys-Gasnier", - "tags": [ - "rust", - "file", - "read", - "utility" - ], - "contributors": [], - "code": "fn read_lines(file_name: &str) -> std::io::Result>\n Ok(\n std::fs::read_to_string(file_name)?\n .lines()\n .map(String::from)\n .collect()\n )\n}\n\n// Usage:\nlet lines = read_lines(\"path/to/file.txt\").expect(\"Failed to read lines from file\")\n" - } - ] - }, - { - "language": "rust", - "categoryName": "String Manipulation", - "snippets": [ - { - "title": "Capitalize String", - "description": "Makes the first letter of a string uppercase.", - "author": "Mathys-Gasnier", - "tags": [ - "rust", - "string", - "capitalize", - "utility" - ], - "contributors": [], - "code": "fn capitalized(str: &str) -> String {\n let mut chars = str.chars();\n match chars.next() {\n None => String::new(),\n Some(f) => f.to_uppercase().chain(chars).collect(),\n }\n}\n\n// Usage:\nassert_eq!(capitalized(\"lower_case\"), \"Lower_case\")\n" - } - ] - }, - { - "language": "scss", - "categoryName": "Animations", - "snippets": [ - { - "title": "Fade In Animation", - "description": "Animates the fade-in effect.", - "author": "dostonnabotov", - "tags": [ - "scss", - "animation", - "fade", - "css" - ], - "contributors": [], - "code": "@keyframes fade-in {\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n}\n\n@mixin fade-in($duration: 1s, $easing: ease-in-out) {\n animation: fade-in $duration $easing;\n}\n" - }, - { - "title": "Slide In From Left", - "description": "Animates content sliding in from the left.", - "author": "dostonnabotov", - "tags": [ - "scss", - "animation", - "slide", - "css" - ], - "contributors": [], - "code": "@keyframes slide-in-left {\n from {\n transform: translateX(-100%);\n }\n to {\n transform: translateX(0);\n }\n}\n\n@mixin slide-in-left($duration: 0.5s, $easing: ease-out) {\n animation: slide-in-left $duration $easing;\n}\n" - } - ] - }, - { - "language": "scss", - "categoryName": "Borders Shadows", - "snippets": [ - { - "title": "Border Radius Helper", - "description": "Applies a customizable border-radius.", - "author": "dostonnabotov", - "tags": [ - "scss", - "border", - "radius", - "css" - ], - "contributors": [], - "code": "@mixin border-radius($radius: 4px) {\n border-radius: $radius;\n}\n" - }, - { - "title": "Box Shadow Helper", - "description": "Generates a box shadow with customizable values.", - "author": "dostonnabotov", - "tags": [ - "scss", - "box-shadow", - "css", - "effects" - ], - "contributors": [], - "code": "@mixin box-shadow($x: 0px, $y: 4px, $blur: 10px, $spread: 0px, $color: rgba(0, 0, 0, 0.1)) {\n box-shadow: $x $y $blur $spread $color;\n}\n" - } - ] - }, - { - "language": "scss", - "categoryName": "Components", - "snippets": [ - { - "title": "Primary Button", - "description": "Generates a styled primary button.", - "author": "dostonnabotov", - "tags": [ - "scss", - "button", - "primary", - "css" - ], - "contributors": [], - "code": "@mixin primary-button($bg: #007bff, $color: #fff) {\n background-color: $bg;\n color: $color;\n padding: 0.5rem 1rem;\n border: none;\n border-radius: 4px;\n cursor: pointer;\n\n &:hover {\n background-color: darken($bg, 10%);\n }\n}\n" - } - ] - }, - { - "language": "scss", - "categoryName": "Layouts", - "snippets": [ - { - "title": "Aspect Ratio", - "description": "Ensures that elements maintain a specific aspect ratio.", - "author": "dostonnabotov", - "tags": [ - "scss", - "aspect-ratio", - "layout", - "css" - ], - "contributors": [], - "code": "@mixin aspect-ratio($width, $height) {\n position: relative;\n width: 100%;\n padding-top: ($height / $width) * 100%;\n > * {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n }\n}\n" - }, - { - "title": "Flex Center", - "description": "A mixin to center content using flexbox.", - "author": "dostonnabotov", - "tags": [ - "scss", - "flex", - "center", - "css" - ], - "contributors": [], - "code": "@mixin flex-center {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n" - }, - { - "title": "Grid Container", - "description": "Creates a responsive grid container with customizable column counts.", - "author": "dostonnabotov", - "tags": [ - "scss", - "grid", - "layout", - "css" - ], - "contributors": [], - "code": "@mixin grid-container($columns: 12, $gap: 1rem) {\n display: grid;\n grid-template-columns: repeat($columns, 1fr);\n gap: $gap;\n}\n" - } - ] - }, - { - "language": "scss", - "categoryName": "Typography", - "snippets": [ - { - "title": "Font Import Helper", - "description": "Simplifies importing custom fonts in Sass.", - "author": "dostonnabotov", - "tags": [ - "sass", - "mixin", - "fonts", - "css" - ], - "contributors": [], - "code": "@mixin import-font($family, $weight: 400, $style: normal) {\n @font-face {\n font-family: #{$family};\n font-weight: #{$weight};\n font-style: #{$style};\n src: url('/fonts/#{$family}-#{$weight}.woff2') format('woff2'),\n url('/fonts/#{$family}-#{$weight}.woff') format('woff');\n }\n}\n" - }, - { - "title": "Line Clamp Mixin", - "description": "A Sass mixin to clamp text to a specific number of lines.", - "author": "dostonnabotov", - "tags": [ - "sass", - "mixin", - "typography", - "css" - ], - "contributors": [], - "code": "@mixin line-clamp($number) {\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: $number;\n overflow: hidden;\n}\n" - }, - { - "title": "Text Gradient", - "description": "Adds a gradient color effect to text.", - "author": "dostonnabotov", - "tags": [ - "sass", - "mixin", - "gradient", - "text", - "css" - ], - "contributors": [], - "code": "@mixin text-gradient($from, $to) {\n background: linear-gradient(to right, $from, $to);\n -webkit-background-clip: text;\n -webkit-text-fill-color: transparent;\n}\n" - }, - { - "title": "Text Overflow Ellipsis", - "description": "Ensures long text is truncated with an ellipsis.", - "author": "dostonnabotov", - "tags": [ - "sass", - "mixin", - "text", - "css" - ], - "contributors": [], - "code": "@mixin text-ellipsis {\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n" - } - ] - }, - { - "language": "scss", - "categoryName": "Utilities", - "snippets": [ - { - "title": "Clearfix", - "description": "Provides a clearfix utility for floating elements.", - "author": "dostonnabotov", - "tags": [ - "scss", - "clearfix", - "utility", - "css" - ], - "contributors": [], - "code": "@mixin clearfix {\n &::after {\n content: '';\n display: block;\n clear: both;\n }\n}\n" - }, - { - "title": "Responsive Breakpoints", - "description": "Generates media queries for responsive design.", - "author": "dostonnabotov", - "tags": [ - "scss", - "responsive", - "media-queries", - "css" - ], - "contributors": [], - "code": "@mixin breakpoint($breakpoint) {\n @if $breakpoint == sm {\n @media (max-width: 576px) { @content; }\n } @else if $breakpoint == md {\n @media (max-width: 768px) { @content; }\n } @else if $breakpoint == lg {\n @media (max-width: 992px) { @content; }\n } @else if $breakpoint == xl {\n @media (max-width: 1200px) { @content; }\n }\n}\n" - } - ] - } -] \ No newline at end of file diff --git a/public/data/c.json b/public/consolidated/c.json similarity index 100% rename from public/data/c.json rename to public/consolidated/c.json diff --git a/public/data/cpp.json b/public/consolidated/cpp.json similarity index 100% rename from public/data/cpp.json rename to public/consolidated/cpp.json diff --git a/public/data/css.json b/public/consolidated/css.json similarity index 100% rename from public/data/css.json rename to public/consolidated/css.json diff --git a/public/data/html.json b/public/consolidated/html.json similarity index 100% rename from public/data/html.json rename to public/consolidated/html.json diff --git a/public/data/javascript.json b/public/consolidated/javascript.json similarity index 100% rename from public/data/javascript.json rename to public/consolidated/javascript.json diff --git a/public/data/python.json b/public/consolidated/python.json similarity index 100% rename from public/data/python.json rename to public/consolidated/python.json diff --git a/public/data/rust.json b/public/consolidated/rust.json similarity index 100% rename from public/data/rust.json rename to public/consolidated/rust.json diff --git a/public/data/scss.json b/public/consolidated/scss.json similarity index 100% rename from public/data/scss.json rename to public/consolidated/scss.json diff --git a/snippets/c/basics/hello-world.md b/snippets/c/basics/hello-world.md index c414ab9b..c8122d5a 100644 --- a/snippets/c/basics/hello-world.md +++ b/snippets/c/basics/hello-world.md @@ -1,8 +1,8 @@ --- -Title: Hello, World! -Description: Prints Hello, World! to the terminal. -Author: 0xHouss -Tags: c,printing,hello-world,utility +title: Hello, World! +description: Prints Hello, World! to the terminal. +author: 0xHouss +tags: c,printing,hello-world,utility --- ```c diff --git a/snippets/c/mathematical-functions/factorial-function.md b/snippets/c/mathematical-functions/factorial-function.md index 3dc0118e..7e8a7b08 100644 --- a/snippets/c/mathematical-functions/factorial-function.md +++ b/snippets/c/mathematical-functions/factorial-function.md @@ -1,8 +1,8 @@ --- -Title: Factorial Function -Description: Calculates the factorial of a number. -Author: 0xHouss -Tags: c,math,factorial,utility +title: Factorial Function +description: Calculates the factorial of a number. +author: 0xHouss +tags: c,math,factorial,utility --- ```c diff --git a/snippets/c/mathematical-functions/power-function.md b/snippets/c/mathematical-functions/power-function.md index 31846ea1..c9a81262 100644 --- a/snippets/c/mathematical-functions/power-function.md +++ b/snippets/c/mathematical-functions/power-function.md @@ -1,8 +1,8 @@ --- -Title: Power Function -Description: Calculates the power of a number. -Author: 0xHouss -Tags: c,math,power,utility +title: Power Function +description: Calculates the power of a number. +author: 0xHouss +tags: c,math,power,utility --- ```c diff --git a/snippets/cpp/basics/hello-world.md b/snippets/cpp/basics/hello-world.md index be5010f2..eadaa386 100644 --- a/snippets/cpp/basics/hello-world.md +++ b/snippets/cpp/basics/hello-world.md @@ -1,8 +1,8 @@ --- -Title: Hello, World! -Description: Prints Hello, World! to the terminal. -Author: James-Beans -Tags: cpp,printing,hello-world,utility +title: Hello, World! +description: Prints Hello, World! to the terminal. +author: James-Beans +tags: cpp,printing,hello-world,utility --- ```cpp diff --git a/snippets/cpp/string-manipulation/reverse-string.md b/snippets/cpp/string-manipulation/reverse-string.md index 58d35829..de209c88 100644 --- a/snippets/cpp/string-manipulation/reverse-string.md +++ b/snippets/cpp/string-manipulation/reverse-string.md @@ -1,8 +1,8 @@ --- -Title: Reverse String -Description: Reverses the characters in a string. -Author: Vaibhav-kesarwani -Tags: cpp,array,reverse,utility +title: Reverse String +description: Reverses the characters in a string. +author: Vaibhav-kesarwani +tags: cpp,array,reverse,utility --- ```cpp diff --git a/snippets/cpp/string-manipulation/split-string.md b/snippets/cpp/string-manipulation/split-string.md index 450d0c3b..f903a2b2 100644 --- a/snippets/cpp/string-manipulation/split-string.md +++ b/snippets/cpp/string-manipulation/split-string.md @@ -1,8 +1,8 @@ --- -Title: Split String -Description: Splits a string by a delimiter -Author: saminjay -Tags: cpp,string,split,utility +title: Split String +description: Splits a string by a delimiter +author: saminjay +tags: cpp,string,split,utility --- ```cpp diff --git a/snippets/css/buttons/3d-button-effect.md b/snippets/css/buttons/3d-button-effect.md index 59e4bbc3..3498993a 100644 --- a/snippets/css/buttons/3d-button-effect.md +++ b/snippets/css/buttons/3d-button-effect.md @@ -1,8 +1,8 @@ --- -Title: 3D Button Effect -Description: Adds a 3D effect to a button when clicked. -Author: dostonnabotov -Tags: css,button,3D,effect +title: 3D Button Effect +description: Adds a 3D effect to a button when clicked. +author: dostonnabotov +tags: css,button,3D,effect --- ```css diff --git a/snippets/css/buttons/button-hover-effect.md b/snippets/css/buttons/button-hover-effect.md index 635c7dec..22f4c2d4 100644 --- a/snippets/css/buttons/button-hover-effect.md +++ b/snippets/css/buttons/button-hover-effect.md @@ -1,8 +1,8 @@ --- -Title: Button Hover Effect -Description: Creates a hover effect with a color transition. -Author: dostonnabotov -Tags: css,button,hover,transition +title: Button Hover Effect +description: Creates a hover effect with a color transition. +author: dostonnabotov +tags: css,button,hover,transition --- ```css diff --git a/snippets/css/buttons/macos-button.md b/snippets/css/buttons/macos-button.md index cfd94671..2da30207 100644 --- a/snippets/css/buttons/macos-button.md +++ b/snippets/css/buttons/macos-button.md @@ -1,8 +1,8 @@ --- -Title: MacOS Button -Description: A macOS-like button style, with hover and shading effects. -Author: e3nviction -Tags: css,button,macos,hover,transition +title: MacOS Button +description: A macOS-like button style, with hover and shading effects. +author: e3nviction +tags: css,button,macos,hover,transition --- ```css diff --git a/snippets/css/effects/blur-background.md b/snippets/css/effects/blur-background.md index 41f579a4..2891e820 100644 --- a/snippets/css/effects/blur-background.md +++ b/snippets/css/effects/blur-background.md @@ -1,8 +1,8 @@ --- -Title: Blur Background -Description: Applies a blur effect to the background of an element. -Author: dostonnabotov -Tags: css,blur,background,effects +title: Blur Background +description: Applies a blur effect to the background of an element. +author: dostonnabotov +tags: css,blur,background,effects --- ```css diff --git a/snippets/css/effects/hover-glow-effect.md b/snippets/css/effects/hover-glow-effect.md index b2af4ef7..2c2ec862 100644 --- a/snippets/css/effects/hover-glow-effect.md +++ b/snippets/css/effects/hover-glow-effect.md @@ -1,8 +1,8 @@ --- -Title: Hover Glow Effect -Description: Adds a glowing effect on hover. -Author: dostonnabotov -Tags: css,hover,glow,effects +title: Hover Glow Effect +description: Adds a glowing effect on hover. +author: dostonnabotov +tags: css,hover,glow,effects --- ```css diff --git a/snippets/css/effects/hover-to-reveal-color.md b/snippets/css/effects/hover-to-reveal-color.md index 18d5f746..0a355e5a 100644 --- a/snippets/css/effects/hover-to-reveal-color.md +++ b/snippets/css/effects/hover-to-reveal-color.md @@ -1,8 +1,8 @@ --- -Title: Hover to Reveal Color -Description: A card with an image that transitions from grayscale to full color on hover. -Author: Haider-Mukhtar -Tags: css,hover,image,effects +title: Hover to Reveal Color +description: A card with an image that transitions from grayscale to full color on hover. +author: Haider-Mukhtar +tags: css,hover,image,effects --- ```css diff --git a/snippets/css/layouts/css-reset.md b/snippets/css/layouts/css-reset.md index a5127b11..9195135b 100644 --- a/snippets/css/layouts/css-reset.md +++ b/snippets/css/layouts/css-reset.md @@ -1,8 +1,8 @@ --- -Title: CSS Reset -Description: Resets some default browser styles, ensuring consistency across browsers. -Author: AmeerMoustafa -Tags: css,reset,browser,layout +title: CSS Reset +description: Resets some default browser styles, ensuring consistency across browsers. +author: AmeerMoustafa +tags: css,reset,browser,layout --- ```css diff --git a/snippets/css/layouts/equal-width-columns.md b/snippets/css/layouts/equal-width-columns.md index 3e1ef183..69b4128d 100644 --- a/snippets/css/layouts/equal-width-columns.md +++ b/snippets/css/layouts/equal-width-columns.md @@ -1,8 +1,8 @@ --- -Title: Equal-Width Columns -Description: Creates columns with equal widths using flexbox. -Author: dostonnabotov -Tags: css,flexbox,columns,layout +title: Equal-Width Columns +description: Creates columns with equal widths using flexbox. +author: dostonnabotov +tags: css,flexbox,columns,layout --- ```css diff --git a/snippets/css/layouts/grid-layout.md b/snippets/css/layouts/grid-layout.md index 00c34eaf..04ebd0e9 100644 --- a/snippets/css/layouts/grid-layout.md +++ b/snippets/css/layouts/grid-layout.md @@ -1,8 +1,8 @@ --- -Title: Grid layout -Description: Equal sized items in a responsive grid -Author: xshubhamg -Tags: css,layout,grid +title: Grid layout +description: Equal sized items in a responsive grid +author: xshubhamg +tags: css,layout,grid --- ```css diff --git a/snippets/css/layouts/responsive-design.md b/snippets/css/layouts/responsive-design.md index f4741e3f..6d983451 100644 --- a/snippets/css/layouts/responsive-design.md +++ b/snippets/css/layouts/responsive-design.md @@ -1,8 +1,8 @@ --- -Title: Responsive Design -Description: The different responsive breakpoints. -Author: kruimol -Tags: css,responsive +title: Responsive Design +description: The different responsive breakpoints. +author: kruimol +tags: css,responsive --- ```css diff --git a/snippets/css/layouts/sticky-footer.md b/snippets/css/layouts/sticky-footer.md index bf4bd422..8c8c7f09 100644 --- a/snippets/css/layouts/sticky-footer.md +++ b/snippets/css/layouts/sticky-footer.md @@ -1,8 +1,8 @@ --- -Title: Sticky Footer -Description: Ensures the footer always stays at the bottom of the page. -Author: dostonnabotov -Tags: css,layout,footer,sticky +title: Sticky Footer +description: Ensures the footer always stays at the bottom of the page. +author: dostonnabotov +tags: css,layout,footer,sticky --- ```css diff --git a/snippets/css/typography/letter-spacing.md b/snippets/css/typography/letter-spacing.md index df034688..4871b714 100644 --- a/snippets/css/typography/letter-spacing.md +++ b/snippets/css/typography/letter-spacing.md @@ -1,8 +1,8 @@ --- -Title: Letter Spacing -Description: Adds space between letters for better readability. -Author: dostonnabotov -Tags: css,typography,spacing +title: Letter Spacing +description: Adds space between letters for better readability. +author: dostonnabotov +tags: css,typography,spacing --- ```css diff --git a/snippets/css/typography/responsive-font-sizing.md b/snippets/css/typography/responsive-font-sizing.md index 42fc7014..7eb87f2c 100644 --- a/snippets/css/typography/responsive-font-sizing.md +++ b/snippets/css/typography/responsive-font-sizing.md @@ -1,8 +1,8 @@ --- -Title: Responsive Font Sizing -Description: Adjusts font size based on viewport width. -Author: dostonnabotov -Tags: css,font,responsive,typography +title: Responsive Font Sizing +description: Adjusts font size based on viewport width. +author: dostonnabotov +tags: css,font,responsive,typography --- ```css diff --git a/snippets/html/basic-layouts/grid-layout-with-navigation.md b/snippets/html/basic-layouts/grid-layout-with-navigation.md index 7a2090ad..da6c47cf 100644 --- a/snippets/html/basic-layouts/grid-layout-with-navigation.md +++ b/snippets/html/basic-layouts/grid-layout-with-navigation.md @@ -1,8 +1,8 @@ --- -Title: Grid Layout with Navigation -Description: Full-height grid layout with header navigation using nesting syntax. -Author: GreenMan36 -Tags: html,css,layout,sticky,grid,full-height +title: Grid Layout with Navigation +description: Full-height grid layout with header navigation using nesting syntax. +author: GreenMan36 +tags: html,css,layout,sticky,grid,full-height --- ```html diff --git a/snippets/html/basic-layouts/sticky-header-footer-layout.md b/snippets/html/basic-layouts/sticky-header-footer-layout.md index 6cb30dd1..26c065eb 100644 --- a/snippets/html/basic-layouts/sticky-header-footer-layout.md +++ b/snippets/html/basic-layouts/sticky-header-footer-layout.md @@ -1,8 +1,8 @@ --- -Title: Sticky Header-Footer Layout -Description: Full-height layout with sticky header and footer, using modern viewport units and flexbox. -Author: GreenMan36 -Tags: html,css,layout,sticky,flexbox,viewport +title: Sticky Header-Footer Layout +description: Full-height layout with sticky header and footer, using modern viewport units and flexbox. +author: GreenMan36 +tags: html,css,layout,sticky,flexbox,viewport --- ```html diff --git a/snippets/javascript/array-manipulation/flatten-array.md b/snippets/javascript/array-manipulation/flatten-array.md index a92e37c2..7d2546d8 100644 --- a/snippets/javascript/array-manipulation/flatten-array.md +++ b/snippets/javascript/array-manipulation/flatten-array.md @@ -1,8 +1,8 @@ --- -Title: Flatten Array -Description: Flattens a multi-dimensional array. -Author: dostonnabotov -Tags: javascript,array,flatten,utility +title: Flatten Array +description: Flattens a multi-dimensional array. +author: dostonnabotov +tags: javascript,array,flatten,utility --- ```js diff --git a/snippets/javascript/array-manipulation/remove-duplicates.md b/snippets/javascript/array-manipulation/remove-duplicates.md index 6c576c01..134bfc89 100644 --- a/snippets/javascript/array-manipulation/remove-duplicates.md +++ b/snippets/javascript/array-manipulation/remove-duplicates.md @@ -1,8 +1,8 @@ --- -Title: Remove Duplicates -Description: Removes duplicate values from an array. -Author: dostonnabotov -Tags: javascript,array,deduplicate,utility +title: Remove Duplicates +description: Removes duplicate values from an array. +author: dostonnabotov +tags: javascript,array,deduplicate,utility --- ```js diff --git a/snippets/javascript/array-manipulation/shuffle-array.md b/snippets/javascript/array-manipulation/shuffle-array.md index 0a1a0379..7f41f9aa 100644 --- a/snippets/javascript/array-manipulation/shuffle-array.md +++ b/snippets/javascript/array-manipulation/shuffle-array.md @@ -1,8 +1,8 @@ --- -Title: Shuffle Array -Description: Shuffles an Array. -Author: loxt-nixo -Tags: javascript,array,shuffle,utility +title: Shuffle Array +description: Shuffles an Array. +author: loxt-nixo +tags: javascript,array,shuffle,utility --- ```js diff --git a/snippets/javascript/array-manipulation/zip-arrays.md b/snippets/javascript/array-manipulation/zip-arrays.md index 673b83d0..12d3a7d7 100644 --- a/snippets/javascript/array-manipulation/zip-arrays.md +++ b/snippets/javascript/array-manipulation/zip-arrays.md @@ -1,8 +1,8 @@ --- -Title: Zip Arrays -Description: Combines two arrays by pairing corresponding elements from each array. -Author: Swaraj-Singh-30 -Tags: javascript,array,utility,map +title: Zip Arrays +description: Combines two arrays by pairing corresponding elements from each array. +author: Swaraj-Singh-30 +tags: javascript,array,utility,map --- ```js diff --git a/snippets/javascript/basics/hello-world.md b/snippets/javascript/basics/hello-world.md index bfa646cc..b65c84b9 100644 --- a/snippets/javascript/basics/hello-world.md +++ b/snippets/javascript/basics/hello-world.md @@ -1,8 +1,8 @@ --- -Title: Hello, World! -Description: Prints Hello, World! to the terminal. -Author: James-Beans -Tags: javascript,printing,hello-world,utility +title: Hello, World! +description: Prints Hello, World! to the terminal. +author: James-Beans +tags: javascript,printing,hello-world,utility --- ```js diff --git a/snippets/javascript/date-and-time/add-days-to-a-date.md b/snippets/javascript/date-and-time/add-days-to-a-date.md index bd4436f7..34cb879a 100644 --- a/snippets/javascript/date-and-time/add-days-to-a-date.md +++ b/snippets/javascript/date-and-time/add-days-to-a-date.md @@ -1,8 +1,8 @@ --- -Title: Add Days to a Date -Description: Adds a specified number of days to a given date. -Author: axorax -Tags: javascript,date,add-days,utility +title: Add Days to a Date +description: Adds a specified number of days to a given date. +author: axorax +tags: javascript,date,add-days,utility --- ```js diff --git a/snippets/javascript/date-and-time/check-leap-year.md b/snippets/javascript/date-and-time/check-leap-year.md index 7720e89e..c65fac67 100644 --- a/snippets/javascript/date-and-time/check-leap-year.md +++ b/snippets/javascript/date-and-time/check-leap-year.md @@ -1,8 +1,8 @@ --- -Title: Check Leap Year -Description: Determines if a given year is a leap year. -Author: axorax -Tags: javascript,date,leap-year,utility +title: Check Leap Year +description: Determines if a given year is a leap year. +author: axorax +tags: javascript,date,leap-year,utility --- ```js diff --git a/snippets/javascript/date-and-time/convert-to-unix-timestamp.md b/snippets/javascript/date-and-time/convert-to-unix-timestamp.md index 229ce5f2..87bcceaa 100644 --- a/snippets/javascript/date-and-time/convert-to-unix-timestamp.md +++ b/snippets/javascript/date-and-time/convert-to-unix-timestamp.md @@ -1,8 +1,8 @@ --- -Title: Convert to Unix Timestamp -Description: Converts a date to a Unix timestamp in seconds. -Author: Yugveer06 -Tags: javascript,date,unix,timestamp,utility +title: Convert to Unix Timestamp +description: Converts a date to a Unix timestamp in seconds. +author: Yugveer06 +tags: javascript,date,unix,timestamp,utility --- ```js diff --git a/snippets/javascript/date-and-time/format-date.md b/snippets/javascript/date-and-time/format-date.md index fad01ad2..db75a004 100644 --- a/snippets/javascript/date-and-time/format-date.md +++ b/snippets/javascript/date-and-time/format-date.md @@ -1,8 +1,8 @@ --- -Title: Format Date -Description: Formats a date in 'YYYY-MM-DD' format. -Author: dostonnabotov -Tags: javascript,date,format,utility +title: Format Date +description: Formats a date in 'YYYY-MM-DD' format. +author: dostonnabotov +tags: javascript,date,format,utility --- ```js diff --git a/snippets/javascript/date-and-time/get-current-timestamp.md b/snippets/javascript/date-and-time/get-current-timestamp.md index fb9fd34c..2581e299 100644 --- a/snippets/javascript/date-and-time/get-current-timestamp.md +++ b/snippets/javascript/date-and-time/get-current-timestamp.md @@ -1,8 +1,8 @@ --- -Title: Get Current Timestamp -Description: Retrieves the current timestamp in milliseconds since January 1, 1970. -Author: axorax -Tags: javascript,date,timestamp,utility +title: Get Current Timestamp +description: Retrieves the current timestamp in milliseconds since January 1, 1970. +author: axorax +tags: javascript,date,timestamp,utility --- ```js diff --git a/snippets/javascript/date-and-time/get-day-of-the-year.md b/snippets/javascript/date-and-time/get-day-of-the-year.md index 3c6226a4..9ac076db 100644 --- a/snippets/javascript/date-and-time/get-day-of-the-year.md +++ b/snippets/javascript/date-and-time/get-day-of-the-year.md @@ -1,8 +1,8 @@ --- -Title: Get Day of the Year -Description: Calculates the day of the year (1-365 or 1-366 for leap years) for a given date. -Author: axorax -Tags: javascript,date,day-of-year,utility +title: Get Day of the Year +description: Calculates the day of the year (1-365 or 1-366 for leap years) for a given date. +author: axorax +tags: javascript,date,day-of-year,utility --- ```js diff --git a/snippets/javascript/date-and-time/get-days-in-month.md b/snippets/javascript/date-and-time/get-days-in-month.md index 4a083aa5..d1c97b3e 100644 --- a/snippets/javascript/date-and-time/get-days-in-month.md +++ b/snippets/javascript/date-and-time/get-days-in-month.md @@ -1,8 +1,8 @@ --- -Title: Get Days in Month -Description: Calculates the number of days in a specific month of a given year. -Author: axorax -Tags: javascript,date,days-in-month,utility +title: Get Days in Month +description: Calculates the number of days in a specific month of a given year. +author: axorax +tags: javascript,date,days-in-month,utility --- ```js diff --git a/snippets/javascript/date-and-time/get-time-difference.md b/snippets/javascript/date-and-time/get-time-difference.md index c0193221..57f4e210 100644 --- a/snippets/javascript/date-and-time/get-time-difference.md +++ b/snippets/javascript/date-and-time/get-time-difference.md @@ -1,8 +1,8 @@ --- -Title: Get Time Difference -Description: Calculates the time difference in days between two dates. -Author: dostonnabotov -Tags: javascript,date,time-difference,utility +title: Get Time Difference +description: Calculates the time difference in days between two dates. +author: dostonnabotov +tags: javascript,date,time-difference,utility --- ```js diff --git a/snippets/javascript/date-and-time/relative-time-formatter.md b/snippets/javascript/date-and-time/relative-time-formatter.md index 83130cb4..936f6aaa 100644 --- a/snippets/javascript/date-and-time/relative-time-formatter.md +++ b/snippets/javascript/date-and-time/relative-time-formatter.md @@ -1,8 +1,8 @@ --- -Title: Relative Time Formatter -Description: Displays how long ago a date occurred or how far in the future a date is. -Author: Yugveer06 -Tags: javascript,date,time,relative,future,past,utility +title: Relative Time Formatter +description: Displays how long ago a date occurred or how far in the future a date is. +author: Yugveer06 +tags: javascript,date,time,relative,future,past,utility --- ```js diff --git a/snippets/javascript/date-and-time/start-of-the-day.md b/snippets/javascript/date-and-time/start-of-the-day.md index 533b7159..39d417a8 100644 --- a/snippets/javascript/date-and-time/start-of-the-day.md +++ b/snippets/javascript/date-and-time/start-of-the-day.md @@ -1,8 +1,8 @@ --- -Title: Start of the Day -Description: Returns the start of the day (midnight) for a given date. -Author: axorax -Tags: javascript,date,start-of-day,utility +title: Start of the Day +description: Returns the start of the day (midnight) for a given date. +author: axorax +tags: javascript,date,start-of-day,utility --- ```js diff --git a/snippets/javascript/dom-manipulation/change-element-style.md b/snippets/javascript/dom-manipulation/change-element-style.md index a37eaa82..32ec73ea 100644 --- a/snippets/javascript/dom-manipulation/change-element-style.md +++ b/snippets/javascript/dom-manipulation/change-element-style.md @@ -1,8 +1,8 @@ --- -Title: Change Element Style -Description: Changes the inline style of an element. -Author: axorax -Tags: javascript,dom,style,utility +title: Change Element Style +description: Changes the inline style of an element. +author: axorax +tags: javascript,dom,style,utility --- ```js diff --git a/snippets/javascript/dom-manipulation/get-element-position.md b/snippets/javascript/dom-manipulation/get-element-position.md index cd7ce3c8..e7958b6a 100644 --- a/snippets/javascript/dom-manipulation/get-element-position.md +++ b/snippets/javascript/dom-manipulation/get-element-position.md @@ -1,8 +1,8 @@ --- -Title: Get Element Position -Description: Gets the position of an element relative to the viewport. -Author: axorax -Tags: javascript,dom,position,utility +title: Get Element Position +description: Gets the position of an element relative to the viewport. +author: axorax +tags: javascript,dom,position,utility --- ```js diff --git a/snippets/javascript/dom-manipulation/remove-element.md b/snippets/javascript/dom-manipulation/remove-element.md index 9cfe9084..5874b3cd 100644 --- a/snippets/javascript/dom-manipulation/remove-element.md +++ b/snippets/javascript/dom-manipulation/remove-element.md @@ -1,8 +1,8 @@ --- -Title: Remove Element -Description: Removes a specified element from the DOM. -Author: axorax -Tags: javascript,dom,remove,utility +title: Remove Element +description: Removes a specified element from the DOM. +author: axorax +tags: javascript,dom,remove,utility --- ```js diff --git a/snippets/javascript/dom-manipulation/smooth-scroll-to-element.md b/snippets/javascript/dom-manipulation/smooth-scroll-to-element.md index b6900196..eccc9c68 100644 --- a/snippets/javascript/dom-manipulation/smooth-scroll-to-element.md +++ b/snippets/javascript/dom-manipulation/smooth-scroll-to-element.md @@ -1,8 +1,8 @@ --- -Title: Smooth Scroll to Element -Description: Scrolls smoothly to a specified element. -Author: dostonnabotov -Tags: javascript,dom,scroll,ui +title: Smooth Scroll to Element +description: Scrolls smoothly to a specified element. +author: dostonnabotov +tags: javascript,dom,scroll,ui --- ```js diff --git a/snippets/javascript/dom-manipulation/toggle-class.md b/snippets/javascript/dom-manipulation/toggle-class.md index 08ee2f38..30473093 100644 --- a/snippets/javascript/dom-manipulation/toggle-class.md +++ b/snippets/javascript/dom-manipulation/toggle-class.md @@ -1,8 +1,8 @@ --- -Title: Toggle Class -Description: Toggles a class on an element. -Author: dostonnabotov -Tags: javascript,dom,class,utility +title: Toggle Class +description: Toggles a class on an element. +author: dostonnabotov +tags: javascript,dom,class,utility --- ```js diff --git a/snippets/javascript/function-utilities/compose-functions.md b/snippets/javascript/function-utilities/compose-functions.md index 2de032d8..f05da50e 100644 --- a/snippets/javascript/function-utilities/compose-functions.md +++ b/snippets/javascript/function-utilities/compose-functions.md @@ -1,8 +1,8 @@ --- -Title: Compose Functions -Description: Composes multiple functions into a single function, where the output of one function becomes the input of the next. -Author: axorax -Tags: javascript,function,compose,utility +title: Compose Functions +description: Composes multiple functions into a single function, where the output of one function becomes the input of the next. +author: axorax +tags: javascript,function,compose,utility --- ```js diff --git a/snippets/javascript/function-utilities/curry-function.md b/snippets/javascript/function-utilities/curry-function.md index 89a01b0a..aa74ab60 100644 --- a/snippets/javascript/function-utilities/curry-function.md +++ b/snippets/javascript/function-utilities/curry-function.md @@ -1,8 +1,8 @@ --- -Title: Curry Function -Description: Transforms a function into its curried form. -Author: axorax -Tags: javascript,curry,function,utility +title: Curry Function +description: Transforms a function into its curried form. +author: axorax +tags: javascript,curry,function,utility --- ```js diff --git a/snippets/javascript/function-utilities/debounce-function.md b/snippets/javascript/function-utilities/debounce-function.md index d73117d1..fc3674d4 100644 --- a/snippets/javascript/function-utilities/debounce-function.md +++ b/snippets/javascript/function-utilities/debounce-function.md @@ -1,8 +1,8 @@ --- -Title: Debounce Function -Description: Delays a function execution until after a specified time. -Author: dostonnabotov -Tags: javascript,utility,debounce,performance +title: Debounce Function +description: Delays a function execution until after a specified time. +author: dostonnabotov +tags: javascript,utility,debounce,performance --- ```js diff --git a/snippets/javascript/function-utilities/get-contrast-color.md b/snippets/javascript/function-utilities/get-contrast-color.md index b5ab4374..2dd5862b 100644 --- a/snippets/javascript/function-utilities/get-contrast-color.md +++ b/snippets/javascript/function-utilities/get-contrast-color.md @@ -1,8 +1,8 @@ --- -Title: Get Contrast Color -Description: Returns either black or white text color based on the brightness of the provided hex color. -Author: yaya12085 -Tags: javascript,color,hex,contrast,brightness,utility +title: Get Contrast Color +description: Returns either black or white text color based on the brightness of the provided hex color. +author: yaya12085 +tags: javascript,color,hex,contrast,brightness,utility --- ```js diff --git a/snippets/javascript/function-utilities/memoize-function.md b/snippets/javascript/function-utilities/memoize-function.md index dbda561b..dcde72bf 100644 --- a/snippets/javascript/function-utilities/memoize-function.md +++ b/snippets/javascript/function-utilities/memoize-function.md @@ -1,8 +1,8 @@ --- -Title: Memoize Function -Description: Caches the result of a function based on its arguments to improve performance. -Author: axorax -Tags: javascript,memoization,optimization,utility +title: Memoize Function +description: Caches the result of a function based on its arguments to improve performance. +author: axorax +tags: javascript,memoization,optimization,utility --- ```js diff --git a/snippets/javascript/function-utilities/once-function.md b/snippets/javascript/function-utilities/once-function.md index 3eb756b3..62db4b46 100644 --- a/snippets/javascript/function-utilities/once-function.md +++ b/snippets/javascript/function-utilities/once-function.md @@ -1,8 +1,8 @@ --- -Title: Once Function -Description: Ensures a function is only called once. -Author: axorax -Tags: javascript,function,once,utility +title: Once Function +description: Ensures a function is only called once. +author: axorax +tags: javascript,function,once,utility --- ```js diff --git a/snippets/javascript/function-utilities/rate-limit-function.md b/snippets/javascript/function-utilities/rate-limit-function.md index 0976c971..d6dc81b2 100644 --- a/snippets/javascript/function-utilities/rate-limit-function.md +++ b/snippets/javascript/function-utilities/rate-limit-function.md @@ -1,8 +1,8 @@ --- -Title: Rate Limit Function -Description: Limits how often a function can be executed within a given time window. -Author: axorax -Tags: javascript,function,rate-limiting,utility +title: Rate Limit Function +description: Limits how often a function can be executed within a given time window. +author: axorax +tags: javascript,function,rate-limiting,utility --- ```js diff --git a/snippets/javascript/function-utilities/repeat-function-invocation.md b/snippets/javascript/function-utilities/repeat-function-invocation.md index 7c66ed84..a425a995 100644 --- a/snippets/javascript/function-utilities/repeat-function-invocation.md +++ b/snippets/javascript/function-utilities/repeat-function-invocation.md @@ -1,8 +1,8 @@ --- -Title: Repeat Function Invocation -Description: Invokes a function a specified number of times. -Author: dostonnabotov -Tags: javascript,function,repeat,utility +title: Repeat Function Invocation +description: Invokes a function a specified number of times. +author: dostonnabotov +tags: javascript,function,repeat,utility --- ```js diff --git a/snippets/javascript/function-utilities/sleep-function.md b/snippets/javascript/function-utilities/sleep-function.md index 3964270c..991390ea 100644 --- a/snippets/javascript/function-utilities/sleep-function.md +++ b/snippets/javascript/function-utilities/sleep-function.md @@ -1,8 +1,8 @@ --- -Title: Sleep Function -Description: Waits for a specified amount of milliseconds before resolving. -Author: 0xHouss -Tags: javascript,sleep,delay,utility,promises +title: Sleep Function +description: Waits for a specified amount of milliseconds before resolving. +author: 0xHouss +tags: javascript,sleep,delay,utility,promises --- ```js diff --git a/snippets/javascript/function-utilities/throttle-function.md b/snippets/javascript/function-utilities/throttle-function.md index 9d8c1f95..a425479f 100644 --- a/snippets/javascript/function-utilities/throttle-function.md +++ b/snippets/javascript/function-utilities/throttle-function.md @@ -1,8 +1,8 @@ --- -Title: Throttle Function -Description: Limits a function execution to once every specified time interval. -Author: dostonnabotov -Tags: javascript,utility,throttle,performance +title: Throttle Function +description: Limits a function execution to once every specified time interval. +author: dostonnabotov +tags: javascript,utility,throttle,performance --- ```js diff --git a/snippets/javascript/local-storage/add-item-to-localstorage.md b/snippets/javascript/local-storage/add-item-to-localstorage.md index cb27da30..853f2949 100644 --- a/snippets/javascript/local-storage/add-item-to-localstorage.md +++ b/snippets/javascript/local-storage/add-item-to-localstorage.md @@ -1,8 +1,8 @@ --- -Title: Add Item to localStorage -Description: Stores a value in localStorage under the given key. -Author: dostonnabotov -Tags: javascript,localStorage,storage,utility +title: Add Item to localStorage +description: Stores a value in localStorage under the given key. +author: dostonnabotov +tags: javascript,localStorage,storage,utility --- ```js diff --git a/snippets/javascript/local-storage/check-if-item-exists-in-localstorage.md b/snippets/javascript/local-storage/check-if-item-exists-in-localstorage.md index 389beabb..77fbe5d5 100644 --- a/snippets/javascript/local-storage/check-if-item-exists-in-localstorage.md +++ b/snippets/javascript/local-storage/check-if-item-exists-in-localstorage.md @@ -1,8 +1,8 @@ --- -Title: Check if Item Exists in localStorage -Description: Checks if a specific item exists in localStorage. -Author: axorax -Tags: javascript,localStorage,storage,utility +title: Check if Item Exists in localStorage +description: Checks if a specific item exists in localStorage. +author: axorax +tags: javascript,localStorage,storage,utility --- ```js diff --git a/snippets/javascript/local-storage/clear-all-localstorage.md b/snippets/javascript/local-storage/clear-all-localstorage.md index da1c8e6f..f5f9a6d8 100644 --- a/snippets/javascript/local-storage/clear-all-localstorage.md +++ b/snippets/javascript/local-storage/clear-all-localstorage.md @@ -1,8 +1,8 @@ --- -Title: Clear All localStorage -Description: Clears all data from localStorage. -Author: dostonnabotov -Tags: javascript,localStorage,storage,utility +title: Clear All localStorage +description: Clears all data from localStorage. +author: dostonnabotov +tags: javascript,localStorage,storage,utility --- ```js diff --git a/snippets/javascript/local-storage/retrieve-item-from-localstorage.md b/snippets/javascript/local-storage/retrieve-item-from-localstorage.md index 003745f8..e6dba542 100644 --- a/snippets/javascript/local-storage/retrieve-item-from-localstorage.md +++ b/snippets/javascript/local-storage/retrieve-item-from-localstorage.md @@ -1,8 +1,8 @@ --- -Title: Retrieve Item from localStorage -Description: Retrieves a value from localStorage by key and parses it. -Author: dostonnabotov -Tags: javascript,localStorage,storage,utility +title: Retrieve Item from localStorage +description: Retrieves a value from localStorage by key and parses it. +author: dostonnabotov +tags: javascript,localStorage,storage,utility --- ```js diff --git a/snippets/javascript/number-formatting/convert-number-to-currency.md b/snippets/javascript/number-formatting/convert-number-to-currency.md index e1c49de3..2600cfd5 100644 --- a/snippets/javascript/number-formatting/convert-number-to-currency.md +++ b/snippets/javascript/number-formatting/convert-number-to-currency.md @@ -1,8 +1,8 @@ --- -Title: Convert Number to Currency -Description: Converts a number to a currency format with a specific locale. -Author: axorax -Tags: javascript,number,currency,utility +title: Convert Number to Currency +description: Converts a number to a currency format with a specific locale. +author: axorax +tags: javascript,number,currency,utility --- ```js diff --git a/snippets/javascript/number-formatting/convert-number-to-roman-numerals.md b/snippets/javascript/number-formatting/convert-number-to-roman-numerals.md index 1ed5bf81..7830174a 100644 --- a/snippets/javascript/number-formatting/convert-number-to-roman-numerals.md +++ b/snippets/javascript/number-formatting/convert-number-to-roman-numerals.md @@ -1,8 +1,8 @@ --- -Title: Convert Number to Roman Numerals -Description: Converts a number to Roman numeral representation. -Author: axorax -Tags: javascript,number,roman,utility +title: Convert Number to Roman Numerals +description: Converts a number to Roman numeral representation. +author: axorax +tags: javascript,number,roman,utility --- ```js diff --git a/snippets/javascript/number-formatting/convert-to-scientific-notation.md b/snippets/javascript/number-formatting/convert-to-scientific-notation.md index 631e9af2..dc16282d 100644 --- a/snippets/javascript/number-formatting/convert-to-scientific-notation.md +++ b/snippets/javascript/number-formatting/convert-to-scientific-notation.md @@ -1,8 +1,8 @@ --- -Title: Convert to Scientific Notation -Description: Converts a number to scientific notation. -Author: axorax -Tags: javascript,number,scientific,utility +title: Convert to Scientific Notation +description: Converts a number to scientific notation. +author: axorax +tags: javascript,number,scientific,utility --- ```js diff --git a/snippets/javascript/number-formatting/format-number-with-commas.md b/snippets/javascript/number-formatting/format-number-with-commas.md index a3eea426..27bd7175 100644 --- a/snippets/javascript/number-formatting/format-number-with-commas.md +++ b/snippets/javascript/number-formatting/format-number-with-commas.md @@ -1,8 +1,8 @@ --- -Title: Format Number with Commas -Description: Formats a number with commas for better readability (e.g., 1000 -> 1,000). -Author: axorax -Tags: javascript,number,format,utility +title: Format Number with Commas +description: Formats a number with commas for better readability (e.g., 1000 -> 1,000). +author: axorax +tags: javascript,number,format,utility --- ```js diff --git a/snippets/javascript/number-formatting/number-formatter.md b/snippets/javascript/number-formatting/number-formatter.md index ca94810a..83996903 100644 --- a/snippets/javascript/number-formatting/number-formatter.md +++ b/snippets/javascript/number-formatting/number-formatter.md @@ -1,8 +1,8 @@ --- -Title: Number Formatter -Description: Formats a number with suffixes (K, M, B, etc.). -Author: realvishalrana -Tags: javascript,number,format,utility +title: Number Formatter +description: Formats a number with suffixes (K, M, B, etc.). +author: realvishalrana +tags: javascript,number,format,utility --- ```js diff --git a/snippets/javascript/number-formatting/number-to-words-converter.md b/snippets/javascript/number-formatting/number-to-words-converter.md index 3e319d26..cdac597d 100644 --- a/snippets/javascript/number-formatting/number-to-words-converter.md +++ b/snippets/javascript/number-formatting/number-to-words-converter.md @@ -1,8 +1,8 @@ --- -Title: Number to Words Converter -Description: Converts a number to its word representation in English. -Author: axorax -Tags: javascript,number,words,utility +title: Number to Words Converter +description: Converts a number to its word representation in English. +author: axorax +tags: javascript,number,words,utility --- ```js diff --git a/snippets/javascript/object-manipulation/check-if-object-is-empty.md b/snippets/javascript/object-manipulation/check-if-object-is-empty.md index fbc75281..bb0dfde9 100644 --- a/snippets/javascript/object-manipulation/check-if-object-is-empty.md +++ b/snippets/javascript/object-manipulation/check-if-object-is-empty.md @@ -1,8 +1,8 @@ --- -Title: Check if Object is Empty -Description: Checks whether an object has no own enumerable properties. -Author: axorax -Tags: javascript,object,check,empty +title: Check if Object is Empty +description: Checks whether an object has no own enumerable properties. +author: axorax +tags: javascript,object,check,empty --- ```js diff --git a/snippets/javascript/object-manipulation/clone-object-shallowly.md b/snippets/javascript/object-manipulation/clone-object-shallowly.md index 82feef8b..546ad090 100644 --- a/snippets/javascript/object-manipulation/clone-object-shallowly.md +++ b/snippets/javascript/object-manipulation/clone-object-shallowly.md @@ -1,8 +1,8 @@ --- -Title: Clone Object Shallowly -Description: Creates a shallow copy of an object. -Author: axorax -Tags: javascript,object,clone,shallow +title: Clone Object Shallowly +description: Creates a shallow copy of an object. +author: axorax +tags: javascript,object,clone,shallow --- ```js diff --git a/snippets/javascript/object-manipulation/compare-two-objects-shallowly.md b/snippets/javascript/object-manipulation/compare-two-objects-shallowly.md index ca020fd6..6d3d3eaf 100644 --- a/snippets/javascript/object-manipulation/compare-two-objects-shallowly.md +++ b/snippets/javascript/object-manipulation/compare-two-objects-shallowly.md @@ -1,8 +1,8 @@ --- -Title: Compare Two Objects Shallowly -Description: Compares two objects shallowly and returns whether they are equal. -Author: axorax -Tags: javascript,object,compare,shallow +title: Compare Two Objects Shallowly +description: Compares two objects shallowly and returns whether they are equal. +author: axorax +tags: javascript,object,compare,shallow --- ```js diff --git a/snippets/javascript/object-manipulation/convert-object-to-query-string.md b/snippets/javascript/object-manipulation/convert-object-to-query-string.md index 6a746040..568057f4 100644 --- a/snippets/javascript/object-manipulation/convert-object-to-query-string.md +++ b/snippets/javascript/object-manipulation/convert-object-to-query-string.md @@ -1,8 +1,8 @@ --- -Title: Convert Object to Query String -Description: Converts an object to a query string for use in URLs. -Author: axorax -Tags: javascript,object,query string,url +title: Convert Object to Query String +description: Converts an object to a query string for use in URLs. +author: axorax +tags: javascript,object,query string,url --- ```js diff --git a/snippets/javascript/object-manipulation/count-properties-in-object.md b/snippets/javascript/object-manipulation/count-properties-in-object.md index 00080128..67aa9227 100644 --- a/snippets/javascript/object-manipulation/count-properties-in-object.md +++ b/snippets/javascript/object-manipulation/count-properties-in-object.md @@ -1,8 +1,8 @@ --- -Title: Count Properties in Object -Description: Counts the number of own properties in an object. -Author: axorax -Tags: javascript,object,count,properties +title: Count Properties in Object +description: Counts the number of own properties in an object. +author: axorax +tags: javascript,object,count,properties --- ```js diff --git a/snippets/javascript/object-manipulation/filter-object.md b/snippets/javascript/object-manipulation/filter-object.md index dd604527..889387a6 100644 --- a/snippets/javascript/object-manipulation/filter-object.md +++ b/snippets/javascript/object-manipulation/filter-object.md @@ -1,8 +1,8 @@ --- -Title: Filter Object -Description: Filter out entries in an object where the value is falsy, including empty strings, empty objects, null, and undefined. -Author: realvishalrana -Tags: javascript,object,filter,utility +title: Filter Object +description: Filter out entries in an object where the value is falsy, including empty strings, empty objects, null, and undefined. +author: realvishalrana +tags: javascript,object,filter,utility --- ```js diff --git a/snippets/javascript/object-manipulation/flatten-nested-object.md b/snippets/javascript/object-manipulation/flatten-nested-object.md index 4e85541f..d30219d1 100644 --- a/snippets/javascript/object-manipulation/flatten-nested-object.md +++ b/snippets/javascript/object-manipulation/flatten-nested-object.md @@ -1,8 +1,8 @@ --- -Title: Flatten Nested Object -Description: Flattens a nested object into a single-level object with dot notation for keys. -Author: axorax -Tags: javascript,object,flatten,utility +title: Flatten Nested Object +description: Flattens a nested object into a single-level object with dot notation for keys. +author: axorax +tags: javascript,object,flatten,utility --- ```js diff --git a/snippets/javascript/object-manipulation/freeze-object.md b/snippets/javascript/object-manipulation/freeze-object.md index 99a1fa92..b933019f 100644 --- a/snippets/javascript/object-manipulation/freeze-object.md +++ b/snippets/javascript/object-manipulation/freeze-object.md @@ -1,8 +1,8 @@ --- -Title: Freeze Object -Description: Freezes an object to make it immutable. -Author: axorax -Tags: javascript,object,freeze,immutable +title: Freeze Object +description: Freezes an object to make it immutable. +author: axorax +tags: javascript,object,freeze,immutable --- ```js diff --git a/snippets/javascript/object-manipulation/get-nested-value.md b/snippets/javascript/object-manipulation/get-nested-value.md index 6d3278e9..398ca88f 100644 --- a/snippets/javascript/object-manipulation/get-nested-value.md +++ b/snippets/javascript/object-manipulation/get-nested-value.md @@ -1,8 +1,8 @@ --- -Title: Get Nested Value -Description: Retrieves the value at a given path in a nested object. -Author: realvishalrana -Tags: javascript,object,nested,utility +title: Get Nested Value +description: Retrieves the value at a given path in a nested object. +author: realvishalrana +tags: javascript,object,nested,utility --- ```js diff --git a/snippets/javascript/object-manipulation/invert-object-keys-and-values.md b/snippets/javascript/object-manipulation/invert-object-keys-and-values.md index b5e54f27..14f1c4d4 100644 --- a/snippets/javascript/object-manipulation/invert-object-keys-and-values.md +++ b/snippets/javascript/object-manipulation/invert-object-keys-and-values.md @@ -1,8 +1,8 @@ --- -Title: Invert Object Keys and Values -Description: Creates a new object by swapping keys and values of the given object. -Author: axorax -Tags: javascript,object,invert,utility +title: Invert Object Keys and Values +description: Creates a new object by swapping keys and values of the given object. +author: axorax +tags: javascript,object,invert,utility --- ```js diff --git a/snippets/javascript/object-manipulation/merge-objects-deeply.md b/snippets/javascript/object-manipulation/merge-objects-deeply.md index 904458d6..e7dadbad 100644 --- a/snippets/javascript/object-manipulation/merge-objects-deeply.md +++ b/snippets/javascript/object-manipulation/merge-objects-deeply.md @@ -1,8 +1,8 @@ --- -Title: Merge Objects Deeply -Description: Deeply merges two or more objects, including nested properties. -Author: axorax -Tags: javascript,object,merge,deep +title: Merge Objects Deeply +description: Deeply merges two or more objects, including nested properties. +author: axorax +tags: javascript,object,merge,deep --- ```js diff --git a/snippets/javascript/object-manipulation/omit-keys-from-object.md b/snippets/javascript/object-manipulation/omit-keys-from-object.md index d39f1483..4487e332 100644 --- a/snippets/javascript/object-manipulation/omit-keys-from-object.md +++ b/snippets/javascript/object-manipulation/omit-keys-from-object.md @@ -1,8 +1,8 @@ --- -Title: Omit Keys from Object -Description: Creates a new object with specific keys omitted. -Author: axorax -Tags: javascript,object,omit,utility +title: Omit Keys from Object +description: Creates a new object with specific keys omitted. +author: axorax +tags: javascript,object,omit,utility --- ```js diff --git a/snippets/javascript/object-manipulation/pick-keys-from-object.md b/snippets/javascript/object-manipulation/pick-keys-from-object.md index 42f2ff49..ae900203 100644 --- a/snippets/javascript/object-manipulation/pick-keys-from-object.md +++ b/snippets/javascript/object-manipulation/pick-keys-from-object.md @@ -1,8 +1,8 @@ --- -Title: Pick Keys from Object -Description: Creates a new object with only the specified keys. -Author: axorax -Tags: javascript,object,pick,utility +title: Pick Keys from Object +description: Creates a new object with only the specified keys. +author: axorax +tags: javascript,object,pick,utility --- ```js diff --git a/snippets/javascript/object-manipulation/unique-by-key.md b/snippets/javascript/object-manipulation/unique-by-key.md index c4e5c184..3a9e9fe1 100644 --- a/snippets/javascript/object-manipulation/unique-by-key.md +++ b/snippets/javascript/object-manipulation/unique-by-key.md @@ -1,8 +1,8 @@ --- -Title: Unique By Key -Description: Filters an array of objects to only include unique objects by a specified key. -Author: realvishalrana -Tags: javascript,array,unique,utility +title: Unique By Key +description: Filters an array of objects to only include unique objects by a specified key. +author: realvishalrana +tags: javascript,array,unique,utility --- ```js diff --git a/snippets/javascript/regular-expression/regex-match-utility-function.md b/snippets/javascript/regular-expression/regex-match-utility-function.md index 7be32eca..266d6ec4 100644 --- a/snippets/javascript/regular-expression/regex-match-utility-function.md +++ b/snippets/javascript/regular-expression/regex-match-utility-function.md @@ -1,8 +1,8 @@ --- -Title: Regex Match Utility Function -Description: Enhanced regular expression matching utility. -Author: aumirza -Tags: javascript,regex +title: Regex Match Utility Function +description: Enhanced regular expression matching utility. +author: aumirza +tags: javascript,regex --- ```js diff --git a/snippets/javascript/string-manipulation/capitalize-string.md b/snippets/javascript/string-manipulation/capitalize-string.md index e6f32f7c..1b515664 100644 --- a/snippets/javascript/string-manipulation/capitalize-string.md +++ b/snippets/javascript/string-manipulation/capitalize-string.md @@ -1,8 +1,8 @@ --- -Title: Capitalize String -Description: Capitalizes the first letter of a string. -Author: dostonnabotov -Tags: javascript,string,capitalize,utility +title: Capitalize String +description: Capitalizes the first letter of a string. +author: dostonnabotov +tags: javascript,string,capitalize,utility --- ```js diff --git a/snippets/javascript/string-manipulation/check-if-string-is-a-palindrome.md b/snippets/javascript/string-manipulation/check-if-string-is-a-palindrome.md index d6978bb9..5cd487ee 100644 --- a/snippets/javascript/string-manipulation/check-if-string-is-a-palindrome.md +++ b/snippets/javascript/string-manipulation/check-if-string-is-a-palindrome.md @@ -1,8 +1,8 @@ --- -Title: Check if String is a Palindrome -Description: Checks whether a given string is a palindrome. -Author: axorax -Tags: javascript,check,palindrome,string +title: Check if String is a Palindrome +description: Checks whether a given string is a palindrome. +author: axorax +tags: javascript,check,palindrome,string --- ```js diff --git a/snippets/javascript/string-manipulation/convert-string-to-camel-case.md b/snippets/javascript/string-manipulation/convert-string-to-camel-case.md index 6981ff7e..d58026de 100644 --- a/snippets/javascript/string-manipulation/convert-string-to-camel-case.md +++ b/snippets/javascript/string-manipulation/convert-string-to-camel-case.md @@ -1,8 +1,8 @@ --- -Title: Convert String to Camel Case -Description: Converts a given string into camelCase. -Author: aumirza -Tags: string,case,camelCase +title: Convert String to Camel Case +description: Converts a given string into camelCase. +author: aumirza +tags: string,case,camelCase --- ```js diff --git a/snippets/javascript/string-manipulation/convert-string-to-param-case.md b/snippets/javascript/string-manipulation/convert-string-to-param-case.md index a4ae72c0..9d2617bc 100644 --- a/snippets/javascript/string-manipulation/convert-string-to-param-case.md +++ b/snippets/javascript/string-manipulation/convert-string-to-param-case.md @@ -1,8 +1,8 @@ --- -Title: Convert String to Param Case -Description: Converts a given string into param-case. -Author: aumirza -Tags: string,case,paramCase +title: Convert String to Param Case +description: Converts a given string into param-case. +author: aumirza +tags: string,case,paramCase --- ```js diff --git a/snippets/javascript/string-manipulation/convert-string-to-pascal-case.md b/snippets/javascript/string-manipulation/convert-string-to-pascal-case.md index b1994ff4..ece7cc10 100644 --- a/snippets/javascript/string-manipulation/convert-string-to-pascal-case.md +++ b/snippets/javascript/string-manipulation/convert-string-to-pascal-case.md @@ -1,8 +1,8 @@ --- -Title: Convert String to Pascal Case -Description: Converts a given string into Pascal Case. -Author: aumirza -Tags: string,case,pascalCase +title: Convert String to Pascal Case +description: Converts a given string into Pascal Case. +author: aumirza +tags: string,case,pascalCase --- ```js diff --git a/snippets/javascript/string-manipulation/convert-string-to-snake-case.md b/snippets/javascript/string-manipulation/convert-string-to-snake-case.md index b75399b2..67a30e33 100644 --- a/snippets/javascript/string-manipulation/convert-string-to-snake-case.md +++ b/snippets/javascript/string-manipulation/convert-string-to-snake-case.md @@ -1,8 +1,8 @@ --- -Title: Convert String to Snake Case -Description: Converts a given string into snake_case. -Author: axorax -Tags: string,case,snake_case +title: Convert String to Snake Case +description: Converts a given string into snake_case. +author: axorax +tags: string,case,snake_case --- ```js diff --git a/snippets/javascript/string-manipulation/convert-string-to-title-case.md b/snippets/javascript/string-manipulation/convert-string-to-title-case.md index b724c0dd..cbea3521 100644 --- a/snippets/javascript/string-manipulation/convert-string-to-title-case.md +++ b/snippets/javascript/string-manipulation/convert-string-to-title-case.md @@ -1,8 +1,8 @@ --- -Title: Convert String to Title Case -Description: Converts a given string into Title Case. -Author: aumirza -Tags: string,case,titleCase +title: Convert String to Title Case +description: Converts a given string into Title Case. +author: aumirza +tags: string,case,titleCase --- ```js diff --git a/snippets/javascript/string-manipulation/convert-tabs-to-spaces.md b/snippets/javascript/string-manipulation/convert-tabs-to-spaces.md index c3022a6e..fbeb9816 100644 --- a/snippets/javascript/string-manipulation/convert-tabs-to-spaces.md +++ b/snippets/javascript/string-manipulation/convert-tabs-to-spaces.md @@ -1,8 +1,8 @@ --- -Title: Convert Tabs to Spaces -Description: Converts all tab characters in a string to spaces. -Author: axorax -Tags: string,tabs,spaces +title: Convert Tabs to Spaces +description: Converts all tab characters in a string to spaces. +author: axorax +tags: string,tabs,spaces --- ```js diff --git a/snippets/javascript/string-manipulation/count-words-in-a-string.md b/snippets/javascript/string-manipulation/count-words-in-a-string.md index c5614f57..036457a5 100644 --- a/snippets/javascript/string-manipulation/count-words-in-a-string.md +++ b/snippets/javascript/string-manipulation/count-words-in-a-string.md @@ -1,8 +1,8 @@ --- -Title: Count Words in a String -Description: Counts the number of words in a string. -Author: axorax -Tags: javascript,string,manipulation,word count,count +title: Count Words in a String +description: Counts the number of words in a string. +author: axorax +tags: javascript,string,manipulation,word count,count --- ```js diff --git a/snippets/javascript/string-manipulation/data-with-prefix.md b/snippets/javascript/string-manipulation/data-with-prefix.md index 35194faa..d9a916c7 100644 --- a/snippets/javascript/string-manipulation/data-with-prefix.md +++ b/snippets/javascript/string-manipulation/data-with-prefix.md @@ -1,8 +1,8 @@ --- -Title: Data with Prefix -Description: Adds a prefix and postfix to data, with a fallback value. -Author: realvishalrana -Tags: javascript,data,utility +title: Data with Prefix +description: Adds a prefix and postfix to data, with a fallback value. +author: realvishalrana +tags: javascript,data,utility --- ```js diff --git a/snippets/javascript/string-manipulation/extract-initials-from-name.md b/snippets/javascript/string-manipulation/extract-initials-from-name.md index 284eeb62..d782a152 100644 --- a/snippets/javascript/string-manipulation/extract-initials-from-name.md +++ b/snippets/javascript/string-manipulation/extract-initials-from-name.md @@ -1,8 +1,8 @@ --- -Title: Extract Initials from Name -Description: Extracts and returns the initials from a full name. -Author: axorax -Tags: string,initials,name +title: Extract Initials from Name +description: Extracts and returns the initials from a full name. +author: axorax +tags: string,initials,name --- ```js diff --git a/snippets/javascript/string-manipulation/mask-sensitive-information.md b/snippets/javascript/string-manipulation/mask-sensitive-information.md index 6da405f6..28123404 100644 --- a/snippets/javascript/string-manipulation/mask-sensitive-information.md +++ b/snippets/javascript/string-manipulation/mask-sensitive-information.md @@ -1,8 +1,8 @@ --- -Title: Mask Sensitive Information -Description: Masks parts of a sensitive string, like a credit card or email address. -Author: axorax -Tags: string,mask,sensitive +title: Mask Sensitive Information +description: Masks parts of a sensitive string, like a credit card or email address. +author: axorax +tags: string,mask,sensitive --- ```js diff --git a/snippets/javascript/string-manipulation/pad-string-on-both-sides.md b/snippets/javascript/string-manipulation/pad-string-on-both-sides.md index 4689d661..a8c4e359 100644 --- a/snippets/javascript/string-manipulation/pad-string-on-both-sides.md +++ b/snippets/javascript/string-manipulation/pad-string-on-both-sides.md @@ -1,8 +1,8 @@ --- -Title: Pad String on Both Sides -Description: Pads a string on both sides with a specified character until it reaches the desired length. -Author: axorax -Tags: string,pad,manipulation +title: Pad String on Both Sides +description: Pads a string on both sides with a specified character until it reaches the desired length. +author: axorax +tags: string,pad,manipulation --- ```js diff --git a/snippets/javascript/string-manipulation/random-string.md b/snippets/javascript/string-manipulation/random-string.md index a78faad6..3512f04c 100644 --- a/snippets/javascript/string-manipulation/random-string.md +++ b/snippets/javascript/string-manipulation/random-string.md @@ -1,8 +1,8 @@ --- -Title: Random string -Description: Generates a random string of characters of a certain length -Author: kruimol -Tags: javascript,function,random +title: Random string +description: Generates a random string of characters of a certain length +author: kruimol +tags: javascript,function,random --- ```js diff --git a/snippets/javascript/string-manipulation/remove-all-whitespace.md b/snippets/javascript/string-manipulation/remove-all-whitespace.md index 1c8c7074..6c5c8f23 100644 --- a/snippets/javascript/string-manipulation/remove-all-whitespace.md +++ b/snippets/javascript/string-manipulation/remove-all-whitespace.md @@ -1,8 +1,8 @@ --- -Title: Remove All Whitespace -Description: Removes all whitespace from a string. -Author: axorax -Tags: javascript,string,whitespace +title: Remove All Whitespace +description: Removes all whitespace from a string. +author: axorax +tags: javascript,string,whitespace --- ```js diff --git a/snippets/javascript/string-manipulation/remove-vowels-from-a-string.md b/snippets/javascript/string-manipulation/remove-vowels-from-a-string.md index a47ec16e..377017e6 100644 --- a/snippets/javascript/string-manipulation/remove-vowels-from-a-string.md +++ b/snippets/javascript/string-manipulation/remove-vowels-from-a-string.md @@ -1,8 +1,8 @@ --- -Title: Remove Vowels from a String -Description: Removes all vowels from a given string. -Author: axorax -Tags: string,remove,vowels +title: Remove Vowels from a String +description: Removes all vowels from a given string. +author: axorax +tags: string,remove,vowels --- ```js diff --git a/snippets/javascript/string-manipulation/reverse-string.md b/snippets/javascript/string-manipulation/reverse-string.md index ce55448d..70a57428 100644 --- a/snippets/javascript/string-manipulation/reverse-string.md +++ b/snippets/javascript/string-manipulation/reverse-string.md @@ -1,8 +1,8 @@ --- -Title: Reverse String -Description: Reverses the characters in a string. -Author: dostonnabotov -Tags: javascript,string,reverse,utility +title: Reverse String +description: Reverses the characters in a string. +author: dostonnabotov +tags: javascript,string,reverse,utility --- ```js diff --git a/snippets/javascript/string-manipulation/slugify-string.md b/snippets/javascript/string-manipulation/slugify-string.md index c3536639..94471dc0 100644 --- a/snippets/javascript/string-manipulation/slugify-string.md +++ b/snippets/javascript/string-manipulation/slugify-string.md @@ -1,8 +1,8 @@ --- -Title: Slugify String -Description: Converts a string into a URL-friendly slug format. -Author: dostonnabotov -Tags: javascript,string,slug,utility +title: Slugify String +description: Converts a string into a URL-friendly slug format. +author: dostonnabotov +tags: javascript,string,slug,utility --- ```js diff --git a/snippets/javascript/string-manipulation/truncate-text.md b/snippets/javascript/string-manipulation/truncate-text.md index 84437145..a216eb48 100644 --- a/snippets/javascript/string-manipulation/truncate-text.md +++ b/snippets/javascript/string-manipulation/truncate-text.md @@ -1,8 +1,8 @@ --- -Title: Truncate Text -Description: Truncates the text to a maximum length and appends '...' if the text exceeds the maximum length. -Author: realvishalrana -Tags: javascript,string,truncate,utility,text +title: Truncate Text +description: Truncates the text to a maximum length and appends '...' if the text exceeds the maximum length. +author: realvishalrana +tags: javascript,string,truncate,utility,text --- ```js diff --git a/snippets/python/basics/hello-world.md b/snippets/python/basics/hello-world.md index e94d322b..948370e3 100644 --- a/snippets/python/basics/hello-world.md +++ b/snippets/python/basics/hello-world.md @@ -1,8 +1,8 @@ --- -Title: Hello, World! -Description: Prints Hello, World! to the terminal. -Author: James-Beans -Tags: python,printing,hello-world,utility +title: Hello, World! +description: Prints Hello, World! to the terminal. +author: James-Beans +tags: python,printing,hello-world,utility --- ```py diff --git a/snippets/python/datetime-utilities/calculate-date-difference-in-milliseconds.md b/snippets/python/datetime-utilities/calculate-date-difference-in-milliseconds.md index 350315b1..9daf08f3 100644 --- a/snippets/python/datetime-utilities/calculate-date-difference-in-milliseconds.md +++ b/snippets/python/datetime-utilities/calculate-date-difference-in-milliseconds.md @@ -1,8 +1,8 @@ --- -Title: Calculate Date Difference in Milliseconds -Description: Calculates the difference between two dates in milliseconds. -Author: e3nviction -Tags: python,datetime,utility +title: Calculate Date Difference in Milliseconds +description: Calculates the difference between two dates in milliseconds. +author: e3nviction +tags: python,datetime,utility --- ```py diff --git a/snippets/python/datetime-utilities/check-if-date-is-a-weekend.md b/snippets/python/datetime-utilities/check-if-date-is-a-weekend.md index 70c1475c..1e9fa63f 100644 --- a/snippets/python/datetime-utilities/check-if-date-is-a-weekend.md +++ b/snippets/python/datetime-utilities/check-if-date-is-a-weekend.md @@ -1,8 +1,8 @@ --- -Title: Check if Date is a Weekend -Description: Checks whether a given date falls on a weekend. -Author: axorax -Tags: python,datetime,weekend,utility +title: Check if Date is a Weekend +description: Checks whether a given date falls on a weekend. +author: axorax +tags: python,datetime,weekend,utility --- ```py diff --git a/snippets/python/datetime-utilities/determine-day-of-the-week.md b/snippets/python/datetime-utilities/determine-day-of-the-week.md index 71ae5dfc..4f1fa00d 100644 --- a/snippets/python/datetime-utilities/determine-day-of-the-week.md +++ b/snippets/python/datetime-utilities/determine-day-of-the-week.md @@ -1,8 +1,8 @@ --- -Title: Determine Day of the Week -Description: Calculates the day of the week for a given date. -Author: axorax -Tags: python,datetime,weekday,utility +title: Determine Day of the Week +description: Calculates the day of the week for a given date. +author: axorax +tags: python,datetime,weekday,utility --- ```py diff --git a/snippets/python/datetime-utilities/generate-date-range-list.md b/snippets/python/datetime-utilities/generate-date-range-list.md index 36508709..054591c8 100644 --- a/snippets/python/datetime-utilities/generate-date-range-list.md +++ b/snippets/python/datetime-utilities/generate-date-range-list.md @@ -1,8 +1,8 @@ --- -Title: Generate Date Range List -Description: Generates a list of dates between two given dates. -Author: axorax -Tags: python,datetime,range,utility +title: Generate Date Range List +description: Generates a list of dates between two given dates. +author: axorax +tags: python,datetime,range,utility --- ```py diff --git a/snippets/python/datetime-utilities/get-current-date-and-time-string.md b/snippets/python/datetime-utilities/get-current-date-and-time-string.md index 22e6bf99..683ece2d 100644 --- a/snippets/python/datetime-utilities/get-current-date-and-time-string.md +++ b/snippets/python/datetime-utilities/get-current-date-and-time-string.md @@ -1,8 +1,8 @@ --- -Title: Get Current Date and Time String -Description: Fetches the current date and time as a formatted string. -Author: e3nviction -Tags: python,datetime,utility +title: Get Current Date and Time String +description: Fetches the current date and time as a formatted string. +author: e3nviction +tags: python,datetime,utility --- ```py diff --git a/snippets/python/datetime-utilities/get-number-of-days-in-a-month.md b/snippets/python/datetime-utilities/get-number-of-days-in-a-month.md index 9e1053a5..85a0adf2 100644 --- a/snippets/python/datetime-utilities/get-number-of-days-in-a-month.md +++ b/snippets/python/datetime-utilities/get-number-of-days-in-a-month.md @@ -1,8 +1,8 @@ --- -Title: Get Number of Days in a Month -Description: Determines the number of days in a specific month and year. -Author: axorax -Tags: python,datetime,calendar,utility +title: Get Number of Days in a Month +description: Determines the number of days in a specific month and year. +author: axorax +tags: python,datetime,calendar,utility --- ```py diff --git a/snippets/python/error-handling/handle-file-not-found-error.md b/snippets/python/error-handling/handle-file-not-found-error.md index d2d720a2..f2cb9c6c 100644 --- a/snippets/python/error-handling/handle-file-not-found-error.md +++ b/snippets/python/error-handling/handle-file-not-found-error.md @@ -1,8 +1,8 @@ --- -Title: Handle File Not Found Error -Description: Attempts to open a file and handles the case where the file does not exist. -Author: axorax -Tags: python,error-handling,file,utility +title: Handle File Not Found Error +description: Attempts to open a file and handles the case where the file does not exist. +author: axorax +tags: python,error-handling,file,utility --- ```py diff --git a/snippets/python/error-handling/retry-function-execution-on-exception.md b/snippets/python/error-handling/retry-function-execution-on-exception.md index 0723ee37..47e60295 100644 --- a/snippets/python/error-handling/retry-function-execution-on-exception.md +++ b/snippets/python/error-handling/retry-function-execution-on-exception.md @@ -1,8 +1,8 @@ --- -Title: Retry Function Execution on Exception -Description: Retries a function execution a specified number of times if it raises an exception. -Author: axorax -Tags: python,error-handling,retry,utility +title: Retry Function Execution on Exception +description: Retries a function execution a specified number of times if it raises an exception. +author: axorax +tags: python,error-handling,retry,utility --- ```py diff --git a/snippets/python/error-handling/safe-division.md b/snippets/python/error-handling/safe-division.md index 8d53bf57..256f6c97 100644 --- a/snippets/python/error-handling/safe-division.md +++ b/snippets/python/error-handling/safe-division.md @@ -1,8 +1,8 @@ --- -Title: Safe Division -Description: Performs division with error handling. -Author: e3nviction -Tags: python,error-handling,division,utility +title: Safe Division +description: Performs division with error handling. +author: e3nviction +tags: python,error-handling,division,utility --- ```py diff --git a/snippets/python/error-handling/validate-input-with-exception-handling.md b/snippets/python/error-handling/validate-input-with-exception-handling.md index ae1ea01e..19383917 100644 --- a/snippets/python/error-handling/validate-input-with-exception-handling.md +++ b/snippets/python/error-handling/validate-input-with-exception-handling.md @@ -1,8 +1,8 @@ --- -Title: Validate Input with Exception Handling -Description: Validates user input and handles invalid input gracefully. -Author: axorax -Tags: python,error-handling,validation,utility +title: Validate Input with Exception Handling +description: Validates user input and handles invalid input gracefully. +author: axorax +tags: python,error-handling,validation,utility --- ```py diff --git a/snippets/python/file-handling/append-to-file.md b/snippets/python/file-handling/append-to-file.md index 759c2d82..e370aed1 100644 --- a/snippets/python/file-handling/append-to-file.md +++ b/snippets/python/file-handling/append-to-file.md @@ -1,8 +1,8 @@ --- -Title: Append to File -Description: Appends content to the end of a file. -Author: axorax -Tags: python,file,append,utility +title: Append to File +description: Appends content to the end of a file. +author: axorax +tags: python,file,append,utility --- ```py diff --git a/snippets/python/file-handling/check-if-file-exists.md b/snippets/python/file-handling/check-if-file-exists.md index 3f109a06..c4ae48b9 100644 --- a/snippets/python/file-handling/check-if-file-exists.md +++ b/snippets/python/file-handling/check-if-file-exists.md @@ -1,8 +1,8 @@ --- -Title: Check if File Exists -Description: Checks if a file exists at the specified path. -Author: axorax -Tags: python,file,exists,check,utility +title: Check if File Exists +description: Checks if a file exists at the specified path. +author: axorax +tags: python,file,exists,check,utility --- ```py diff --git a/snippets/python/file-handling/copy-file.md b/snippets/python/file-handling/copy-file.md index c737a268..d2a8388f 100644 --- a/snippets/python/file-handling/copy-file.md +++ b/snippets/python/file-handling/copy-file.md @@ -1,8 +1,8 @@ --- -Title: Copy File -Description: Copies a file from source to destination. -Author: axorax -Tags: python,file,copy,utility +title: Copy File +description: Copies a file from source to destination. +author: axorax +tags: python,file,copy,utility --- ```py diff --git a/snippets/python/file-handling/delete-file.md b/snippets/python/file-handling/delete-file.md index 2dc67691..7edb228c 100644 --- a/snippets/python/file-handling/delete-file.md +++ b/snippets/python/file-handling/delete-file.md @@ -1,8 +1,8 @@ --- -Title: Delete File -Description: Deletes a file at the specified path. -Author: axorax -Tags: python,file,delete,utility +title: Delete File +description: Deletes a file at the specified path. +author: axorax +tags: python,file,delete,utility --- ```py diff --git a/snippets/python/file-handling/find-files.md b/snippets/python/file-handling/find-files.md index 928d9d23..3355c5cf 100644 --- a/snippets/python/file-handling/find-files.md +++ b/snippets/python/file-handling/find-files.md @@ -1,8 +1,8 @@ --- -Title: Find Files -Description: Finds all files of the specified type within a given directory. -Author: Jackeastern -Tags: python,os,filesystem,file_search +title: Find Files +description: Finds all files of the specified type within a given directory. +author: Jackeastern +tags: python,os,filesystem,file_search --- ```py diff --git a/snippets/python/file-handling/get-file-extension.md b/snippets/python/file-handling/get-file-extension.md index 4f49ef5a..84e1b849 100644 --- a/snippets/python/file-handling/get-file-extension.md +++ b/snippets/python/file-handling/get-file-extension.md @@ -1,8 +1,8 @@ --- -Title: Get File Extension -Description: Gets the extension of a file. -Author: axorax -Tags: python,file,extension,utility +title: Get File Extension +description: Gets the extension of a file. +author: axorax +tags: python,file,extension,utility --- ```py diff --git a/snippets/python/file-handling/list-files-in-directory.md b/snippets/python/file-handling/list-files-in-directory.md index 9abaf4be..515a5ee0 100644 --- a/snippets/python/file-handling/list-files-in-directory.md +++ b/snippets/python/file-handling/list-files-in-directory.md @@ -1,8 +1,8 @@ --- -Title: List Files in Directory -Description: Lists all files in a specified directory. -Author: axorax -Tags: python,file,list,directory,utility +title: List Files in Directory +description: Lists all files in a specified directory. +author: axorax +tags: python,file,list,directory,utility --- ```py diff --git a/snippets/python/file-handling/read-file-in-chunks.md b/snippets/python/file-handling/read-file-in-chunks.md index 155e480b..ea876a23 100644 --- a/snippets/python/file-handling/read-file-in-chunks.md +++ b/snippets/python/file-handling/read-file-in-chunks.md @@ -1,8 +1,8 @@ --- -Title: Read File in Chunks -Description: Reads a file in chunks of a specified size. -Author: axorax -Tags: python,file,read,chunks,utility +title: Read File in Chunks +description: Reads a file in chunks of a specified size. +author: axorax +tags: python,file,read,chunks,utility --- ```py diff --git a/snippets/python/file-handling/read-file-lines.md b/snippets/python/file-handling/read-file-lines.md index fe058140..9ec68806 100644 --- a/snippets/python/file-handling/read-file-lines.md +++ b/snippets/python/file-handling/read-file-lines.md @@ -1,8 +1,8 @@ --- -Title: Read File Lines -Description: Reads all lines from a file and returns them as a list. -Author: dostonnabotov -Tags: python,file,read,utility +title: Read File Lines +description: Reads all lines from a file and returns them as a list. +author: dostonnabotov +tags: python,file,read,utility --- ```py diff --git a/snippets/python/file-handling/write-to-file.md b/snippets/python/file-handling/write-to-file.md index 1e8d5c29..a9155260 100644 --- a/snippets/python/file-handling/write-to-file.md +++ b/snippets/python/file-handling/write-to-file.md @@ -1,8 +1,8 @@ --- -Title: Write to File -Description: Writes content to a file. -Author: dostonnabotov -Tags: python,file,write,utility +title: Write to File +description: Writes content to a file. +author: dostonnabotov +tags: python,file,write,utility --- ```py diff --git a/snippets/python/json-manipulation/filter-json-data.md b/snippets/python/json-manipulation/filter-json-data.md index aace6946..d087b762 100644 --- a/snippets/python/json-manipulation/filter-json-data.md +++ b/snippets/python/json-manipulation/filter-json-data.md @@ -1,8 +1,8 @@ --- -Title: Filter JSON Data -Description: Filters a JSON object based on a condition and returns the filtered data. -Author: axorax -Tags: python,json,filter,data +title: Filter JSON Data +description: Filters a JSON object based on a condition and returns the filtered data. +author: axorax +tags: python,json,filter,data --- ```py diff --git a/snippets/python/json-manipulation/flatten-nested-json.md b/snippets/python/json-manipulation/flatten-nested-json.md index 6830dde6..8cdb0dd6 100644 --- a/snippets/python/json-manipulation/flatten-nested-json.md +++ b/snippets/python/json-manipulation/flatten-nested-json.md @@ -1,8 +1,8 @@ --- -Title: Flatten Nested JSON -Description: Flattens a nested JSON object into a flat dictionary. -Author: axorax -Tags: python,json,flatten,nested +title: Flatten Nested JSON +description: Flattens a nested JSON object into a flat dictionary. +author: axorax +tags: python,json,flatten,nested --- ```py diff --git a/snippets/python/json-manipulation/merge-multiple-json-files.md b/snippets/python/json-manipulation/merge-multiple-json-files.md index ef3e1b39..dc00e0e8 100644 --- a/snippets/python/json-manipulation/merge-multiple-json-files.md +++ b/snippets/python/json-manipulation/merge-multiple-json-files.md @@ -1,8 +1,8 @@ --- -Title: Merge Multiple JSON Files -Description: Merges multiple JSON files into one and writes the merged data into a new file. -Author: axorax -Tags: python,json,merge,file +title: Merge Multiple JSON Files +description: Merges multiple JSON files into one and writes the merged data into a new file. +author: axorax +tags: python,json,merge,file --- ```py diff --git a/snippets/python/json-manipulation/read-json-file.md b/snippets/python/json-manipulation/read-json-file.md index c3f43ffa..8c9bf77c 100644 --- a/snippets/python/json-manipulation/read-json-file.md +++ b/snippets/python/json-manipulation/read-json-file.md @@ -1,8 +1,8 @@ --- -Title: Read JSON File -Description: Reads a JSON file and parses its content. -Author: e3nviction -Tags: python,json,file,read +title: Read JSON File +description: Reads a JSON file and parses its content. +author: e3nviction +tags: python,json,file,read --- ```py diff --git a/snippets/python/json-manipulation/update-json-file.md b/snippets/python/json-manipulation/update-json-file.md index 4c83ad4c..69a83672 100644 --- a/snippets/python/json-manipulation/update-json-file.md +++ b/snippets/python/json-manipulation/update-json-file.md @@ -1,8 +1,8 @@ --- -Title: Update JSON File -Description: Updates an existing JSON file with new data or modifies the existing values. -Author: axorax -Tags: python,json,update,file +title: Update JSON File +description: Updates an existing JSON file with new data or modifies the existing values. +author: axorax +tags: python,json,update,file --- ```py diff --git a/snippets/python/json-manipulation/validate-json-schema.md b/snippets/python/json-manipulation/validate-json-schema.md index 639f0a66..d7dd4f7b 100644 --- a/snippets/python/json-manipulation/validate-json-schema.md +++ b/snippets/python/json-manipulation/validate-json-schema.md @@ -1,8 +1,8 @@ --- -Title: Validate JSON Schema -Description: Validates a JSON object against a predefined schema. -Author: axorax -Tags: python,json,validation,schema +title: Validate JSON Schema +description: Validates a JSON object against a predefined schema. +author: axorax +tags: python,json,validation,schema --- ```py diff --git a/snippets/python/json-manipulation/write-json-file.md b/snippets/python/json-manipulation/write-json-file.md index 92985748..624b856b 100644 --- a/snippets/python/json-manipulation/write-json-file.md +++ b/snippets/python/json-manipulation/write-json-file.md @@ -1,8 +1,8 @@ --- -Title: Write JSON File -Description: Writes a dictionary to a JSON file. -Author: e3nviction -Tags: python,json,file,write +title: Write JSON File +description: Writes a dictionary to a JSON file. +author: e3nviction +tags: python,json,file,write --- ```py diff --git a/snippets/python/list-manipulation/find-duplicates-in-a-list.md b/snippets/python/list-manipulation/find-duplicates-in-a-list.md index bd99e976..9627fba8 100644 --- a/snippets/python/list-manipulation/find-duplicates-in-a-list.md +++ b/snippets/python/list-manipulation/find-duplicates-in-a-list.md @@ -1,8 +1,8 @@ --- -Title: Find Duplicates in a List -Description: Identifies duplicate elements in a list. -Author: axorax -Tags: python,list,duplicates,utility +title: Find Duplicates in a List +description: Identifies duplicate elements in a list. +author: axorax +tags: python,list,duplicates,utility --- ```py diff --git a/snippets/python/list-manipulation/find-intersection-of-two-lists.md b/snippets/python/list-manipulation/find-intersection-of-two-lists.md index 4d241948..d3964090 100644 --- a/snippets/python/list-manipulation/find-intersection-of-two-lists.md +++ b/snippets/python/list-manipulation/find-intersection-of-two-lists.md @@ -1,8 +1,8 @@ --- -Title: Find Intersection of Two Lists -Description: Finds the common elements between two lists. -Author: axorax -Tags: python,list,intersection,utility +title: Find Intersection of Two Lists +description: Finds the common elements between two lists. +author: axorax +tags: python,list,intersection,utility --- ```py diff --git a/snippets/python/list-manipulation/find-maximum-difference-in-list.md b/snippets/python/list-manipulation/find-maximum-difference-in-list.md index f7a08bca..2173f3b9 100644 --- a/snippets/python/list-manipulation/find-maximum-difference-in-list.md +++ b/snippets/python/list-manipulation/find-maximum-difference-in-list.md @@ -1,8 +1,8 @@ --- -Title: Find Maximum Difference in List -Description: Finds the maximum difference between any two elements in a list. -Author: axorax -Tags: python,list,difference,utility +title: Find Maximum Difference in List +description: Finds the maximum difference between any two elements in a list. +author: axorax +tags: python,list,difference,utility --- ```py diff --git a/snippets/python/list-manipulation/flatten-nested-list.md b/snippets/python/list-manipulation/flatten-nested-list.md index 22643c07..1cff2bec 100644 --- a/snippets/python/list-manipulation/flatten-nested-list.md +++ b/snippets/python/list-manipulation/flatten-nested-list.md @@ -1,8 +1,8 @@ --- -Title: Flatten Nested List -Description: Flattens a multi-dimensional list into a single list. -Author: dostonnabotov -Tags: python,list,flatten,utility +title: Flatten Nested List +description: Flattens a multi-dimensional list into a single list. +author: dostonnabotov +tags: python,list,flatten,utility --- ```py diff --git a/snippets/python/list-manipulation/flatten-unevenly-nested-lists.md b/snippets/python/list-manipulation/flatten-unevenly-nested-lists.md index 0c41a426..87a13eb5 100644 --- a/snippets/python/list-manipulation/flatten-unevenly-nested-lists.md +++ b/snippets/python/list-manipulation/flatten-unevenly-nested-lists.md @@ -1,8 +1,8 @@ --- -Title: Flatten Unevenly Nested Lists -Description: Converts unevenly nested lists of any depth into a single flat list. -Author: agilarasu -Tags: python,list,flattening,nested-lists,depth,utilities +title: Flatten Unevenly Nested Lists +description: Converts unevenly nested lists of any depth into a single flat list. +author: agilarasu +tags: python,list,flattening,nested-lists,depth,utilities --- ```py diff --git a/snippets/python/list-manipulation/partition-list.md b/snippets/python/list-manipulation/partition-list.md index 3f99e8ae..5e4565b5 100644 --- a/snippets/python/list-manipulation/partition-list.md +++ b/snippets/python/list-manipulation/partition-list.md @@ -1,8 +1,8 @@ --- -Title: Partition List -Description: Partitions a list into sublists of a given size. -Author: axorax -Tags: python,list,partition,utility +title: Partition List +description: Partitions a list into sublists of a given size. +author: axorax +tags: python,list,partition,utility --- ```py diff --git a/snippets/python/list-manipulation/remove-duplicates.md b/snippets/python/list-manipulation/remove-duplicates.md index f89e239e..2b83961d 100644 --- a/snippets/python/list-manipulation/remove-duplicates.md +++ b/snippets/python/list-manipulation/remove-duplicates.md @@ -1,8 +1,8 @@ --- -Title: Remove Duplicates -Description: Removes duplicate elements from a list while maintaining order. -Author: dostonnabotov -Tags: python,list,duplicates,utility +title: Remove Duplicates +description: Removes duplicate elements from a list while maintaining order. +author: dostonnabotov +tags: python,list,duplicates,utility --- ```py diff --git a/snippets/python/math-and-numbers/calculate-compound-interest.md b/snippets/python/math-and-numbers/calculate-compound-interest.md index 93e143e4..68df23b8 100644 --- a/snippets/python/math-and-numbers/calculate-compound-interest.md +++ b/snippets/python/math-and-numbers/calculate-compound-interest.md @@ -1,8 +1,8 @@ --- -Title: Calculate Compound Interest -Description: Calculates compound interest for a given principal amount, rate, and time period. -Author: axorax -Tags: python,math,compound interest,finance +title: Calculate Compound Interest +description: Calculates compound interest for a given principal amount, rate, and time period. +author: axorax +tags: python,math,compound interest,finance --- ```py diff --git a/snippets/python/math-and-numbers/check-perfect-square.md b/snippets/python/math-and-numbers/check-perfect-square.md index fce869e2..3cf91bc7 100644 --- a/snippets/python/math-and-numbers/check-perfect-square.md +++ b/snippets/python/math-and-numbers/check-perfect-square.md @@ -1,8 +1,8 @@ --- -Title: Check Perfect Square -Description: Checks if a number is a perfect square. -Author: axorax -Tags: python,math,perfect square,check +title: Check Perfect Square +description: Checks if a number is a perfect square. +author: axorax +tags: python,math,perfect square,check --- ```py diff --git a/snippets/python/math-and-numbers/check-prime-number.md b/snippets/python/math-and-numbers/check-prime-number.md index 945daa2d..bbb4aa96 100644 --- a/snippets/python/math-and-numbers/check-prime-number.md +++ b/snippets/python/math-and-numbers/check-prime-number.md @@ -1,8 +1,8 @@ --- -Title: Check Prime Number -Description: Checks if a number is a prime number. -Author: dostonnabotov -Tags: python,math,prime,check +title: Check Prime Number +description: Checks if a number is a prime number. +author: dostonnabotov +tags: python,math,prime,check --- ```py diff --git a/snippets/python/math-and-numbers/convert-binary-to-decimal.md b/snippets/python/math-and-numbers/convert-binary-to-decimal.md index e8996d50..6abdfffa 100644 --- a/snippets/python/math-and-numbers/convert-binary-to-decimal.md +++ b/snippets/python/math-and-numbers/convert-binary-to-decimal.md @@ -1,8 +1,8 @@ --- -Title: Convert Binary to Decimal -Description: Converts a binary string to its decimal equivalent. -Author: axorax -Tags: python,math,binary,decimal,conversion +title: Convert Binary to Decimal +description: Converts a binary string to its decimal equivalent. +author: axorax +tags: python,math,binary,decimal,conversion --- ```py diff --git a/snippets/python/math-and-numbers/find-factorial.md b/snippets/python/math-and-numbers/find-factorial.md index 709a37b7..939e8fa6 100644 --- a/snippets/python/math-and-numbers/find-factorial.md +++ b/snippets/python/math-and-numbers/find-factorial.md @@ -1,8 +1,8 @@ --- -Title: Find Factorial -Description: Calculates the factorial of a number. -Author: dostonnabotov -Tags: python,math,factorial,utility +title: Find Factorial +description: Calculates the factorial of a number. +author: dostonnabotov +tags: python,math,factorial,utility --- ```py diff --git a/snippets/python/math-and-numbers/find-lcm-least-common-multiple.md b/snippets/python/math-and-numbers/find-lcm-least-common-multiple.md index 6acd3b11..31a44f5b 100644 --- a/snippets/python/math-and-numbers/find-lcm-least-common-multiple.md +++ b/snippets/python/math-and-numbers/find-lcm-least-common-multiple.md @@ -1,8 +1,8 @@ --- -Title: Find LCM (Least Common Multiple) -Description: Calculates the least common multiple (LCM) of two numbers. -Author: axorax -Tags: python,math,lcm,gcd,utility +title: Find LCM (Least Common Multiple) +description: Calculates the least common multiple (LCM) of two numbers. +author: axorax +tags: python,math,lcm,gcd,utility --- ```py diff --git a/snippets/python/math-and-numbers/solve-quadratic-equation.md b/snippets/python/math-and-numbers/solve-quadratic-equation.md index 469b19a2..2a66bf3e 100644 --- a/snippets/python/math-and-numbers/solve-quadratic-equation.md +++ b/snippets/python/math-and-numbers/solve-quadratic-equation.md @@ -1,8 +1,8 @@ --- -Title: Solve Quadratic Equation -Description: Solves a quadratic equation ax^2 + bx + c = 0 and returns the roots. -Author: axorax -Tags: python,math,quadratic,equation,solver +title: Solve Quadratic Equation +description: Solves a quadratic equation ax^2 + bx + c = 0 and returns the roots. +author: axorax +tags: python,math,quadratic,equation,solver --- ```py diff --git a/snippets/python/sqlite-database/create-sqlite-database-table.md b/snippets/python/sqlite-database/create-sqlite-database-table.md index a2339546..fef20041 100644 --- a/snippets/python/sqlite-database/create-sqlite-database-table.md +++ b/snippets/python/sqlite-database/create-sqlite-database-table.md @@ -1,8 +1,8 @@ --- -Title: Create SQLite Database Table -Description: Creates a table in an SQLite database with a dynamic schema. -Author: e3nviction -Tags: python,sqlite,database,table +title: Create SQLite Database Table +description: Creates a table in an SQLite database with a dynamic schema. +author: e3nviction +tags: python,sqlite,database,table --- ```py diff --git a/snippets/python/sqlite-database/insert-data-into-sqlite-table.md b/snippets/python/sqlite-database/insert-data-into-sqlite-table.md index d5298720..3e8cb557 100644 --- a/snippets/python/sqlite-database/insert-data-into-sqlite-table.md +++ b/snippets/python/sqlite-database/insert-data-into-sqlite-table.md @@ -1,8 +1,8 @@ --- -Title: Insert Data into Sqlite Table -Description: Inserts a row into a specified SQLite table using a dictionary of fields and values. -Author: e3nviction -Tags: python,sqlite,database,utility +title: Insert Data into Sqlite Table +description: Inserts a row into a specified SQLite table using a dictionary of fields and values. +author: e3nviction +tags: python,sqlite,database,utility --- ```py diff --git a/snippets/python/string-manipulation/capitalize-words.md b/snippets/python/string-manipulation/capitalize-words.md index b7e85a48..e6acdcd4 100644 --- a/snippets/python/string-manipulation/capitalize-words.md +++ b/snippets/python/string-manipulation/capitalize-words.md @@ -1,8 +1,8 @@ --- -Title: Capitalize Words -Description: Capitalizes the first letter of each word in a string. -Author: axorax -Tags: python,string,capitalize,utility +title: Capitalize Words +description: Capitalizes the first letter of each word in a string. +author: axorax +tags: python,string,capitalize,utility --- ```py diff --git a/snippets/python/string-manipulation/check-anagram.md b/snippets/python/string-manipulation/check-anagram.md index a77f842f..311c9c76 100644 --- a/snippets/python/string-manipulation/check-anagram.md +++ b/snippets/python/string-manipulation/check-anagram.md @@ -1,8 +1,8 @@ --- -Title: Check Anagram -Description: Checks if two strings are anagrams of each other. -Author: SteliosGee -Tags: python,string,anagram,check,utility +title: Check Anagram +description: Checks if two strings are anagrams of each other. +author: SteliosGee +tags: python,string,anagram,check,utility --- ```py diff --git a/snippets/python/string-manipulation/check-palindrome.md b/snippets/python/string-manipulation/check-palindrome.md index 16bca74e..08e30294 100644 --- a/snippets/python/string-manipulation/check-palindrome.md +++ b/snippets/python/string-manipulation/check-palindrome.md @@ -1,8 +1,8 @@ --- -Title: Check Palindrome -Description: Checks if a string is a palindrome. -Author: dostonnabotov -Tags: python,string,palindrome,utility +title: Check Palindrome +description: Checks if a string is a palindrome. +author: dostonnabotov +tags: python,string,palindrome,utility --- ```py diff --git a/snippets/python/string-manipulation/convert-snake-case-to-camel-case.md b/snippets/python/string-manipulation/convert-snake-case-to-camel-case.md index a69ac827..c3caf5e2 100644 --- a/snippets/python/string-manipulation/convert-snake-case-to-camel-case.md +++ b/snippets/python/string-manipulation/convert-snake-case-to-camel-case.md @@ -1,8 +1,8 @@ --- -Title: Convert Snake Case to Camel Case -Description: Converts a snake_case string to camelCase. -Author: axorax -Tags: python,string,snake-case,camel-case,convert,utility +title: Convert Snake Case to Camel Case +description: Converts a snake_case string to camelCase. +author: axorax +tags: python,string,snake-case,camel-case,convert,utility --- ```py diff --git a/snippets/python/string-manipulation/convert-string-to-ascii.md b/snippets/python/string-manipulation/convert-string-to-ascii.md index d9bddcf0..2af792d1 100644 --- a/snippets/python/string-manipulation/convert-string-to-ascii.md +++ b/snippets/python/string-manipulation/convert-string-to-ascii.md @@ -1,8 +1,8 @@ --- -Title: Convert String to ASCII -Description: Converts a string into its ASCII representation. -Author: axorax -Tags: python,string,ascii,convert,utility +title: Convert String to ASCII +description: Converts a string into its ASCII representation. +author: axorax +tags: python,string,ascii,convert,utility --- ```py diff --git a/snippets/python/string-manipulation/count-character-frequency.md b/snippets/python/string-manipulation/count-character-frequency.md index f6c85a7c..8665eb67 100644 --- a/snippets/python/string-manipulation/count-character-frequency.md +++ b/snippets/python/string-manipulation/count-character-frequency.md @@ -1,8 +1,8 @@ --- -Title: Count Character Frequency -Description: Counts the frequency of each character in a string. -Author: axorax -Tags: python,string,character-frequency,utility +title: Count Character Frequency +description: Counts the frequency of each character in a string. +author: axorax +tags: python,string,character-frequency,utility --- ```py diff --git a/snippets/python/string-manipulation/count-vowels.md b/snippets/python/string-manipulation/count-vowels.md index 11407e93..3500ad6c 100644 --- a/snippets/python/string-manipulation/count-vowels.md +++ b/snippets/python/string-manipulation/count-vowels.md @@ -1,8 +1,8 @@ --- -Title: Count Vowels -Description: Counts the number of vowels in a string. -Author: SteliosGee -Tags: python,string,vowels,count,utility +title: Count Vowels +description: Counts the number of vowels in a string. +author: SteliosGee +tags: python,string,vowels,count,utility --- ```py diff --git a/snippets/python/string-manipulation/count-words.md b/snippets/python/string-manipulation/count-words.md index 1755e566..301de052 100644 --- a/snippets/python/string-manipulation/count-words.md +++ b/snippets/python/string-manipulation/count-words.md @@ -1,8 +1,8 @@ --- -Title: Count Words -Description: Counts the number of words in a string. -Author: axorax -Tags: python,string,word-count,utility +title: Count Words +description: Counts the number of words in a string. +author: axorax +tags: python,string,word-count,utility --- ```py diff --git a/snippets/python/string-manipulation/find-all-substrings.md b/snippets/python/string-manipulation/find-all-substrings.md index f3be9d18..be2c16ec 100644 --- a/snippets/python/string-manipulation/find-all-substrings.md +++ b/snippets/python/string-manipulation/find-all-substrings.md @@ -1,8 +1,8 @@ --- -Title: Find All Substrings -Description: Finds all substrings of a given string. -Author: axorax -Tags: python,string,substring,find,utility +title: Find All Substrings +description: Finds all substrings of a given string. +author: axorax +tags: python,string,substring,find,utility --- ```py diff --git a/snippets/python/string-manipulation/find-longest-word.md b/snippets/python/string-manipulation/find-longest-word.md index 94a7158e..aec61eea 100644 --- a/snippets/python/string-manipulation/find-longest-word.md +++ b/snippets/python/string-manipulation/find-longest-word.md @@ -1,8 +1,8 @@ --- -Title: Find Longest Word -Description: Finds the longest word in a string. -Author: axorax -Tags: python,string,longest-word,utility +title: Find Longest Word +description: Finds the longest word in a string. +author: axorax +tags: python,string,longest-word,utility --- ```py diff --git a/snippets/python/string-manipulation/find-unique-characters.md b/snippets/python/string-manipulation/find-unique-characters.md index c3e94bc4..8b6bd787 100644 --- a/snippets/python/string-manipulation/find-unique-characters.md +++ b/snippets/python/string-manipulation/find-unique-characters.md @@ -1,8 +1,8 @@ --- -Title: Find Unique Characters -Description: Finds all unique characters in a string. -Author: axorax -Tags: python,string,unique,characters,utility +title: Find Unique Characters +description: Finds all unique characters in a string. +author: axorax +tags: python,string,unique,characters,utility --- ```py diff --git a/snippets/python/string-manipulation/remove-duplicate-characters.md b/snippets/python/string-manipulation/remove-duplicate-characters.md index e25191d0..02ca422c 100644 --- a/snippets/python/string-manipulation/remove-duplicate-characters.md +++ b/snippets/python/string-manipulation/remove-duplicate-characters.md @@ -1,8 +1,8 @@ --- -Title: Remove Duplicate Characters -Description: Removes duplicate characters from a string while maintaining the order. -Author: axorax -Tags: python,string,duplicates,remove,utility +title: Remove Duplicate Characters +description: Removes duplicate characters from a string while maintaining the order. +author: axorax +tags: python,string,duplicates,remove,utility --- ```py diff --git a/snippets/python/string-manipulation/remove-punctuation.md b/snippets/python/string-manipulation/remove-punctuation.md index b18e1295..ad2616f5 100644 --- a/snippets/python/string-manipulation/remove-punctuation.md +++ b/snippets/python/string-manipulation/remove-punctuation.md @@ -1,8 +1,8 @@ --- -Title: Remove Punctuation -Description: Removes punctuation from a string. -Author: SteliosGee -Tags: python,string,punctuation,remove,utility +title: Remove Punctuation +description: Removes punctuation from a string. +author: SteliosGee +tags: python,string,punctuation,remove,utility --- ```py diff --git a/snippets/python/string-manipulation/remove-specific-characters.md b/snippets/python/string-manipulation/remove-specific-characters.md index ce75a767..e686c299 100644 --- a/snippets/python/string-manipulation/remove-specific-characters.md +++ b/snippets/python/string-manipulation/remove-specific-characters.md @@ -1,8 +1,8 @@ --- -Title: Remove Specific Characters -Description: Removes specific characters from a string. -Author: axorax -Tags: python,string,remove,characters,utility +title: Remove Specific Characters +description: Removes specific characters from a string. +author: axorax +tags: python,string,remove,characters,utility --- ```py diff --git a/snippets/python/string-manipulation/remove-whitespace.md b/snippets/python/string-manipulation/remove-whitespace.md index 9745af85..34ed871d 100644 --- a/snippets/python/string-manipulation/remove-whitespace.md +++ b/snippets/python/string-manipulation/remove-whitespace.md @@ -1,8 +1,8 @@ --- -Title: Remove Whitespace -Description: Removes all whitespace from a string. -Author: axorax -Tags: python,string,whitespace,remove,utility +title: Remove Whitespace +description: Removes all whitespace from a string. +author: axorax +tags: python,string,whitespace,remove,utility --- ```py diff --git a/snippets/python/string-manipulation/reverse-string.md b/snippets/python/string-manipulation/reverse-string.md index 83213418..2bfa2765 100644 --- a/snippets/python/string-manipulation/reverse-string.md +++ b/snippets/python/string-manipulation/reverse-string.md @@ -1,8 +1,8 @@ --- -Title: Reverse String -Description: Reverses the characters in a string. -Author: dostonnabotov -Tags: python,string,reverse,utility +title: Reverse String +description: Reverses the characters in a string. +author: dostonnabotov +tags: python,string,reverse,utility --- ```py diff --git a/snippets/python/string-manipulation/split-camel-case.md b/snippets/python/string-manipulation/split-camel-case.md index 95a311ea..b5561287 100644 --- a/snippets/python/string-manipulation/split-camel-case.md +++ b/snippets/python/string-manipulation/split-camel-case.md @@ -1,8 +1,8 @@ --- -Title: Split Camel Case -Description: Splits a camel case string into separate words. -Author: axorax -Tags: python,string,camel-case,split,utility +title: Split Camel Case +description: Splits a camel case string into separate words. +author: axorax +tags: python,string,camel-case,split,utility --- ```py diff --git a/snippets/python/string-manipulation/truncate-string.md b/snippets/python/string-manipulation/truncate-string.md index 2528258d..e07b5f79 100644 --- a/snippets/python/string-manipulation/truncate-string.md +++ b/snippets/python/string-manipulation/truncate-string.md @@ -1,8 +1,8 @@ --- -Title: Truncate String -Description: Truncates a string to a specified length and adds an ellipsis. -Author: axorax -Tags: python,string,truncate,utility +title: Truncate String +description: Truncates a string to a specified length and adds an ellipsis. +author: axorax +tags: python,string,truncate,utility --- ```py diff --git a/snippets/python/utilities/convert-bytes-to-human-readable-format.md b/snippets/python/utilities/convert-bytes-to-human-readable-format.md index fa476880..08fc338e 100644 --- a/snippets/python/utilities/convert-bytes-to-human-readable-format.md +++ b/snippets/python/utilities/convert-bytes-to-human-readable-format.md @@ -1,8 +1,8 @@ --- -Title: Convert Bytes to Human-Readable Format -Description: Converts a size in bytes to a human-readable format. -Author: axorax -Tags: python,bytes,format,utility +title: Convert Bytes to Human-Readable Format +description: Converts a size in bytes to a human-readable format. +author: axorax +tags: python,bytes,format,utility --- ```py diff --git a/snippets/python/utilities/generate-random-string.md b/snippets/python/utilities/generate-random-string.md index 45f97ca0..b680cf49 100644 --- a/snippets/python/utilities/generate-random-string.md +++ b/snippets/python/utilities/generate-random-string.md @@ -1,8 +1,8 @@ --- -Title: Generate Random String -Description: Generates a random alphanumeric string. -Author: dostonnabotov -Tags: python,random,string,utility +title: Generate Random String +description: Generates a random alphanumeric string. +author: dostonnabotov +tags: python,random,string,utility --- ```py diff --git a/snippets/python/utilities/measure-execution-time.md b/snippets/python/utilities/measure-execution-time.md index 5c513da8..8ffdd291 100644 --- a/snippets/python/utilities/measure-execution-time.md +++ b/snippets/python/utilities/measure-execution-time.md @@ -1,8 +1,8 @@ --- -Title: Measure Execution Time -Description: Measures the execution time of a code block. -Author: dostonnabotov -Tags: python,time,execution,utility +title: Measure Execution Time +description: Measures the execution time of a code block. +author: dostonnabotov +tags: python,time,execution,utility --- ```py diff --git a/snippets/rust/basics/hello-world.md b/snippets/rust/basics/hello-world.md index 4e042a85..da2502dd 100644 --- a/snippets/rust/basics/hello-world.md +++ b/snippets/rust/basics/hello-world.md @@ -1,8 +1,8 @@ --- -Title: Hello, World! -Description: Prints Hello, World! to the terminal. -Author: James-Beans -Tags: rust,printing,hello-world,utility +title: Hello, World! +description: Prints Hello, World! to the terminal. +author: James-Beans +tags: rust,printing,hello-world,utility --- ```rust diff --git a/snippets/rust/file-handling/find-files.md b/snippets/rust/file-handling/find-files.md index e68a98e3..2dfac208 100644 --- a/snippets/rust/file-handling/find-files.md +++ b/snippets/rust/file-handling/find-files.md @@ -1,8 +1,8 @@ --- -Title: Find Files -Description: Finds all files of the specified extension within a given directory. -Author: Mathys-Gasnier -Tags: rust,file,search +title: Find Files +description: Finds all files of the specified extension within a given directory. +author: Mathys-Gasnier +tags: rust,file,search --- ```rust diff --git a/snippets/rust/file-handling/read-file-lines.md b/snippets/rust/file-handling/read-file-lines.md index e5fd742b..e2ebe6bc 100644 --- a/snippets/rust/file-handling/read-file-lines.md +++ b/snippets/rust/file-handling/read-file-lines.md @@ -1,8 +1,8 @@ --- -Title: Read File Lines -Description: Reads all lines from a file and returns them as a vector of strings. -Author: Mathys-Gasnier -Tags: rust,file,read,utility +title: Read File Lines +description: Reads all lines from a file and returns them as a vector of strings. +author: Mathys-Gasnier +tags: rust,file,read,utility --- ```rust diff --git a/snippets/rust/string-manipulation/capitalize-string.md b/snippets/rust/string-manipulation/capitalize-string.md index 072e87a7..1fc9a26b 100644 --- a/snippets/rust/string-manipulation/capitalize-string.md +++ b/snippets/rust/string-manipulation/capitalize-string.md @@ -1,8 +1,8 @@ --- -Title: Capitalize String -Description: Makes the first letter of a string uppercase. -Author: Mathys-Gasnier -Tags: rust,string,capitalize,utility +title: Capitalize String +description: Makes the first letter of a string uppercase. +author: Mathys-Gasnier +tags: rust,string,capitalize,utility --- ```rust diff --git a/snippets/scss/animations/fade-in-animation.md b/snippets/scss/animations/fade-in-animation.md index 6c3e03da..029f6deb 100644 --- a/snippets/scss/animations/fade-in-animation.md +++ b/snippets/scss/animations/fade-in-animation.md @@ -1,8 +1,8 @@ --- -Title: Fade In Animation -Description: Animates the fade-in effect. -Author: dostonnabotov -Tags: scss,animation,fade,css +title: Fade In Animation +description: Animates the fade-in effect. +author: dostonnabotov +tags: scss,animation,fade,css --- ```scss diff --git a/snippets/scss/animations/slide-in-from-left.md b/snippets/scss/animations/slide-in-from-left.md index fb1ca028..decfc2dc 100644 --- a/snippets/scss/animations/slide-in-from-left.md +++ b/snippets/scss/animations/slide-in-from-left.md @@ -1,8 +1,8 @@ --- -Title: Slide In From Left -Description: Animates content sliding in from the left. -Author: dostonnabotov -Tags: scss,animation,slide,css +title: Slide In From Left +description: Animates content sliding in from the left. +author: dostonnabotov +tags: scss,animation,slide,css --- ```scss diff --git a/snippets/scss/borders-shadows/border-radius-helper.md b/snippets/scss/borders-shadows/border-radius-helper.md index 3b965e5e..a6cdcc2e 100644 --- a/snippets/scss/borders-shadows/border-radius-helper.md +++ b/snippets/scss/borders-shadows/border-radius-helper.md @@ -1,8 +1,8 @@ --- -Title: Border Radius Helper -Description: Applies a customizable border-radius. -Author: dostonnabotov -Tags: scss,border,radius,css +title: Border Radius Helper +description: Applies a customizable border-radius. +author: dostonnabotov +tags: scss,border,radius,css --- ```scss diff --git a/snippets/scss/borders-shadows/box-shadow-helper.md b/snippets/scss/borders-shadows/box-shadow-helper.md index 728df676..dc33f1d5 100644 --- a/snippets/scss/borders-shadows/box-shadow-helper.md +++ b/snippets/scss/borders-shadows/box-shadow-helper.md @@ -1,8 +1,8 @@ --- -Title: Box Shadow Helper -Description: Generates a box shadow with customizable values. -Author: dostonnabotov -Tags: scss,box-shadow,css,effects +title: Box Shadow Helper +description: Generates a box shadow with customizable values. +author: dostonnabotov +tags: scss,box-shadow,css,effects --- ```scss diff --git a/snippets/scss/components/primary-button.md b/snippets/scss/components/primary-button.md index b15f3a91..47dc6a4d 100644 --- a/snippets/scss/components/primary-button.md +++ b/snippets/scss/components/primary-button.md @@ -1,8 +1,8 @@ --- -Title: Primary Button -Description: Generates a styled primary button. -Author: dostonnabotov -Tags: scss,button,primary,css +title: Primary Button +description: Generates a styled primary button. +author: dostonnabotov +tags: scss,button,primary,css --- ```scss diff --git a/snippets/scss/layouts/aspect-ratio.md b/snippets/scss/layouts/aspect-ratio.md index 1a9106f1..ddd8d072 100644 --- a/snippets/scss/layouts/aspect-ratio.md +++ b/snippets/scss/layouts/aspect-ratio.md @@ -1,8 +1,8 @@ --- -Title: Aspect Ratio -Description: Ensures that elements maintain a specific aspect ratio. -Author: dostonnabotov -Tags: scss,aspect-ratio,layout,css +title: Aspect Ratio +description: Ensures that elements maintain a specific aspect ratio. +author: dostonnabotov +tags: scss,aspect-ratio,layout,css --- ```scss diff --git a/snippets/scss/layouts/flex-center.md b/snippets/scss/layouts/flex-center.md index cef2a05d..c74908c6 100644 --- a/snippets/scss/layouts/flex-center.md +++ b/snippets/scss/layouts/flex-center.md @@ -1,8 +1,8 @@ --- -Title: Flex Center -Description: A mixin to center content using flexbox. -Author: dostonnabotov -Tags: scss,flex,center,css +title: Flex Center +description: A mixin to center content using flexbox. +author: dostonnabotov +tags: scss,flex,center,css --- ```scss diff --git a/snippets/scss/layouts/grid-container.md b/snippets/scss/layouts/grid-container.md index 34dd36d0..c11a4168 100644 --- a/snippets/scss/layouts/grid-container.md +++ b/snippets/scss/layouts/grid-container.md @@ -1,8 +1,8 @@ --- -Title: Grid Container -Description: Creates a responsive grid container with customizable column counts. -Author: dostonnabotov -Tags: scss,grid,layout,css +title: Grid Container +description: Creates a responsive grid container with customizable column counts. +author: dostonnabotov +tags: scss,grid,layout,css --- ```scss diff --git a/snippets/scss/typography/font-import-helper.md b/snippets/scss/typography/font-import-helper.md index 1e4de341..4ad41181 100644 --- a/snippets/scss/typography/font-import-helper.md +++ b/snippets/scss/typography/font-import-helper.md @@ -1,8 +1,8 @@ --- -Title: Font Import Helper -Description: Simplifies importing custom fonts in Sass. -Author: dostonnabotov -Tags: sass,mixin,fonts,css +title: Font Import Helper +description: Simplifies importing custom fonts in Sass. +author: dostonnabotov +tags: sass,mixin,fonts,css --- ```scss diff --git a/snippets/scss/typography/line-clamp-mixin.md b/snippets/scss/typography/line-clamp-mixin.md index fb0ee478..af48f1a8 100644 --- a/snippets/scss/typography/line-clamp-mixin.md +++ b/snippets/scss/typography/line-clamp-mixin.md @@ -1,8 +1,8 @@ --- -Title: Line Clamp Mixin -Description: A Sass mixin to clamp text to a specific number of lines. -Author: dostonnabotov -Tags: sass,mixin,typography,css +title: Line Clamp Mixin +description: A Sass mixin to clamp text to a specific number of lines. +author: dostonnabotov +tags: sass,mixin,typography,css --- ```scss diff --git a/snippets/scss/typography/text-gradient.md b/snippets/scss/typography/text-gradient.md index 273698c8..91776580 100644 --- a/snippets/scss/typography/text-gradient.md +++ b/snippets/scss/typography/text-gradient.md @@ -1,8 +1,8 @@ --- -Title: Text Gradient -Description: Adds a gradient color effect to text. -Author: dostonnabotov -Tags: sass,mixin,gradient,text,css +title: Text Gradient +description: Adds a gradient color effect to text. +author: dostonnabotov +tags: sass,mixin,gradient,text,css --- ```scss diff --git a/snippets/scss/typography/text-overflow-ellipsis.md b/snippets/scss/typography/text-overflow-ellipsis.md index 4f698e86..f5e75caf 100644 --- a/snippets/scss/typography/text-overflow-ellipsis.md +++ b/snippets/scss/typography/text-overflow-ellipsis.md @@ -1,8 +1,8 @@ --- -Title: Text Overflow Ellipsis -Description: Ensures long text is truncated with an ellipsis. -Author: dostonnabotov -Tags: sass,mixin,text,css +title: Text Overflow Ellipsis +description: Ensures long text is truncated with an ellipsis. +author: dostonnabotov +tags: sass,mixin,text,css --- ```scss diff --git a/snippets/scss/utilities/clearfix.md b/snippets/scss/utilities/clearfix.md index 3831a301..24285f82 100644 --- a/snippets/scss/utilities/clearfix.md +++ b/snippets/scss/utilities/clearfix.md @@ -1,8 +1,8 @@ --- -Title: Clearfix -Description: Provides a clearfix utility for floating elements. -Author: dostonnabotov -Tags: scss,clearfix,utility,css +title: Clearfix +description: Provides a clearfix utility for floating elements. +author: dostonnabotov +tags: scss,clearfix,utility,css --- ```scss diff --git a/snippets/scss/utilities/responsive-breakpoints.md b/snippets/scss/utilities/responsive-breakpoints.md index cd13f19f..0a29e98e 100644 --- a/snippets/scss/utilities/responsive-breakpoints.md +++ b/snippets/scss/utilities/responsive-breakpoints.md @@ -1,8 +1,8 @@ --- -Title: Responsive Breakpoints -Description: Generates media queries for responsive design. -Author: dostonnabotov -Tags: scss,responsive,media-queries,css +title: Responsive Breakpoints +description: Generates media queries for responsive design. +author: dostonnabotov +tags: scss,responsive,media-queries,css --- ```scss diff --git a/src/hooks/useCategories.ts b/src/hooks/useCategories.ts index aea09b89..3f869de2 100644 --- a/src/hooks/useCategories.ts +++ b/src/hooks/useCategories.ts @@ -12,7 +12,7 @@ type CategoryData = { export const useCategories = () => { const { language } = useAppContext(); const { data, loading, error } = useFetch( - `/data/${slugify(language.lang)}.json` + `/consolidated/${slugify(language.lang)}.json` ); const fetchedCategories = useMemo(() => { diff --git a/src/hooks/useLanguages.ts b/src/hooks/useLanguages.ts index 6f2ee0d2..da6df94d 100644 --- a/src/hooks/useLanguages.ts +++ b/src/hooks/useLanguages.ts @@ -3,7 +3,7 @@ import { useFetch } from "./useFetch"; export const useLanguages = () => { const { data, loading, error } = - useFetch("/data/_index.json"); + useFetch("/consolidated/_index.json"); return { fetchedLanguages: data || [], loading, error }; }; diff --git a/src/hooks/useSnippets.ts b/src/hooks/useSnippets.ts index 9d14e46b..8556de76 100644 --- a/src/hooks/useSnippets.ts +++ b/src/hooks/useSnippets.ts @@ -11,7 +11,7 @@ type CategoryData = { export const useSnippets = () => { const { language, category } = useAppContext(); const { data, loading, error } = useFetch( - `/data/${slugify(language.lang)}.json` + `/consolidated/${slugify(language.lang)}.json` ); const fetchedSnippets = data diff --git a/utils/consolidate.js b/utils/consolidate.js deleted file mode 100644 index c5f3b5a7..00000000 --- a/utils/consolidate.js +++ /dev/null @@ -1,27 +0,0 @@ -import { readdirSync, readFileSync, mkdirSync, writeFileSync } from "fs"; -import { basename, join } from "path"; - -const dataDir = "public/data"; -const outputFile = "public/consolidated/all_snippets.json"; - -const files = readdirSync(dataDir).filter( - (f) => f.endsWith(".json") && f !== "_index.json" -); - -const consolidated = []; - -files.forEach((file) => { - const language = basename(file, ".json"); - const content = JSON.parse(readFileSync(join(dataDir, file))); - - content.forEach((category) => { - consolidated.push({ - language, - categoryName: category.categoryName, - snippets: category.snippets, - }); - }); -}); - -mkdirSync("public/consolidated", { recursive: true }); -writeFileSync(outputFile, JSON.stringify(consolidated, null, 2)); diff --git a/utils/consolidateSnippets.js b/utils/consolidateSnippets.js index d0a33b2a..6a7673a1 100644 --- a/utils/consolidateSnippets.js +++ b/utils/consolidateSnippets.js @@ -3,7 +3,7 @@ import { parseAllSnippets, reverseSlugify } from './snippetParser.js'; import { join } from 'path'; import { copyFileSync, writeFileSync } from 'fs'; -const dataPath = 'public/data/'; +const dataPath = 'public/consolidated/'; const indexPath = join(dataPath, '_index.json'); const iconPath = 'public/icons/'; const snippetsPath = 'snippets/'; diff --git a/utils/migrateSnippets.js b/utils/migrateSnippets.js deleted file mode 100644 index 247f7729..00000000 --- a/utils/migrateSnippets.js +++ /dev/null @@ -1,62 +0,0 @@ -import { copyFileSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs'; -import { join } from 'path'; - -function slugify(string, separator = "-") { - return string - .toString() // Cast to string (optional) - .toLowerCase() // Convert the string to lowercase letters - .trim() // Remove whitespace from both sides of a string (optional) - .replace(/\s+/g, separator) // Replace spaces with {separator} - .replace(/[^\w\-]+/g, "") // Remove all non-word chars - .replace(/\_/g, separator) // Replace _ with {separator} - .replace(/\-\-+/g, separator) // Replace multiple - with single {separator} - .replace(/\-$/g, ""); // Remove trailing - -} - -const languageToMarkdownHighlightOverwrites = { - 'javascript': 'js', - 'python': 'py' -}; - -function formatSnippet(language, snippet) { - return `--- -Title: ${snippet.title} -Description: ${snippet.description} -Author: ${snippet.author} -Tags: ${snippet.tags}${('contributors' in snippet) && snippet.contributors.length > 0 ? `\nContributors: ${snippet.contributors}` : ''} ---- - -\`\`\`${language in languageToMarkdownHighlightOverwrites ? languageToMarkdownHighlightOverwrites[language] : language} -${Array.isArray(snippet.code) ? snippet.code.join('\n').trim() : snippet.code.trim()} -\`\`\` -`; -} - -const dataDir = "public/data"; -const iconsDir = "public/icons"; -const snippetDir = "snippets"; - -for (const file of readdirSync(dataDir)) { - if(!file.endsWith('.json') || file === '_index.json') continue; - - const languageName = file.slice(0, -5); - const content = JSON.parse(readFileSync(join(dataDir, file))); - const languagePath = join(snippetDir, languageName); - const iconPath = join(iconsDir, `${languageName}.svg`); - - mkdirSync(languagePath, { recursive: true }); - copyFileSync(iconPath, join(languagePath, 'icon.svg')); - - for (const category of content) { - if(category === 'icon.svg') continue; - const categoryPath = join(languagePath, slugify(category.categoryName)); - - mkdirSync(categoryPath, { recursive: true }); - - for(const snippet of category.snippets) { - const snippetPath = join(categoryPath, `${slugify(snippet.title)}.md`); - - writeFileSync(snippetPath, formatSnippet(languageName, snippet)); - } - } -} \ No newline at end of file diff --git a/utils/snippetParser.js b/utils/snippetParser.js index 346f1ab8..a096557f 100644 --- a/utils/snippetParser.js +++ b/utils/snippetParser.js @@ -16,7 +16,7 @@ function raise(issue, snippet = '') { return null; } -const propertyRegex = /^\s+([a-zA-Z]+): (.+)/; +const propertyRegex = /^\s+([a-zA-Z]+):\s*(.+)/; const headerEndCodeStartRegex = /^\s+---\s+```.*\n/; const codeRegex = /^(.+)```/s function parseSnippet(snippetPath, text) {