Skip to content

Commit b83edbd

Browse files
committed
Update consolidated snippets
1 parent 55e8268 commit b83edbd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

public/consolidated/all_snippets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{"language": "javascript", {"categoryName":"DOM Manipulation","snippets":[{"title":"Toggle Class","description":"Toggles a class on an element.","code":["const toggleClass = (element, className) => {"," element.classList.toggle(className);","};","","// Usage:","const element = document.querySelector('.my-element');","toggleClass(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) => {"," element.scrollIntoView({ behavior: 'smooth' });","};","","// Usage:","const target = document.querySelector('#target');","smoothScroll(target);"],"tags":["javascript","dom","scroll","ui"],"author":"technoph1le"}]}
1818
{"language": "javascript", {"categoryName":"Local Storage","snippets":[{"title":"Add Item to localStorage","description":"Stores a value in localStorage under the given key.","code":["const addToLocalStorage = (key, value) => {"," localStorage.setItem(key, JSON.stringify(value));","};","","// Usage:","addToLocalStorage('user', { name: 'John', age: 30 });"],"tags":["javascript","localStorage","storage","utility"],"author":"technoph1le"},{"title":"Retrieve Item from localStorage","description":"Retrieves a value from localStorage by key and parses it.","code":["const getFromLocalStorage = (key) => {"," const item = localStorage.getItem(key);"," return item ? JSON.parse(item) : null;","};","","// Usage:","const user = getFromLocalStorage('user');","console.log(user); // Output: { name: 'John', age: 30 }"],"tags":["javascript","localStorage","storage","utility"],"author":"technoph1le"},{"title":"Clear All localStorage","description":"Clears all data from localStorage.","code":["const clearLocalStorage = () => {"," localStorage.clear();","};","","// Usage:","clearLocalStorage(); // Removes all items from localStorage"],"tags":["javascript","localStorage","storage","utility"],"author":"technoph1le"}]}
1919
{"language": "python", {"categoryName":"String Manipulation","snippets":[{"title":"Reverse String","description":"Reverses the characters in a string.","code":["def reverse_string(s):"," return s[::-1]","","# Usage:","print(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):"," s = s.lower().replace(' ', '')"," return s == s[::-1]","","# Usage:","print(is_palindrome('A man a plan a canal Panama')) # Output: True"],"tags":["python","string","palindrome","utility"],"author":"technoph1le"}]}
20-
{"language": "python", {"categoryName":"List Manipulation","snippets":[{"title":"Flatten Nested List","description":"Flattens a multi-dimensional list into a single list.","code":["def flatten_list(lst):"," return [item for sublist in lst for item in sublist]","","# Usage:","nested_list = [[1, 2], [3, 4], [5]]","print(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):"," return list(dict.fromkeys(lst))","","# Usage:","print(remove_duplicates([1, 2, 2, 3, 4, 4, 5])) # Output: [1, 2, 3, 4, 5]"],"tags":["python","list","duplicates","utility"],"author":"technoph1le"}]}
20+
{"language": "python", {"categoryName":"List Manipulation","snippets":[{"title":"Flatten Nested List","description":"Flattens a multi-dimensional list into a single list.","code":["def flatten_list(lst):"," return [item for sublist in lst for item in sublist]","","# Usage:","nested_list = [[1, 2], [3, 4], [5]]","print(flatten_list(nested_list)) # Output: [1, 2, 3, 4, 5]"],"tags":["python","list","flatten","utility"],"author":"technoph1le"},{"title":"Flatten Unevenly Nested Lists","description":"Converts unevenly nested lists of any depth into a single flat list.","code":["def flatten(nested_list):"," \"\"\""," Flattens unevenly nested lists of any depth into a single flat list."," \"\"\""," for item in nested_list:"," if isinstance(item, list):"," yield from flatten(item)"," else:"," yield item","","# Usage:","nested_list = [1, [2, [3, 4]], 5]","flattened = list(flatten(nested_list))","print(flattened) # Output: [1, 2, 3, 4, 5]"],"tags":["python","list","flattening","nested-lists","depth","utilities"],"author":"agilarasu"},{"title":"Remove Duplicates","description":"Removes duplicate elements from a list while maintaining order.","code":["def remove_duplicates(lst):"," return list(dict.fromkeys(lst))","","# Usage:","print(remove_duplicates([1, 2, 2, 3, 4, 4, 5])) # Output: [1, 2, 3, 4, 5]"],"tags":["python","list","duplicates","utility"],"author":"technoph1le"}]}
2121
{"language": "python", {"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):"," with open(filepath, 'r') as file:"," return file.readlines()","","# Usage:","lines = read_file_lines('example.txt')","print(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):"," with open(filepath, 'w') as file:"," file.write(content)","","# Usage:","write_to_file('example.txt', 'Hello, World!')"],"tags":["python","file","write","utility"],"author":"technoph1le"},{"title":"Find Files","description":"Finds all files of the specified type within a given directory.","code":["import os","","def find_files(directory, file_type):"," file_type = file_type.lower() # Convert file_type to lowercase"," found_files = []",""," for root, _, files in os.walk(directory):"," for file in files:"," file_ext = os.path.splitext(file)[1].lower()"," if file_ext == file_type:"," full_path = os.path.join(root, file)"," found_files.append(full_path)",""," return found_files","","# Example Usage:","pdf_files = find_files('/path/to/your/directory', '.pdf')","print(pdf_files)"],"tags":["python","os","filesystem","file_search"],"author":"Jackeastern"}]}
2222
{"language": "python", {"categoryName":"Math and Numbers","snippets":[{"title":"Find Factorial","description":"Calculates the factorial of a number.","code":["def factorial(n):"," if n == 0:"," return 1"," return n * factorial(n - 1)","","# Usage:","print(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):"," if n <= 1:"," return False"," for i in range(2, int(n**0.5) + 1):"," if n % i == 0:"," return False"," return True","","# Usage:","print(is_prime(17)) # Output: True"],"tags":["python","math","prime","check"],"author":"technoph1le"}]}
2323
{"language": "python", {"categoryName":"Utilities","snippets":[{"title":"Measure Execution Time","description":"Measures the execution time of a code block.","code":["import time","","def measure_time(func, *args):"," start = time.time()"," result = func(*args)"," end = time.time()"," print(f'Execution time: {end - start:.6f} seconds')"," return result","","# Usage:","def slow_function():"," time.sleep(2)","","measure_time(slow_function)"],"tags":["python","time","execution","utility"],"author":"technoph1le"},{"title":"Generate Random String","description":"Generates a random alphanumeric string.","code":["import random","import string","","def random_string(length):"," letters_and_digits = string.ascii_letters + string.digits"," return ''.join(random.choice(letters_and_digits) for _ in range(length))","","# Usage:","print(random_string(10)) # Output: Random 10-character string"],"tags":["python","random","string","utility"],"author":"technoph1le"}]}

0 commit comments

Comments
 (0)