-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added snippets for js, python, css and scss
- Loading branch information
1 parent
f842a51
commit a0d7395
Showing
14 changed files
with
434 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
[ | ||
{ | ||
"lang": "SCSS", | ||
"icon": "/icons/sass.svg" | ||
"lang": "JavaScript", | ||
"icon": "/icons/javascript.svg" | ||
}, | ||
{ | ||
"lang": "CSS", | ||
"icon": "/icons/css.svg" | ||
}, | ||
{ | ||
"lang": "Python", | ||
"icon": "/icons/python.svg" | ||
}, | ||
{ | ||
"lang": "SCSS", | ||
"icon": "/icons/sass.svg" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
[ | ||
{ | ||
"categoryName": "Array Manipulation", | ||
"snippets": [ | ||
{ | ||
"title": "Remove Duplicates", | ||
"description": "Removes duplicate values from an array.", | ||
"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]", | ||
"tags": ["javascript", "array", "deduplicate", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Flatten Array", | ||
"description": "Flattens a multi-dimensional array.", | ||
"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]", | ||
"tags": ["javascript", "array", "flatten", "utility"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
}, | ||
{ | ||
"categoryName": "String Manipulation", | ||
"snippets": [ | ||
{ | ||
"title": "Capitalize String", | ||
"description": "Capitalizes the first letter of a string.", | ||
"code": "const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);\n\n// Usage:\nconsole.log(capitalize('hello')); // Output: 'Hello'", | ||
"tags": ["javascript", "string", "capitalize", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Reverse String", | ||
"description": "Reverses the characters in a string.", | ||
"code": "const reverseString = (str) => str.split('').reverse().join('');\n\n// Usage:\nconsole.log(reverseString('hello')); // Output: 'olleh'", | ||
"tags": ["javascript", "string", "reverse", "utility"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
}, | ||
{ | ||
"categoryName": "Date and Time", | ||
"snippets": [ | ||
{ | ||
"title": "Format Date", | ||
"description": "Formats a date in 'YYYY-MM-DD' format.", | ||
"code": "const formatDate = (date) => date.toISOString().split('T')[0];\n\n// Usage:\nconsole.log(formatDate(new Date())); // Output: '2024-12-10'", | ||
"tags": ["javascript", "date", "format", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Get Time Difference", | ||
"description": "Calculates the time difference in days between two dates.", | ||
"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", | ||
"tags": ["javascript", "date", "time-difference", "utility"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
}, | ||
{ | ||
"categoryName": "Utilities", | ||
"snippets": [ | ||
{ | ||
"title": "Debounce Function", | ||
"description": "Delays a function execution until after a specified time.", | ||
"code": "const debounce = (func, delay) => {\n let timeout;\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));", | ||
"tags": ["javascript", "utility", "debounce", "performance"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Throttle Function", | ||
"description": "Limits a function execution to once every specified time interval.", | ||
"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));", | ||
"tags": ["javascript", "utility", "throttle", "performance"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
}, | ||
{ | ||
"categoryName": "DOM Manipulation", | ||
"snippets": [ | ||
{ | ||
"title": "Toggle Class", | ||
"description": "Toggles a class on an element.", | ||
"code": "const toggleClass = (element, className) => {\n element.classList.toggle(className);\n};\n\n// Usage:\nconst element = document.querySelector('.my-element');\ntoggleClass(element, 'active');", | ||
"tags": ["javascript", "dom", "class", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Smooth Scroll to Element", | ||
"description": "Scrolls smoothly to a specified element.", | ||
"code": "const smoothScroll = (element) => {\n element.scrollIntoView({ behavior: 'smooth' });\n};\n\n// Usage:\nconst target = document.querySelector('#target');\nsmoothScroll(target);", | ||
"tags": ["javascript", "dom", "scroll", "ui"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
[ | ||
{ | ||
"categoryName": "String Manipulation", | ||
"snippets": [ | ||
{ | ||
"title": "Reverse String", | ||
"description": "Reverses the characters in a string.", | ||
"code": "def reverse_string(s):\n return s[::-1]\n\n# Usage:\nprint(reverse_string('hello')) # Output: 'olleh'", | ||
"tags": ["python", "string", "reverse", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Check Palindrome", | ||
"description": "Checks if a string is a palindrome.", | ||
"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", | ||
"tags": ["python", "string", "palindrome", "utility"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
}, | ||
{ | ||
"categoryName": "List Manipulation", | ||
"snippets": [ | ||
{ | ||
"title": "Flatten Nested List", | ||
"description": "Flattens a multi-dimensional list into a single list.", | ||
"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]", | ||
"tags": ["python", "list", "flatten", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Remove Duplicates", | ||
"description": "Removes duplicate elements from a list while maintaining order.", | ||
"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]", | ||
"tags": ["python", "list", "duplicates", "utility"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
}, | ||
{ | ||
"categoryName": "File Handling", | ||
"snippets": [ | ||
{ | ||
"title": "Read File Lines", | ||
"description": "Reads all lines from a file and returns them as a list.", | ||
"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)", | ||
"tags": ["python", "file", "read", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Write to File", | ||
"description": "Writes content to a file.", | ||
"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!')", | ||
"tags": ["python", "file", "write", "utility"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
}, | ||
{ | ||
"categoryName": "Math and Numbers", | ||
"snippets": [ | ||
{ | ||
"title": "Find Factorial", | ||
"description": "Calculates the factorial of a number.", | ||
"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", | ||
"tags": ["python", "math", "factorial", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Check Prime Number", | ||
"description": "Checks if a number is a prime number.", | ||
"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", | ||
"tags": ["python", "math", "prime", "check"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
}, | ||
{ | ||
"categoryName": "Utilities", | ||
"snippets": [ | ||
{ | ||
"title": "Measure Execution Time", | ||
"description": "Measures the execution time of a code block.", | ||
"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)", | ||
"tags": ["python", "time", "execution", "utility"], | ||
"author": "@technoph1le" | ||
}, | ||
{ | ||
"title": "Generate Random String", | ||
"description": "Generates a random alphanumeric string.", | ||
"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", | ||
"tags": ["python", "random", "string", "utility"], | ||
"author": "@technoph1le" | ||
} | ||
] | ||
} | ||
] |
Oops, something went wrong.