Skip to content

Instantly share code, notes, and snippets.

@farzadhallaji
farzadhallaji / split_pdf.py
Created December 2, 2025 23:24
splitting pdf file into several files
# pip install pypdf
from __future__ import annotations
import argparse
from pathlib import Path
from typing import List, Tuple
from pypdf import PdfReader, PdfWriter
def parse_ranges(ranges_str: str, total_pages: int) -> List[Tuple[int, int]]:
@farzadhallaji
farzadhallaji / tex2md.py
Last active November 26, 2025 10:55
Convert .tex to .md file
#!/usr/bin/env python3
import argparse
import re
import subprocess
import sys
from pathlib import Path
from typing import Optional
from texmd import tex # pip install texmd
@farzadhallaji
farzadhallaji / transcribe.py
Created November 16, 2025 10:25
voice to text
import os
import sys
import glob
import whisper
def find_audio_files(directory):
# mp3 and m4a, case-insensitive
patterns = ["*.mp3", "*.MP3", "*.m4a", "*.M4A"]
files = []
for pattern in patterns:
#!/usr/bin/env python3
import os
import re
import io
import argparse
from concurrent.futures import ThreadPoolExecutor
def search_file(path: str, regex: re.Pattern, encoding: str, bufsize: int):
"""

1. Score Matching (SM)

Goal

Estimate the score: $s(x) = \nabla_x \log p(x)$

Why Not MLE?

MLE needs normalization: $\log p(x) = \log \tilde{p}(x) - \log Z$,
but $Z = \int \tilde{p}(x) dx$ is intractable.

@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