Skip to content

Instantly share code, notes, and snippets.

View musoftware's full-sized avatar
🌏
Working from home

Musoftware musoftware

🌏
Working from home
View GitHub Profile
@musoftware
musoftware / CachingProxy.cs
Created October 3, 2025 10:22
Caching with Attributes (AOP) in C#
// Filename: CachingProxy.cs
using System;
using System.Collections.Concurrent;
using System.Reflection;
using System.Text.Json;
public class CachingProxy : DispatchProxy
{
private object _wrappedObject;
private static readonly ConcurrentDictionary<string, (object Value, DateTime Expiration)> _cache = new();
@musoftware
musoftware / Program.cs
Created October 3, 2025 10:19
Generic TTL Cache in C#
using System;
using System.Threading;
using System.Threading.Tasks;
public class Program
{
public static async Task Main(string[] args)
{
// Create a cache with a 5-second Time-To-Live.
var weatherCache = new TTLCache(TimeSpan.FromSeconds(5));
@musoftware
musoftware / ttl_cache_decorator.py
Created October 3, 2025 10:16
In-Memory Cache Decorator with TTL Expiration
import time
from functools import wraps
class TTLCache:
"""
A decorator that caches the results of a function for a specified TTL.
"""
def __init__(self, ttl_seconds=300):
"""
Initializes the decorator with a TTL in seconds.
@musoftware
musoftware / Program.cs
Created October 3, 2025 10:12
Generic Retry Handler Class in C#
using System;
public class Program
{
private static readonly Random _opRandom = new Random();
public static void Main(string[] args)
{
Console.WriteLine("--- Running Action (void method) Example ---");
var serviceRetryPolicy = new RetryHandler(retries: 4, baseDelaySeconds: 0.5);
@musoftware
musoftware / retry_handler.py
Created October 3, 2025 10:10
Generic Retry Logic as a Reusable Class
import time
import random
import logging
from functools import wraps
# Set up basic logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
class Retry:
"""
@musoftware
musoftware / remove_duplicates.py
Last active October 3, 2025 10:03
Removing Duplicates from a List in Python
# The original list containing duplicate elements
original_list = [1, 2, 2, 3, 4, 4, 4, 5, 6, 6]
# Use set() to remove duplicates, then convert it back to a list
unique_list = list(set(original_list))
# Print the new list
print(f"Original List: {original_list}")
print(f"Unique List: {unique_list}")
@musoftware
musoftware / file.json
Created January 13, 2024 11:06
Country ISO json
{
AF: "Afghanistan",
AX: "\xc5land Islands",
AL: "Albania",
DZ: "Algeria",
AS: "American Samoa",
AD: "Andorra",
AO: "Angola",
AI: "Anguilla",
AQ: "Antarctica",
@musoftware
musoftware / php72.bat
Created April 7, 2023 01:30
PHP Version with just Batch File to Access directly without Change Enviroment
@echo off
if "%1"=="" (
echo No arguments provided.
exit /b
)
set args=%*
C:/tools/php72/php.exe %args%
1 : Shutdown or Quit your XAMPP server from Xampp control panel.
2 : Download the ZIP version of MariaDB
3 : Rename the xampp/mysql folder to mysql_old.
4 : Unzip or Extract the contents of the MariaDB ZIP file into your XAMPP folder.
5 : Rename the MariaDB folder, called something like mariadb-5.5.37-win32, to mysql.
6 : Rename xampp/mysql/data to data_old.
7 : Copy the xampp/mysql_old/data folder to xampp/mysql/.
8 : Copy the xampp/mysql_old/backup folder to xampp/mysql/.
9 : Copy the xampp/mysql_old/scripts folder to xampp/mysql/.
@musoftware
musoftware / my.cnf
Created March 4, 2023 17:57
mysql configuration
# * Fine Tuning
key_buffer = 64M
max_allowed_packet = 128M
thread_cache_size = 30
myisam-recover = BACKUP
max_connections = 150
table_open_cache = 2048
thread_concurrency = 10
wait_timeout = 600