Skip to content

Instantly share code, notes, and snippets.

View sina-programer's full-sized avatar
🎯
Focusing

Sina.F sina-programer

🎯
Focusing
View GitHub Profile
@sina-programer
sina-programer / centrifugal.py
Created August 25, 2025 19:56
move your data away from its center by any coefficient and also keep the center unchanged by this function! (centrifugal your data)
import numpy as np
def centrifugal(series, k=1):
mu = np.mean(series)
return mu + k * np.subtract(series, mu)
if __name__ == '__main__':
arr = [2, 4, 6]
@sina-programer
sina-programer / sterling-factorial-estimation.py
Created August 25, 2025 19:50
Compute the factorial of any number as easy as substituting in a formula named sterling estimation of factorial!
from math import factorial, sqrt, pi, e
import time
def fact(x):
return sqrt(2*pi*x) * (x / e) ** x
if __name__ == '__main__':
x = 125
@sina-programer
sina-programer / character-shifter.py
Created July 19, 2025 13:36
shift characters in a phrase by below functions in python and leave non-alphabetic chars as they are.
def shifter(phrase, shift=1):
a = ord('a')
N = ord('z') - a + 1
output = ''
for char in phrase.lower():
if char.isalpha():
ordinal = (ord(char) - a + shift) % N + a
char = chr(ordinal)
@sina-programer
sina-programer / polygon-arrangement.py
Created July 10, 2025 13:36
Arrange points of any polygon effortlessly in order to connect them. (by converting them to polar coordinate system and sort by angle)
from functools import partial
import operator as op
import math
def to_polar(point, origin=(0, 0)):
assert len(point) == len(origin) == 2
dx = point[0] - origin[0]
dy = point[1] - origin[1]
d = math.sqrt(dx**2 + dy**2)
r = math.atan2(dy, dx)
@sina-programer
sina-programer / average.py
Created July 9, 2025 16:46
Diverse average/mean functions implemented in python by numpy. (arithmetic, geometric, harmonic, generalized, lehmer, quasi, quadratic, contra-harmonic, weighted, winsorized, trimmed-mean, ...)
from functools import partial
import operator as op
import numpy as np
def length(array):
assert np.ndim(array) == 1
return np.shape(array)[0]
def all_positive(array):
@sina-programer
sina-programer / rock-paper-scissors.py
Last active July 10, 2025 12:59
new mathematically implementation of classic rock-paper-scissors game by a math engine which just compares numbers without several conditions. (the greater number is the winner, so simple)
def convert(value):
value = str(value).lower()
if value == 'rock':
return 0
elif value == 'paper':
return 1
elif value == 'scissors':
return 2
return -1
@sina-programer
sina-programer / perfect_cube.py
Created July 9, 2025 05:45
create a perfect cube shape in any dimensions easily by this python function
def perfect_cube(n):
return [
tuple(map(int, row[2:].rjust(n, '0')))
for row in map(bin, range(2**n))
]
if __name__ == "__main__":
from pprint import pprint
@sina-programer
sina-programer / maxheap.py
Created June 28, 2025 12:12
implementation of Max-Heap data structure class in python from scratch
class Node:
def __init__(self, identifier, priority):
self.identifier = identifier
self.priority = priority
def set_priority(self, value):
self.priority = value
def __gt__(self, other):
return self.priority > other.priority
@sina-programer
sina-programer / matrix-multiplication.py
Created June 28, 2025 08:24
matrix multiplication implemented in python from scratch without arrays.
def matrix_multiplication(A, B):
m = len(A)
n = len(A[0])
n2 = len(B)
k = len(B[0])
assert n == n2
assert all(len(row)==n for row in A)
assert all(len(row)==k for row in B)
@sina-programer
sina-programer / gist-gatherer.py
Created June 26, 2025 12:08
gather all gist from a user in GitHub easily by this script. (I use it to back up my gist locally)
import datetime as dt
import mimetypes
import requests
import json
import os
BASE_URL = "https://api.github.com/users/{username}/gists"
def clean(clause, fill='-', encoding='ascii'):
return clause.strip().replace(' ', fill).encode(encoding, 'ignore').decode(encoding)