Archiving all bash commands typed

This one’s a quickie. Just a second of my config to record all bash commands to a file (.bash_eternal_history) forever. The default bash HISTFILESIZE is 500. Setting it to a non-numeric value will make the history file grow forever (although not your actual history size, which is controlled by HISTSIZE).

I do this in addition:

#~/.bash.d/eternal-history
# don't put duplicate lines in the history
HISTCONTROL=ignoredups
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTFILESIZE=infinite
# Creates an eternal bash log in the form
# PID USER INDEX TIMESTAMP COMMAND
export HISTTIMEFORMAT="%s "

PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo $$ $USER \
"$(history 1)" >> ~/.bash_eternal_history'

Archiving all web traffic

Today I’m going to walk through a setup on how to archive all web (HTTP/S) traffic passing over your Linux desktop. The basic approach is going to be to install a proxy which records traffic. It will record the traffic to WARC files. You can’t proxy non-HTTP traffic (for example, chat or email) because we’re using an HTTP proxy approach.

The end result is pretty slow for reasons I’m not totally sure of yet. It’s possible warcproxy isn’t streaming results.

  1. Install the server
    # pip install warcproxy
  2. Make a warcprox user to run the proxy as.
    # useradd -M --shell=/bin/false warcprox
  3. Make a root certificate. You’re going to intercept HTTPS traffic by pretending to be the website, so if anyone gets ahold of this, they can fake being every website to you. Don’t give it out.
    # mkdir /etc/warcprox
    # cd /etc/warcprox
    # sudo openssl genrsa -out ca.key 409
    # sudo openssl req -new -x509 -key ca.key -out ca.crt
    # cat ca.crt ca.key >ca.pem
    # chown root:warcprox ca.pem ca.key
    # chmod 640 ca.pem ca.key
    
  4. Set up a directory where you’re going to store the WARC files. You’re saving all web traffic, so this will get pretty big.
    # mkdir /var/warcprox
    # chown -R warcprox:warcprox /var/warcprox
    
  5. Set up a boot script for warcproxy. Here’s mine. I’m using supervisorctl rather than systemd.
    #/etc/supervisor.d/warcprox.ini
    [program:warcprox]
    command=/usr/bin/warcprox -p 18000 -c /etc/warcprox/ca.pem --certs-dir ./generated-certs -g sha1
    directory=/var/warcprox
    user=warcprox
    autostart=true
    autorestart=unexpected
    
  6. Set up any browers, etc to use localhost:18000 as your proxy. You could also do some kind of global firewall config. Chromium in particular was pretty irritating on Arch Linux. It doesn’t respect $http_proxy, so you have to pass it separate options. This is also a good point to make sure anything you don’t want recorded BYPASSES the proxy (for example, maybe large things like youtube, etc).

Mail filtering with Dovecot

This expands on my previous post about how to set up an email server.

We’re going to set up a few spam filters in Dovecot under Debian. We’re going to use Sieve, which lets the user set up whichever filters they want. However, we’re going to run a couple pre-baked spam filters regardless of what the user sets up. Continue reading

Installing email with Postfix and Dovecot (with Postgres)

I’m posting my email setup here. The end result will:

  • Use Postfix for SMTP
  • Use Dovecot for IMAP and authentication
  • Store usernames, email forwards, and passwords in a Postgres SQL database
  • Only be accessible over encrypted channels
  • Pass all common spam checks
  • Support SMTP sending and IMAP email checking. I did not include POP3 because I don’t use it, but it should be easy to add
  • NOT add spam filtering or web mail (this article is long enough as it is, maybe in a follow-up)

Continue reading

Dependency Resolution in Javascript

Sometimes I have a bunch of dependencies. Say, UI components that need other UI components to be loaded. I’d really just like to have everything declare dependencies and magically everything is loaded in the right order. It turns out that if use “require” type files this isn’t bad (google “dependency injection”), but for anything other than code loading you’re a bit lost. I did find dependency-graph, but this requires the full list of components to run. I wanted a version would you could add components whenever you wanted–an online framework.

My take is here: https://github.com/vanceza/dependencies-online

It has no requirements, and is available on npm as dependencies-online.

Time management: Optimizers, Satisficers, Minimizers

