Skip to footer navigation.

« Oatmeal

Forget-me-not

A collection of stuff I always end up having to look up.

A dithered image of forget-me-not flowers.

🎶 🌸

How to use tar

Create an archive

tar -cvzf <name-of-target-dir>.tar.gz <name-of-target-dri>

List files and directories in an archive

tar -tvf <tar-archive>

Extract an archive

tar -xvf <tar-archive>

Invert a hex color

Find the opposite of a given hex value

tr \
0123456789abcdef \
fedcba9876543210

Basic JavaScript memoize function

const memoize = function (fn) {
  const cache = {};
  return function () {
    const KEY = JSON.stringify(arguments);
    if (cache[KEY]) {
      return cache[KEY];
    }
    const evaluatedValue = fn(...arguments);
    cache[KEY] = evaluatedValue;
    return evaluatedValue;
  };
};

Find and remove .DS_Store files from a git repo

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

Postgresql commands to determine sizes of database and tables

Entire database:

SELECT pg_size_pretty( pg_database_size('dbname') );

Specific table:

SELECT pg_size_pretty( pg_total_relation_size('tablename') );

Handy lua file i/o

-- see if a file exists
function file_exists(file)
    local f = io.open(file, "rb")
    if f then f:close() end
    return f ~= nil
end

-- run a shell script after ensuring that it exists
function do_file(file)
    if not file_exists(file) then return os.exit(0) end
    os.execute('./' .. file)
end

-- get all lines from a file, exits if the file does not exist
function lines_from(file)
    if not file_exists(file) then return os.exit(0) end
    lines = {}
    for line in io.lines(file) do
        lines[#lines + 1] = line
    end
    return lines
end

tmux cheatsheet

Split the screen vertically

CTRL+B %

Split the screen horizontal

CTRL+B "

Split the screen horizontally

CTRL+B "

Switch between screens

CTRL+B o

Switch left

CTRL+B Arrow-Left

Switch right

CTRL+B Arrow-Right

Create window

CTRL+B C

Switch to window by index

CTRL+B {index}
CTRL+B 0
CTRL+B 2

Detach from session

CTRL+B d

List running sessions

tmux ls

A gentle guide to get started with tmux.

Use bash to walk up a file tree looking for a known pattern

Sorta like recursively searching across nested folders, but upwards. See it used in moon maker.

find_up () {
  path=$(pwd)
  while [ -n "$path" ]; do
    path=${path%/*}
    if [ -d "$path/$1" ]; then
        echo "found $path/$1"
        return
    fi
  done
}

# find_up "$1"

Bookmarklets that convert the selected text to a well formatted snippet of markdown

javascript: (() => {
  const script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "https://unpkg.com/turndown/dist/turndown.js";
  script.async = false;
  script.defer = false;
  document.head.appendChild(script);
  script.addEventListener('load', () => {
      const selection = window.getSelection();
      const range = selection.getRangeAt(0);
      const turndownService = new TurndownService();
      const dummy = document.createElement('div');
      dummy.appendChild(range.cloneContents());
      const markdown = turndownService.turndown(dummy.innerHTML);
      const final = markdown + '\n\n-[' + document.title + ']' + '(' + location.href + ')';
      navigator.clipboard.writeText(final);
  })
})()

Use something like Marek Gibney’s bookmarklet editor to convert this snippet into a usable bookmarklet.

This is a simpler version of the same. It doesn’t have any external dependencies, but doesn’t convert formatted text to markdown.

javascript:(function () {
  const selection = window.getSelection().toString();
  const title = document.title;
  let final = '-[' + title + ']' + '(' + location.href + ')';
  if(selection) {
    final = selection + '\n\n' + final;
  }
  navigator.clipboard.writeText(final);
})();

Same as above, but this one prompts for tags.

javascript:(function () {
  const selection = window.getSelection().toString();
  const title = document.title;
  let final = '-[' + title + ']' + '(' + location.href + ')';
  if(selection) {
    final = selection + '\n\n' + final;
  }
  const tags = prompt('Make sure to append a # to each tag.');
  if(tags) {
    final = final + '\n' + tags
  }
  navigator.clipboard.writeText(final);
})();

Here is my preferred take on the post to linkhut” bookmarklet. It snags the selected text as the post’s description, and prompts you to enter some tags.

javascript:(function () {
  const tags = prompt('A space separated list of tags.');
  window.location="https://ln.ht/_/add?url="+encodeURIComponent(document.location)+"&title="+encodeURIComponent(document.title)+"&notes="+(window.getSelection().toString())+"&tags="+(tags)
})();

Here it is as a link that you can drag to your bookmarks: post to linkhut

Backlinks