Skip to content

Instantly share code, notes, and snippets.

@aeturrell
aeturrell / py_pdf_to_eps_with_inkscape.py
Created December 23, 2020 16:14
Convert pdfs in 'figures/' to eps in 'figures_eps/' using Inkscape called from a Python script.
import pathlib
import subprocess
figures_in = list(pathlib.Path('figures/').glob('*'))
for fig_path in figures_in:
out_path = (pathlib.Path('figures_eps') /
pathlib.Path(fig_path.stem).with_suffix('.eps'))
subprocess.run(["inkscape", fig_path, "-o", out_path,
"--export-ps-level=3"])
@aeturrell
aeturrell / Christmas_gist_12_days.py
Created December 23, 2020 18:08
The 12 days of Christmas in code
presents = {
1: 'A partridge in a pear tree',
2: 'Two turtle doves',
3: 'Three french hens',
4: 'Four calling birds',
5: 'Five golden rings',
6: 'Six geese a-laying',
7: 'Seven swans a-swimming',
8: 'Eight maids a-milking',
9: 'Nine ladies dancing',
@aeturrell
aeturrell / example_firm_matching.py
Created January 27, 2022 13:31
Matching two dataframes of firm names using sparse_dot_topn and sklearn
import os
import glob
import pandas as pd
from tqdm import tqdm
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sparse_dot_topn import awesome_cossim_topn
import string
from nltk.corpus import stopwords
@aeturrell
aeturrell / replace_md_string_using_regex.py
Created July 31, 2023 23:18
Replace some text in all files of a certain kind in a directory using regex
import os
import re
def replace_text_in_files(directory_path, search_pattern, replace_pattern):
for root, dirs, files in os.walk(directory_path):
for file_name in files:
if file_name.endswith(".md"):
file_path = os.path.join(root, file_name)
@aeturrell
aeturrell / timestamp.py
Created August 25, 2023 14:06
Timestamp output files
from datetime import datetime
output_fname = f"prefix_{datetime.now().strftime('%Y_%m_%d-%p%I_%M_%S')}.csv"
@aeturrell
aeturrell / vanilla_regression_benchmark.py
Last active January 11, 2025 15:23
Self-contained benchmarking script for vanilla regressions with Pyfixest and Statsmodels
# /// script
# python = ">=3.10"
# dependencies = [
# "numpy>=1.21.0",
# "pandas>=1.3.0",
# "statsmodels>=0.13.0",
# "pyfixest>=0.11.0",
# "matplotlib>=3.4.0"
# ]
# ///