Skip to content

Instantly share code, notes, and snippets.

@ahmed4end
ahmed4end / QPushButton.py
Last active October 29, 2023 06:50
pyqt5 QPushButton animation example.
from PyQt5 import QtWidgets, QtGui, QtCore
from colour import Color # pip install colour
class Main(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.setStyleSheet("QPushButton{height: 30px;width: 200px;}")
layout = QtWidgets.QHBoxLayout()
@ahmed4end
ahmed4end / expand.py
Created August 10, 2020 14:58
pyqt5 expandable widget.
import sys
import inspect
import textwrap
from collections import OrderedDict, UserString
from PyQt5 import QtCore, QtGui
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
@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 / 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:
@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 / change.py
Last active May 9, 2021 10:57
return money amount in change .
change = lambda t, r=[], coins={5,3,2,1}: r if t==0 else change(*(lambda g: (t-g, r+[g]))(t-min(t-i for i in coins-{sum(r)+t} if t-i>=0)))
print(change(999))
#better attempt
change = lambda x,y=[]: y if x<=0 else change(*(lambda series: (x-[i for i in series if x>=i][0], y+[[i for i in series if x>=i][0]]))([200, 100, 50, 20, 10, 5, 1]))
#with roman encode method
solution = lambda x,y="": y if x<=0 else solution(*(lambda series: (x-[i for i in series if x>=i][0], y+{1000:"M", 500:"D", 100:"C", 50:"L", 10:"X", 5:"V", 1:"I"}[[i for i in series if x>=i][0]]))([1000, 500, 100, 50, 10, 5, 1]))