Skip to content

Instantly share code, notes, and snippets.

@rlowe
rlowe / gist:bfd81aa7aa1d44383e6eb0e7fcf80832
Created September 26, 2025 18:12
@rlowe - longest-common-prefix
package main
func longestCommonPrefix(strs []string) string {
// This loop iterates based on the length of the first string.
// If strs[0] is "", this loop will not execute, and the function
// will correctly return strs[0] ("") at the end.
for i := 0; i < len(strs[0]); i++ {
char := strs[0][i]
for j := 1; j < len(strs); j++ {
@rlowe
rlowe / gist:3c440dbe151918bc34b1ad7aa807fe9f
Created February 21, 2025 17:51
Ryan's Leetcode Two Sum Solution
func twoSum(nums []int, target int) []int {
addends := []int{0, 0}
for i := 0; i < len(nums); i++ {
addends[0] = i
for j := i+1; j < len(nums); j++ {
if nums[i] + nums[j] == target {
addends[1] = j
return addends
@rlowe
rlowe / update_type_hints.py
Created February 14, 2025 20:58
Cursor-generated script to switch from using "Optional" to "None" for Python type hints. (v6)
#!/usr/bin/env python3
"""
Robust script to update Optional[X] type hints to X | None syntax,
with reliable file discovery, proper indentation handling, and comprehensive error checking.
"""
import ast
import logging
import re
import tokenize
from dataclasses import dataclass, field
@rlowe
rlowe / update_type_hints.py
Created February 14, 2025 20:22
Cursor-generated script to switch from using "Optional" to "None" for Python type hints. (v5)
#!/usr/bin/env python3
"""
Comprehensive script to update Optional[X] type hints to X | None syntax,
handling complex edge cases including string templates, code generation,
metaclasses, conditional types, and runtime type generation.
"""
import ast
import logging
import re
import tokenize
@rlowe
rlowe / update_type_hints.py
Created February 14, 2025 20:11
Cursor-generated script to switch from using "Optional" to "None" for Python type hints. (v4)
#!/usr/bin/env python3
"""
Script to update Optional[X] type hints to X | None syntax
"""
import re
from pathlib import Path
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@rlowe
rlowe / update_type_hints.py
Created February 14, 2025 20:01
Cursor-generated script to switch from using "Optional" to "None" for Python type hints. (v3)
#!/usr/bin/env python3
"""
Script to update Optional[X] type hints to X | None syntax
"""
import re
from pathlib import Path
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@rlowe
rlowe / update_type_hints.py
Created February 14, 2025 19:53
Cursor-generated script to switch from using "Optional" to "None" for Python type hints. (v2)
#!/usr/bin/env python3
"""
Script to update Optional[X] type hints to X | None syntax
"""
import re
from pathlib import Path
def replace_optional(match):
"""Handle nested Optional[] replacements"""
inner_type = match.group(1)
@rlowe
rlowe / update_type_hints.py
Created February 14, 2025 19:52
Cursor-generated script to switch from using "Optional" to "None" for Python type hints. (v1)
#!/usr/bin/env python3
"""
Script to update Optional[X] type hints to X | None syntax
"""
import re
from pathlib import Path
def update_type_hints(file_path: str) -> None:
with open(file_path, 'r') as f:
content = f.read()