Code Snippets

These are a collection of code snippets for common use cases. Processes that are often done repeatedly can be automated, and things that I repeat often or search for consistently are shared here.

Git ignore local changes to tracked files

Language: Shell
git update-index --assume-unchanged <file-to-ignore>Copy to Clipbord

Check all checkboxes on page with Chrome DevTools

(function() {
    var aa = document.querySelectorAll("input[type=checkbox]");
    for (var i = 0; i < aa.length; i++){
        aa[i].checked = true;
})()Copy to Clipbord

ABCJS chords minimal example

X: 1
T: Title
M: 4/4
L: 1/8
K: C
|"C"x8|Copy to Clipbord

Identify all images in directory

Language: Shell

for f in *; do mogrify -identify $f; doneCopy to Clipbord

Download images from CSV with wget

Language: Shell
for link in `cat CSV_FILE | cut -d, -f1` 
     wget $link -O /home/tempfolder/
doneCopy to Clipbord

Add custom post type to WordPress RSS

Language: PHP
* add custom post types to main rss feed
function myfeed_request($qv) {
if (isset($qv['feed']) && !isset($qv['post_type']))
$qv['post_type'] = array('post', 'your-custom-post-type-slug');
return $qv;
add_filter('request', 'myfeed_request');Copy to Clipbord

Delete files after n days Linux

Language: Shell
find /path/to/files* -mtime +5 -exec rm {} \;Copy to Clipbord

Add audio to video using FFmpeg

Language: Shell
ffmpeg -i input.mp4 -i input.mp3 -c:v copy -map 0:v:0 -map 1:a:0 output.mp4
Copy to Clipbord

Get background images

Language: JavaScript
Array.from(document.getElementsByClassName('member-image')).map(i =>, -2).slice(5, to Clipbord

Delete and reinstall MySQL Ubuntu

Language: Shell

sudo apt-get remove --purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysql
sudo apt-get dist-upgrade
sudo apt-get install mysql-serverCopy to Clipbord

Deregister Gravity Stylesheets and Scripts from specific pages

Language: PHP

function deregister_scripts() {
    //Change this conditional to target whatever page or form you need.
    if (is_front_page()) {
        // Deregister Stylesheets

        // Deregister Scripts

add_action("gform_enqueue_scripts", "deregister_scripts");Copy to Clipbord

Run Linux process in the background, detached from user

Language: Shell

nohup your_command &Copy to Clipbord

Fix postmeta auto increment issue WordPress

Language: SQL
ALTER TABLE wp_postmeta MODIFY meta_id bigint(20) unsigned NOT NULL auto_increment;Copy to Clipbord

Count lines of code in a git repository

Language: Shell
git ls-files | xargs wc -lCopy to Clipbord

Count words in HTML file

Language: Shell

sed "s/<[^>]*>//g" file.html | wc -wCopy to Clipbord

List installed Debian packages by size

Language: Shell

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -nCopy to Clipbord

cwebp batch process

Language: Shell

for file in *.jpg ; do cwebp -q 100 "$file" -o "${file%.jpg}.webp"; doneCopy to Clipbord

Import MySQL on command line

Language: Shell

mysql -u username -p dbname < dbexport.sqlCopy to Clipbord

Tagline link LilyPond

Language: LilyPond
composer = "Jared Forth"
copyright = "Copyright © Jared Forth"
tagline = \markup {
    \line {
}Copy to Clipbord

Connect to FTP with wget

Language: Shell

wget -r --user="username" --password="password ftp://server.nameCopy to Clipbord

Unzip all zip files in Bash

Language: Shell

unzip \*.zipCopy to Clipbord

Language: Text
### Keybase proof

I hereby claim:

  * I am jaredforth on github.
  * I am jaredforth ( on keybase.
  * I have a public key ASCfVzDntJpUT-6Qu6xv4tHMcIHkeAhE7eFHg0LUV3wv6Ao

To claim this, I am signing this object:

  "body": {
    "key": {
      "eldest_kid": "01209f5730e7b49a544fee90bbac6fe2d1cc7081e4780844ede1478342d4577c2fe80a",
      "host": "",
      "kid": "01209f5730e7b49a544fee90bbac6fe2d1cc7081e4780844ede1478342d4577c2fe80a",
      "uid": "32ff8472eca6829c0e121f03242ba419",
      "username": "jaredforth"
    "merkle_root": {
      "ctime": 1596211938,
      "hash": "d28e8dbab0dcb8a91155af7677a980625d84a2488f535818425a84db1dd063a78469b038f023a39d7acbaf398154a8ed039dd7a0b44f5c127dd4d5b1ca5c28d7",
      "hash_meta": "f6c23852b2930a51d003c222d23e850b51c5aa16847759378c6f35564ca44ce0",
      "seqno": 17143127
    "service": {
      "entropy": "wJpdDvS/NeqBTpECvwlM7Dpu",
      "name": "github",
      "username": "jaredforth"
    "type": "web_service_binding",
    "version": 2
  "client": {
    "name": " go client",
    "version": "5.5.0"
  "ctime": 1596211977,
  "expire_in": 504576000,
  "prev": "78ff3f2f578cd5bb2530b06666916964fd846bbcadc08ea2c99a47bc38c14798",
  "seqno": 4,
  "tag": "signature"

with the key [ASCfVzDntJpUT-6Qu6xv4tHMcIHkeAhE7eFHg0LUV3wv6Ao](, yielding the signature:



And finally, I am proving ownership of the github account by posting this as a gist.

### My publicly-auditable identity:

### From the command line:

Consider the [keybase command line program](

# look me up
keybase id jaredforth
```Copy to Clipbord

Find txt record for a domain

Language: Shell

nslookup -q=txt _acme-challenge.example.comCopy to Clipbord

Find GB of a directory in linux

Language: Shell

du -h yourdirectory/Copy to Clipbord

Dry run certbot with DNS challenge

Language: Shell

certbot-auto certonly --dry-run --manual --preferred-challenges=dns -d -d Copy to Clipbord

Verify syntax of Apache config

Language: Shell

apachectl configtestCopy to Clipbord

Check validity of OpenSSL cert

Language: Shell

# check csr
openssl req -text -noout -verify -in server.csr

# check cert
openssl x509 -text -noout -in fullchain.pemCopy to Clipbord

OpenSSL generate new key and csr

Language: Shell

openssl req \
       -newkey rsa:2048 -nodes -keyout domain.key \
       -out domain.csrCopy to Clipbord

Create circle with members of the set {0,1...11}

Language: TeX

Use \verb`\xdef`

\begin{tikzpicture}[line cap=rect,line width=1pt]
  \filldraw [fill=white] (0,0) circle [radius=2cm];
  \foreach \angle [count=\xi] in {90,60,...,-240}
    \draw[line width=.5pt] (\angle:1.9cm) -- (\angle:2cm);
    \node at (\angle:1.5cm) {\textsf{\i}};
  \foreach \angle in {0,90,180,270}
    \draw[line width=.5pt] (\angle:1.9cm) -- (\angle:2cm);
  %\draw (0,0) -- (120:0.8cm);
  %\draw (0,0) -- (90:1cm);

\end{document}Copy to Clipbord

Create number line in LaTex with tikz package

Language: TeX

  \draw[latex-latex] (-3.5,0) -- (3.5,0) ; %edit here for the axis
  \foreach \x in  {-3,-2,-1,0,1,2,3} % edit here for the vertical lines
    \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
    \foreach \x in {-3,-2,-1,0,1,2,3} % edit here for the numbers
      \draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] 
    \draw[*-o] (0.92,0) -- (2.08,0);
  \draw[very thick] (0.92,0) -- (1.92,0);

\end{document}Copy to Clipbord