Skip to content

Instantly share code, notes, and snippets.

@farzadhallaji
farzadhallaji / df_to_latex.py
Created August 2, 2024 09:56
customizable function to covert pandas dataframe to latex
import pandas as pd
def df_to_latex(df, table_caption, table_label):
# Start building the LaTeX table string
latex_str = r"""
\renewcommand{\arraystretch}{1.5} % Adjust this value to change the row height
\begin{table}[h!]
\centering
\begin{adjustbox}{max width=\textwidth, center} % Fit table to page width and center it
@farzadhallaji
farzadhallaji / crack-zip.py
Created July 25, 2024 12:20
Example for passwords starting with 'TOEFL' word
from time import sleep
import zipfile
import string
import itertools
from concurrent.futures import ProcessPoolExecutor, as_completed
# Define the path to the zip file and character set for passwords
zip_file_path = '/content/0.zip'
last_password_file = '/content/last_password.txt'
characters = string.ascii_uppercase

Enabling Access Time Logging and Identifying Unaccessed Files on Debian

Step 1: Check Current Mount Options

To check if access time logging is enabled, use the mount command:

mount | grep ' on / '
@farzadhallaji
farzadhallaji / zip_folder.py
Last active February 21, 2024 22:31
zip folder for myself
import zipfile
import tarfile
import os
def zip_folder(folder_path, zip_filename):
with zipfile.ZipFile(zip_filename, 'w') as zipf:
for foldername, subfolders, filenames in os.walk(folder_path):
for filename in filenames:
file_path = os.path.join(foldername, filename)
arcname = os.path.relpath(file_path, folder_path)
@farzadhallaji
farzadhallaji / vocab.py
Last active November 12, 2023 23:43
convert list of words to html file to memrize it
# -*- coding: utf-8 -*-
"""vocab.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1GNxF9QyJc8hL3KgVKB8t4GPgH8sGNTci
"""
# ! pip install google-translate-for-goldendict
@farzadhallaji
farzadhallaji / trim_video.sh
Last active October 22, 2023 20:29
trim video
#!/bin/bash
# Check if ffmpeg is installed
command -v ffmpeg >/dev/null 2>&1 || { echo >&2 "ffmpeg is required but it's not installed. Exiting."; exit 1; }
# Check for valid number of arguments
if [ "$#" -ne 4 ]; then
echo "Usage: $0 input.mp4 start_time end_time output_base_path"
echo "Time format: HH:MM:SS or MM:SS"
exit 1
@farzadhallaji
farzadhallaji / videos-duration.py
Created July 17, 2023 19:23
Total duration of all videos
import os
from moviepy.editor import VideoFileClip
folder_path = '/home/ri/Desktop/TFL/ahmadian' # Replace with the path to your folder
total_duration = 0
for file in os.listdir(folder_path):
if file.endswith('.webm'): # Adjust the file extension if necessary
file_path = os.path.join(folder_path, file)
video = VideoFileClip(file_path)
@farzadhallaji
farzadhallaji / Ta-Lib-in-google-colab.py
Created April 30, 2023 00:50
installing Ta-Lib in google colab
!pip uninstall numpy -y
!pip install numpy==1.24.2
!wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
!tar -xzvf ta-lib-0.4.0-src.tar.gz
%cd ta-lib
!./configure --prefix=/usr
!make
!make install
%cd ..
@farzadhallaji
farzadhallaji / hvar.py
Created February 18, 2023 22:25
standard deviation for harmonic mean
from scipy.stats import hmean
# https://stats.stackexchange.com/questions/7471/can-the-standard-deviation-be-calculated-for-harmonic-mean
harmonic_var = lambda S : (np.power(S,-1).var())/(len(S)*np.power(np.power(S,-1).mean(),4))
# example
import numpy as np
np.random.seed(100)
s = np.random.dirichlet((1,5),10)
@farzadhallaji
farzadhallaji / read_dat_file.py
Created February 14, 2023 22:50
how to read .dat dataset files in pandas
import re
def read_dot_dat_file(path):
datContent = [i.strip().split() for i in open(path).readlines()]
r = re.compile("@inputs.*")
_at_data = datContent.index(['@data'])
assert datContent[0][0] == '@relation'
assert datContent[_at_data-1][0] == '@outputs'
assert datContent[_at_data-2][0] == '@inputs'
assert len(datContent[_at_data-3][2:]) == 2 # Two Class