Skip to content

Instantly share code, notes, and snippets.

View cynthiahqy's full-sized avatar

Cynthia Huang cynthiahqy

View GitHub Profile
@cynthiahqy
cynthiahqy / compress_pdf.md
Created October 16, 2024 21:44 — forked from ahmed-musallam/compress_pdf.md
How to compress PDF with ghostscript

How to compress PDF using ghostscript

As a developer, it bothers me when someone sends me a large pdf file compared to the number of pages. Recently, I recieved a 12MB scanned document for just one letter-sized page... so I got to googlin, like I usually do, and found ghostscript!

to learn more abot ghostscript (gs): https://www.ghostscript.com/

What we are interested in, is the gs command line tool, which provides many options for manipulating PDF, but we are interested in compressign those large PDF's into small yet legible documents.

credit goes to this answer on askubuntu forum: https://askubuntu.com/questions/3382/reduce-filesize-of-a-scanned-pdf/3387#3387?newreg=bceddef8bc334e5b88bbfd17a6e7c4f9

@cynthiahqy
cynthiahqy / quarto-staticrypt-ghpages.yml
Last active June 7, 2024 18:07
GitHub action for rendering, encrypting and deploying a Quarto site (without computations)
# based on:
# - https://github.com/quarto-dev/quarto-actions/blob/main/examples/quarto-book-gh-pages.yaml
# - https://github.com/actions/starter-workflows/blob/main/pages/static.yml
on:
push:
branches: main
pull_request:
branches: main
# to be able to trigger a manual build
@cynthiahqy
cynthiahqy / add_blank_pages.py
Last active February 21, 2024 02:58
script for adding blank pages between pdf pages
#!/usr/bin/python3
import sys, getopt, os
try:
from PyPDF2 import PdfReader, PdfWriter
# print("pypdf2 Already installed")
except ImportError as e:
print("Error -> ", e)
@cynthiahqy
cynthiahqy / convert-pdf-to-image.zsh
Created January 28, 2024 13:59
zsh script for extracting pages of a pdf as images into folder named by source pdf
#!/bin/zsh
## grab filename without extension
filepath=$1
filename=${filepath:r}
## extract pages as images
@cynthiahqy
cynthiahqy / notion_dates.R
Created January 13, 2024 03:56
create 2024 date table for notion import
# code to generate csv file of dates to import into notion database
library(tibble)
library(dplyr)
library(lubridate)
library(stringr)
df_2024 <- tibble(
ymd = seq(as.Date("2024-01-01"), as.Date("2024-12-31"), by = "days")
) |>
@cynthiahqy
cynthiahqy / python-setup.md
Last active June 30, 2023 01:12
Python environment setup

Python Version

Do this using instructions from here: https://github.com/pyenv/pyenv

  1. Install brew install pyenv
  2. Configure zsh/bash profile
  3. Install desired python versions
  4. Set global python (for default across machine) and/or local python versions (repo specific)

Virtual Env

@cynthiahqy
cynthiahqy / add-year.zsh
Created October 13, 2022 08:21
script for creating 12 month files for a given year with obsidian YAML
#!/bin/zsh
year=$1
month_names=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
month_num=(01 02 03 04 05 06 07 08 09 10 11 12)
mkdir $year
for (( idx = 1; idx < 12; idx++ )) ; do
file_name=$year/${month_num[idx]}-${month_names[idx]}.md
@cynthiahqy
cynthiahqy / maintain-dev_environ.md
Last active July 8, 2022 08:45
Maintaining Development Environment

Notes to self on infrequent dev environment tasks

Rstats

  • Don't update R using brew install r because reasons
  • Using brew install --cask r is okay
  • Need to reinstall packages after updating R
  • check package library location in ~/.Renviron
install.packages("pak")
@cynthiahqy
cynthiahqy / pandas_tidyverse_equivalents.md
Last active January 13, 2022 03:37
code snippets for doing tidyverse things in pandas

Code for wide to long to wide again

  • Python MultiIndex artifacts mean that df.pivot() is not the exact inverse of df.melt()
# ---- "load" wide data ----

# df <- tibble::tribble(~country, ~pop, ~capital,
#               "USA",      330,  "Washington D.C.",
#               "AUS",      25,   "Canberra",
#               "JPN",      125,  "Tokyo" )
@cynthiahqy
cynthiahqy / all-equal-is-poison.md
Last active October 6, 2021 01:42
all-equal poisons row-wise operations

ISSUE

base::all.equal() poisons numeric columns by recycling the <chr> message, which in turn makes otherwise row-wise operations like dplyr::filter() and dplyr::mutate() behave in an unexpected manner (i.e. returning all FALSE).

This issue arises if just one row has a numeric difference above the tolerance threshold.

For context, I wanted to use all.equal() to filter for rows where both columns have NA values, since the conditions dplyr::near(x,y) and x == y will drop these rows