2021-05-27
I've recently come across the term Memex; a fictional device that acts as a mechanical external memory bank. A way to store and access knowledge that you just don't have the brain capacity to keep otherwise.
The wikipedia article about it explains it better.
In essence our smartphones of today are very much a type of Memex of their own. The internet in our pocket gives us near-instant access to virtually all the combined knowledge and experiences of the entire humankind. Almost.
It doesn't help much when it comes to retrieving your own personal experiences. A blog can help with that, of course. A way to store your ideas and thoughts for later refinement, combination, articulation. I've linked to Cory Doctorow's essay on that subject previously:
https://doctorow.medium.com/the-memex-method-238c71f2fb46
I had an epiphany regarding this yesterday. My youngest turned 6, and of course there was discussion among the around birthday presents. And I can't recall what the other kids were given from everyone on their birthdays (one and two months ago... My memory is great, but short!).
I'm a little sick of never remembering stuff like that. That friend that changed jobs six months ago, where do they work now? Was it this warm/cold last year at this time? What did we get X for Christmas?
This isn't exactly stuff I'd like to put on my blog, and neither is it really ideas or thoughts that will develop over time. It's just tidbits of information that I'd like to have access to now and then.
So I wrote another CGI script, based on my blog editor. It's in ugly bash and it's simplistic and will probably need to be optimised when I've reached a few tens of thousands of entered "memories", but it's better to have something to evaluate than nothing at all.
This is of course on my own domain, protected by login. The interface is simple: an input text field, a search button and a submit button. The submit button adds a line to a text file; the search button uses grep to search it, returning all lines that contain all the entered search terms in reverse chronological order.
#!/bin/bash
echo "Content-Type: text/html"
echo
echo
echo '<!DOCTYPE html>
<html>
<head>
<style>
body {
max-width: 45em;
margin: auto;
padding: 20px;
}
</style>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
<title>Memex</title>
</head>
<body>
<h1>Memex</h1>
<form action="memex.cgi" method="post">
<input type="text" name="note" id="note" style="width: 100%"><br/>
<input type="submit" value="Search" name="search"><input type="submit" value="Submit" name="submit">
</form>'
# When something is submitted, treat it and post
if [[ $REQUEST_METHOD == "POST" ]]; then
POST_DATA=$(cat -)
POST_VARS=(${POST_DATA//&/ })
for i in "${POST_VARS[@]}"
do
STRING=${i//+/ }
POST_VAR_VALUE=$(echo -e "${STRING//%/\\x}")
case "${POST_VAR_VALUE}" in
note=* ) export POST_TEXT="${POST_VAR_VALUE/note=}";;
search=* ) ACTION="SEARCH" ;;
submit=* ) ACTION="SUBMIT" ;;
esac
done
cd ~/Memex
if [[ $ACTION == "SUBMIT" ]]; then
echo -e "$(date --utc +%FT%H:%M:%S)\t${POST_TEXT}" | dos2unix >> "memex.txt"
echo "<p>Posted.</p>"
elif [[ $ACTION == "SEARCH" ]]; then
read -ra term_array <<< "${POST_TEXT}"
RESULT="$(cat memex.txt)"
for term in "${term_array[@]}"; do
RESULT="$(echo "${RESULT}" | grep -i "${term}")"
done
echo "${RESULT}" | tac | sed -e 's;^;<p>;g' -e 's;$;</p>;g'
fi
fi
echo ' </body>
</html>'
-- CC0 Björn Wärmedal