Skip to content

Instantly share code, notes, and snippets.

View jskherman's full-sized avatar

Je Sian Keith Herman jskherman

View GitHub Profile
@jskherman
jskherman / rotate_video-ffmpeg.md
Last active February 11, 2021 17:08
A command for using ffmpeg to rotate a video

The Command

A command for using ffmpeg to rotate a video:

ffmpeg -i /path/to/input/video.mp4 -vf 'transpose=2' -c:v libx264 -c:a copy -crf 20 /path/to/output/video.mp4
  • transpose=2 means to rotate the video counterclockwise
  • transpose=1 means to rotate the video clockwise
@jskherman
jskherman / selenium-driver.py
Last active January 15, 2022 09:14
Install selenium, chromium, and chromedriver on Debian (Jupyter notebook)
# Used in Deepnote
!pip install selenium
!apt-get update
!apt install -y chromium
!wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
!unzip chromedriver_linux64.zip
!chmod +x chromedriver
<!------------------- SITE HEADER -------------------->
<!-- KaTeX for math, Use \( \) and \[ \] -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.1/dist/katex.css" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.1/dist/katex.js" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.1/dist/contrib/auto-render.min.js" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
<!-- Prism.js for code syntax highlighting (header) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.26.0/themes/prism-tomorrow.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.26.0/plugins/toolbar/prism-toolbar.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.26.0/plugins/line-numbers/prism-line-numbers.min.css" />
@jskherman
jskherman / forestapp.cc.py
Last active January 25, 2022 02:35
Script to parse the generated CSV from the Forest App into a pandas dataframe
# Script to parse the csv from the Forest App into a pandas dataframe
#%%
import pandas as pd
from datetime import datetime
### Specify pattern for dates in Forest's csv export for dateparser
dateparse = lambda x: datetime.strptime(x, "%a %b %d %H:%M:%S %Z%z %Y")
### Sidenote: Alternative regex patterns
@jskherman
jskherman / pi_in_the_library_of_babel.md
Last active July 17, 2023 11:18
The 3200 digits of pi in the Library of Babel.

π to 3200 digits in the Library of Babel

The Key

The decoding key is as follows:

Character Digit
a 0
b 1
@jskherman
jskherman / round_up.py
Created February 11, 2022 16:29
Function for rounding up numbers in Python
def round_up(n, decimals=0):
# Move significant decimal digits to the left of the decimal point
multiplier = 10 ** decimals
# Truncate the unneeded digits on the right of the decimal point
sig_digits = n * multiplier // 1
# Determine whether to round up or round down
# Return 1 if the tenth digit is greater than or equal to 5,
# else return 0 if less than 5
import re
text = "[hello:: world]\n[key:: value]\n[testing::1]\n[listing::1,2,3]"
# Caveat: These regex only work with one field on a line
# and cannot have two or more in the same line.
key_regex = r"(?!\[).*(?:(?=\:\:))"
value_regex = r"(?:(?<=\:\:)(.*)(?=\]))"
# Save values to a list
import re
text = "Dummy text here with the cards"
# Regex for Basic Card with Extra field using #flashcard
basic_regex = r"((?:[^\n][\n]?)+) #flashcard ?\n*((?:\n(?:^.{1,3}$|^.{4}(?<!<!--)(?<!Extra: ).*)))(?:\nExtra: (.*))+"
# Regex for Cloze Card with Extra field
cloze_extra = r"((?:.+\n)*(?:.*==.*)(?:\n(?:^.{1,6}$|^.{7}(?<!<!--ID:)(?<!Extra: ).*))*)(?:\nExtra: (.*))?"
@jskherman
jskherman / obsidian-callouts.lua
Last active November 17, 2022 04:02
Pandoc Lua-filter by saf-dmitry for Obsidian Callouts to Quarto Callout Blocks
-- Source: https://stackoverflow.com/a/33511182
-- Check if array contains a specific value
local function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
@jskherman
jskherman / new_csv_row_on_github.py
Last active November 27, 2022 11:07
Reading a csv file on GitHub, appending a new row to it, and committing it back again to GitHub. Might be useful for forms built with python like Streamlit?
# Import packages
import os
import dotenv # For .env files
import datetime
import pandas as pd
# import base64
import requests
import io