I want to talk about three different mindsets for time management and what constitutes “success”. In all three, I’ll talk about an example problem, let’s say “writing term papers” for a student who finds this difficult, and see how each might approach the goal. My goal is not to promote one of these as best, but rather to illustrate that all three exist. Each may be favored by one person or another, or by a single person depending on the situation. I hope that by describing them, I can help people understand one another’s motivations, so as to facilitate communication. The first mindset I will call optimization. The optimizer tries to spend their time gaining resources. For example, they might work to get money. They also attempt to increase the rate at which they can gain resources. Some optimizers even try to increase the rate at which they can e.g. network or learn skills. The intuition here is that most goods are somehow fungible, and that you should try to get as many fungible goods as possible. Example of term papers: An optimizer might try to learn to write term papers, or get faster and faster at writing papers. If they got good at writing term papers, they might try to write even more (for example, taking classes heavy on papers) to take advantage of these skills. Heuristics:

  • Get nowhere faster: Get where you’re going faster, even if you don’t have a specific goal in mind
  • Level up: It’s always good to learn things and develop skills
  • Experiment: Never be content with the status quo. (Choose explore/exploit explicitly and dovetail, for principled experimenters)
  • Accumulate multipliers / Seek good trade routes: Be able to buy all things with money, learning, whatever you have most of. Try to maximize the rate.
  • Get money: Anywhere you have a resource coming in, increase the income rate, or trade rate you’re getting it for.

Failure modes:

  • Butterfly: Ends up unfocused and with no immediate or terminal goals.

The second mindset I will call satisficing. The satisficer is goal-oriented, and tries to stay focus on the goal at all times. Traditional goal-based time management like GTD encourages satisficing. Example of term papers: Their specific goal might be “Get an A on all papers until I graduate”. If they can write well enough to get an A, they probably would not learn to write better. If they can’t get an A, their goal might be better served by learning to write to rubrics. The question of learning to write better vs spending more time editing on each paper would be decided by the amount of time each would take for the actual number of term papers the student expected to write for their immediate goal. Heuristics:

  • Get to the goal as quickly as possible
  • No lost purposes: One of the strengths of satisficing is to avoid “rabbit holes” which don’t contribute to any end goal
  • Munchkin: Think about what will actually contribute to the goal, as well as what won’t.

Failure modes:

  • Tunnel vision / inflexibility: Not contributing to the immediate goal is not the same as being useless. Can lose sight of the big picture (supergoal or unrelated terminal goals) and ways to work toward that other than via the immediate goal.
  • EA Bot Syndrome / Don’t smell the flowers: Excessive goal focus can lose sight of human involvement, and end up giving the satisficer low life quality.

The last mindset I will call minimization. The minimizer will try to minimize the amount of resources spent on a particular task or problem. They will especially try to avoid any indefinitely-big cost. Example of term papers: The student might try to spend the minimum amount of time possible on the paper to get an A. If they knew they were going to write several papers, they might study how to write papers faster, so as to spend less total time–even if they expected the time learning to write faster would be greater than the time to write the immediate papers (“but what if there are more papers someday”). The eventual state of the minimizer will probably be to have set things up to avoid term papers, or write them very quickly. Heuristics:

  • Automate / Offload for free: Spend only a finite amount of time on something
  • Eliminate recurring costs
  • Asymptotic improvement: Any finite number of mistakes is okay, as long as you end up optimal eventually
  • Deal with it permanently: If you’re not closing things and returning to them indefinitely, you’re spending infinite time and attention on it
  • Timebox: Only spend a finite amount of time on something, and then consider it resolved forever

Failure modes:

  • Bad at goals: Minimization deals with recurring activities, but can fail to offer any positive motivation for one-time end goals
  • Negative mindset: Heavy focus on mistakes and resource use

Roasted Chickpeas

roastedHere’s how you make roasted chickpeas (aka garbanzo beans):

  1. Set the oven to 400F.
  2. Drain and empty a can or so of chickpeas into a collander and wash them
  3. Dry the chickpeas (this is the hard step). I use paper towels, but I haven’t figured out a way to not use a billion of them.
  4. Put them in a short pan in the oven and cover them in olive oil. Toss them some with your hands to get them coated.
  5. Cook for 20-30 minutes, shaking the pan so everything turns every 10 minutes. I like them crispy so I do 30 minutes.
  6. Take them out and transfer them to a bowl. Add spices. I like salt, garlic powder, and pepper.

 

Archiving Twitch

Install jq and youtube-dl

Get a list of the last 100 URLs:

curl https://api.twitch.tv/kraken/channels/${TWITCH_USER}/videos?broadcasts=true&limit=100 | 
  jq -r '.videos[].url' > past_broadcasts.txt

Save them locally:

youtube-dl -a past_broadcasts.txt -o "%(upload_date)s.%(title)s.%(id)s.%(ext)s"

Did it. youtube-dl is smart enough to avoid re-downloading videos it already has, so as long as you run this often enough (I do daily), you should avoid losing videos before they’re deleted.

Thanks jrayhawk for the API info.