Skip to content

Instantly share code, notes, and snippets.

View g-simmons's full-sized avatar

Gabriel Simmons g-simmons

View GitHub Profile
(defun gabe-gptel-rewrite ()
"Cursor.sh-like editing experience with gptel.
Construct a system message by prompting the user for a directive.
Call gptel-request with the current selection as user message.
On response from gptel, call ediff-regions-internal to compare
the original and changed versions linewise.
TODO:
- Store old directives, allow user to select from previous directives"
(interactive)
"""
This script is designed to remove line numbers from PDF files within a specified margin.
It uses the pymupdf library to interact with PDFs and the Typer library for command-line interface.
The script can be run from the command line, specifying the input PDF file, output PDF file, margin size,
and a regular expression to match page numbers.
Not thoroughly tested.
Gabriel Simmons, 2024
"""
@g-simmons
g-simmons / typst-playing-cards.typ
Created October 29, 2023 20:37
Simple playing cards in typst
#let card(cardname) = {
let (card, suit) = cardname.split(" of ")
let suits = (
"hearts": sym.suit.heart,
"diamonds": sym.suit.diamond,
"clubs": sym.suit.club,
"spades": sym.suit.spade,
)
let suit_colors = (
"hearts": "red",
@g-simmons
g-simmons / set_indentation_and_font_size.js
Created May 27, 2023 23:03
Set indentation levels and font sizes for nested lists in google doc
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Set Indentation and Font Size', 'setIndentationAndFontSize')
.addToUi();
}
function setIndentationAndFontSize() {
// var doc = DocumentApp.getActiveDocument();
var doc = DocumentApp.openById('<<<<YOUR-DOCUMENT-ID>>>>');
@g-simmons
g-simmons / yamlgrid_from_file.py
Created May 10, 2023 22:51
convert a dvc file template with parameter matrices into a final dvc file with corresponding foreach grids
import yaml
from itertools import product, starmap
from collections import namedtuple
import click
judgement_styles = [1, 2, 3, 4, 5]
groups = ["liberal", "conservative"]
def named_product(**items):
@g-simmons
g-simmons / yamlgrid.py
Created May 10, 2023 22:10
Make a dvc-compatible parameter grid from command line arguments
import yaml
from itertools import product, starmap
from collections import namedtuple
import click
judgement_styles = [1, 2, 3, 4, 5]
groups = ["liberal", "conservative"]
def named_product(**items):
@g-simmons
g-simmons / single_machine_slurm_on_ubuntu.md
Created February 18, 2023 23:47 — forked from ckandoth/single_machine_slurm_on_ubuntu.md
Install Slurm 19.05 on a standalone machine running Ubuntu 20.04

Use apt to install the necessary packages:

sudo apt install -y slurm-wlm slurm-wlm-doc

Load file:///usr/share/doc/slurm-wlm/html/configurator.html in a browser (or file://wsl%24/Ubuntu/usr/share/doc/slurm-wlm/html/configurator.html on WSL2), and:

  1. Set your machine's hostname in SlurmctldHost and NodeName.
  2. Set CPUs as appropriate, and optionally Sockets, CoresPerSocket, and ThreadsPerCore. Use command lscpu to find what you have.
  3. Set RealMemory to the number of megabytes you want to allocate to Slurm jobs,
  4. Set StateSaveLocation to /var/spool/slurm-llnl.
  5. Set ProctrackType to linuxproc because processes are less likely to escape Slurm control on a single machine config.
@g-simmons
g-simmons / rich_joblib_individual_progress_bars.py
Created February 15, 2023 21:59
Rich progress bars for Joblib parallel tasks
import numpy as np
from joblib import Parallel, delayed
from threading import Thread
from rich.progress import Progress, BarColumn, TimeRemainingColumn, TextColumn
from rich.console import Console
from rich.live import Live
import time
# Define the number of tasks and create a shared memory numpy array to hold their progress
num_tasks = 4
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@g-simmons
g-simmons / xpath_soup.py
Created March 4, 2021 21:56 — forked from ergoithz/xpath_soup.py
Generate unique XPATH for BeautifulSoup element
#!/usr/bin/python
# -*- coding: utf-8 -*-
def xpath_soup(element):
# type: (typing.Union[bs4.element.Tag, bs4.element.NavigableString]) -> str
"""
Generate xpath from BeautifulSoup4 element.
:param element: BeautifulSoup4 element.
:type element: bs4.element.Tag or bs4.element.NavigableString