Skip to content

Instantly share code, notes, and snippets.

@ahmed4end
ahmed4end / diff.py
Created January 29, 2023 11:15
How many of a certain day between two dates
import datetime
A1=datetime.datetime.strptime("21/10/2022", "%d/%m/%Y")
A2=datetime.datetime.strptime("29/01/2023", "%d/%m/%Y")
count=0
week="Fri"
for i in range ((A2-A1).days): #gives the no of days from A1 to A2
if A1.strftime("%a")==week:
count+=1
A1+=datetime.timedelta(days=1)
@ahmed4end
ahmed4end / debug.bat
Created July 12, 2022 12:40
run *.exe with debug file.
mathar.exe 1>errors.txt 2>&1
@ahmed4end
ahmed4end / pandas.py
Created July 7, 2021 11:39
extract column value based on another column pandas dataframe
import pandas as pd
file1 = pd.read_csv('./n/oregonhie_descriptive_vars.csv')
file2 = pd.read_csv('./n/oregonhie_inperson_vars.csv')
file2['treatment'] = file2['person_id']
def proccess(key):
a = file1.loc[file1['person_id'] == key, 'treatment'].iloc[0]
@ahmed4end
ahmed4end / configparser.py
Created July 3, 2021 23:15
configparser minimal example
import configparser
class Config:
FILENAME = 'CONFIG.INI'
def __init__(self):
self.config = configparser.ConfigParser()
self.read()
@ahmed4end
ahmed4end / output.bat
Created June 27, 2021 21:07
print cmd command output to a text file.
app.exe 1>output.txt 2>&1
from hashlib import md5
from uuid import getnode
print ( str(md5(hex(getnode()).encode('utf-8')).hexdigest()) )
@ahmed4end
ahmed4end / numerical_miracles.py
Created April 14, 2021 02:31
i generate numerical miracles.
from itertools import permutations as perms
from itertools import product
class miracle:
'''
i make numerical miracles
'''
def __init__(self):
self.ops = ['+', '-', '*', '/']
@ahmed4end
ahmed4end / long division generator.py
Last active September 16, 2021 19:22
long division generator
import random
dividend_length = 3
divsior_length = 1
integer_results = 0
short_float = 1
pop = 20
_c, res = 0, []
while len(res)<pop and _c<5000:
import random, re, pyautogui, time, pyperclip , sys
chat = pyperclip.paste()
chatNames = re.findall(r'(?<=[PM|AM]\r\n).*(?=\r\n)', chat)
chatNames = set(chatNames)-{'Shadow'}
print(chatNames)
#Sol 1 - performance: Exp
vowels = { 'A': 1, 'E': 21, 'I': 7, 'O': 8, 'U': 5, 'T':4 }
result = []
def backtrack(trac=[], totalWeight=10, vowelsRepeatLimit={'A':5}):
'''
:params:
:totalWeight: total weight target.