Skip to content

Instantly share code, notes, and snippets.

View docsallover's full-sized avatar

DocsAllOver docsallover

View GitHub Profile
@docsallover
docsallover / creating_tasks.cs
Created September 24, 2025 15:29
Creating Individual Tasks In C#
// Create and run a CPU-bound task
Task<long> heavyCalculationTask = Task.Run(() => {
long sum = 0;
for (int i = 0; i < 1000000; i++) {
sum += i;
}
return sum;
});
// The main thread is not blocked and can do other work
@docsallover
docsallover / parallel_loop.cs
Created September 24, 2025 15:27
Parallel loop for CPU-bound work in C#
// Parallel loop for CPU-bound work
Parallel.For(0, 1000, i => {
// Perform a heavy calculation
double result = Math.Pow(i, 2);
// ...
});
@docsallover
docsallover / thread_class.cs
Created September 24, 2025 14:52
The Thread Class in C#
using System;
using System.Threading;
public class MyClass
{
public static void DoWork()
{
Console.WriteLine("Worker thread is running...");
Thread.Sleep(2000); // Simulate work
Console.WriteLine("Worker thread finished.");
@docsallover
docsallover / re_module_output.txt
Created September 4, 2025 16:53
Core Functions of Python's re Module (Output)
re.search(): test
re.match(): None
re.findall(): ['test', 'test']
re.sub(): This is a sample. My phone number is 123-456-7890. This is another sample.
re.split(): ['This is a ', '. My phone number is 123-456-7890. This is another ', '.']
@docsallover
docsallover / re_module.py
Created September 4, 2025 16:48
Core Functions of Python's re Module
import re
text = "This is a test. My phone number is 123-456-7890. This is another test."
pattern = r"test"
replacement = "sample"
# 1. re.search() - Finds the first match anywhere in the string
search_match = re.search(pattern, text)
print(f"re.search(): {search_match.group() if search_match else None}")
@docsallover
docsallover / matching_and_capturing_date_output.txt
Created September 4, 2025 16:46
Matching and Capturing a Date With Regex in Python (Output)
All captured dates: [('2025', '09', '04'), ('2026', '01', '15')]
First full match: 2025-09-04
Captured year: 2025
Captured month: 09
Captured day: 04
@docsallover
docsallover / matching_and_capturing_date.py
Created September 4, 2025 16:45
Matching and Capturing a Date With Regex in Python
import re
text = "Invoice for 2025-09-04 was paid. Next invoice due 2026-01-15."
# \d matches any digit (0-9)
# {4} matches exactly 4 digits
# The parentheses create capturing groups for year, month, and day
pattern = r"(\d{4})-(\d{2})-(\d{2})"
# Find all matches
@docsallover
docsallover / the_mock_dataset.py
Created September 4, 2025 16:42
Data Cleaning with Regex (The Mock Dataset)
raw_data = [
"Contact me at user.name@email.com or call me at (123) 456-7890. This is a note.",
"Invoice from customer@example.net, phone: 987.654.3210. ID #892",
"Sent from my mobile. My email is support@docsallover.io. Call me at 555-123-4567.",
"Random text with no useful info.",
"Our team can be reached at docsallover@corp.co, or by phone: +1-555-999-8888. "
]
@docsallover
docsallover / extracting_emails_regex.py
Created September 4, 2025 16:41
Data Cleaning with Regex (Extracting Emails)
def extract_emails(data_list):
"""Finds all email addresses in a list of strings."""
email_pattern = r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}"
found_emails = []
for text in data_list:
emails = re.findall(email_pattern, text)
found_emails.extend(emails)
return found_emails
print("--- Emails Extracted ---")
@docsallover
docsallover / standardizing_phone_number_regex.py
Created September 4, 2025 16:38
Data Cleaning with Regex (Standardizing Phone Numbers)
def standardize_phones(data_list):
"""Converts various phone formats to ###-###-####."""
# Pattern to find common phone number formats with optional country code or punctuation.
phone_pattern = r"(\+?\d{1,3}[-. ]?)?\(?(\d{3})\)?[-. ]?(\d{3})[-. ]?(\d{4})"
# Replacement string using captured groups from the pattern
# The \1, \2, etc., reference the groups in the pattern.
replacement = r"(\2) \3-\4"
cleaned_data = [re.sub(phone_pattern, replacement, text) for text in data_list]