katrielalex

misc thoughts and notes

Read this first

remote time machine

Super easy: you can use a Linux server running netatalk as a Time Machien backup drive. Easy peasy.

Instructions at the link, but in brief:

sudo apt install build-essential devscripts debhelper cdbs autotools-dev dh-buildinfo libdb-dev libwrap0-dev libpam0g-dev libcups2-dev libkrb5-dev libltdl3-dev libgcrypt11-dev libcrack2-dev libavahi-client-dev libldap2-dev libacl1-dev libevent-dev d-shlibs dh-systemd avahi-daemon libc6-dev libnss-mdns

git clone https://github.com/adiknoth/netatalk-debian
cd netatalk-debian
debuild -b -uc -us
sudo dpkg -i ../*.deb

sudo nano /etc/netatalk/afp.conf

You probably want to make a new user with adduser --home $BACKUP_DIR and point the backups to there, adding valid users = $user to afp.conf.

Give it a while for avahi to kick in (I rebooted) and then you should see it in the list of Time Machine drives you can add in Settings.

Continue reading →


spotifyd

This is all pretty obvious, but recording it here for posterity. spotifyd is an open-source, lightweight Spotify client for Premium accounts. We use it for our home server, which runs a couple of instances to enable Spotify Connect to the home speakers.

Setup is pretty easy but requires a little systemd messing around. Step 1 is to clone the repo and build spotifyd (which needs Rust’s cargo), and then symlink it into /usr/bin. I’m using the pulseaudio backend, so the command to build is cargo build --release --features pulseaudio_backend. Step 2: write

[Unit]
Description=A spotify playing daemon
Documentation=https://github.com/Spotifyd/spotifyd

[Service]
ExecStart=/usr/bin/spotifyd --no-daemon
Restart=always
RestartSec=12

[Install]
WantedBy=default.target

to /etc/systemd/user/spotifyd.service and chmod it to readable for everyone. Step 3: for each user that wants to run spotifyd...

Continue reading →


user pulseaudio

Michael and I have a home server running spotifyd (which is really a story for another post); each running a user systemd service to keep it up.

This seemed to confuse pulseaudio a little. The default ubuntu configuration runs one pulseaudio service per user, and only the “active user” gets to actually make sounds come out of the speakers. The definition of active user wasn’t entirely obvious; if someone was logged in to a graphical session then they got it, and otherwise it seemed to take turns based on who was actually playing.

Anyway, apparently it’s not recommended to run pulseaudio as a system user, mostly for security reasons, but as an Official Security Person I can clearly ignore all of these and just run it anyway. So, to get it working:

sudo systemctl enable pulseaudio
sudo systemctl start pulseaudio

then for each user that should play music, add that user to the audio and...

Continue reading →


fish history sync

I use fish in tmux with maybe two dozen shells open at a time, for various projects that I have hanging around. By adding

# history across fishes
function save_history --on-event fish_preexec
    history --save
end
alias hr 'history --merge'  # read and merge history from disk
bind \e\[A 'history --merge ; up-or-search'

to ~/.config/fish/config.fish, reverse search now syncs across all history in all shells (or you can bring a shell up to date with all other shells using hr). That feels good.

View →


flux and hue

[f.lux](www.justgetflux.com) is pretty awesome. Now that my room is lit by hue, I wanted a way to make my room colour temperature match my screen. This requires a few ingredients:

  • a working hue setup, obviously
  • some way to control the lights from the command line. You don’t actually need anything for this, since the bridge actually just accepts HTTP requests to set values, but it’s nice to have a wrapper so you don’t have to worry. I used hue-cli – which, beware, is not the only hue-cli package out there. It has a command hue lights all red which does what you expect
  • some way to get the desired colour temperature when the script is run. Ideally I’d use the f.lux one, and I’ve emailed the devs to ask, but in the meantime the open-source f.lux clone redshift will tell you what it thinks the colour should be given your current location. Note that f.lux has much more aggressive reddening...

Continue reading →


tmuxinator

A quick one: tmuxinator is a super-easy way to manage your tmux configurations, setting up windows and panes just as you like them. When set up, you just have to run

mux work

to connect to your “work” tmux session. Mine, for instance, opens up three different windows, for each of three projects I’ve been working on lately, and one editor window that I just use for command-line stuff, split into two panes.

To get it working just brew install tmux tmuxinator, and then run mux new work to set up a “work” tmuxinator config.

View →


iButton hackery

To get in to various places around Oxford, many places use little iButton fobs, which run on the Dallas Semiconductors 1-Wire protocol. When you tap them against a “master” device, they broadcast their unique ID, which the master can then look up in its list of people.

iButton fob

Kevin and I decided that this was excessively simple, and that we should build something to read and impersonate these fobs. Fortunately, the 1-Wire protocol they use is relatively standard, and there’s already an Arduino library to handle them.

The circuit you need is simple: connect some pin to a 4.7k resistor, +5v power and the centre of the fob, and ground the outside. Then run the following and the serial monitor should spit out the unique ID of any iButton you tap.

#include <OneWire.h>

// This is the pin with the 1-Wire bus on it
OneWire ds(PIN_D0);

// unique serial number read from the key
byte addr[8];

//
...

Continue reading →


Yosemite broke my git svn

Previously on Mavericks:

$ git svn rebase
Can't locate SVN/Core.pm in @INC (@INC contains: /usr/local/Cellar/git/1.8.4/lib /Library/Perl/5.16/darwin-thread-multi-2level /Library/Perl/5.16 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.16 /Library/Perl/Updates/5.16.4 /System/Library/Perl/5.16/darwin-thread-multi-2level /System/Library/Perl/5.16 /System/Library/Perl/Extras/5.16/darwin-thread-multi-2level/System/Library/Perl/Extras/5.16 .) at /usr/local/Cellar/git/1.8.4/libexec/git-core/git-svn line 41.

Solution: since the system Perl 5.16 contains SVN::Core, link it in from /Applications/Xcode.app/Contents/Developer/Library/Perl/5.16.

Now on Yosemite:

$ git svn rebase 
Can't locate SVN/Core.pm in @INC (you may need to install the SVN::Core module) (@INC contains: /usr/local/git/lib/perl5/site_perl
...

Continue reading →


latexmk and auctex

Compiling LaTeX is a pain. LaTeXmk is a Perl script (eww) which iterates compilations, including of the bibliography, until complete.

auctex-latexmk integrates it with AucTeX‘s C-c C-c cycle. You need to add the following to .latexmkrc (the former to stop the compilation process hanging when you make a mistake, and the latter because emacs doesn’t know how to tell latexmk to compile pdfs).

$pdflatex = 'pdflatex --shell-escape -interaction=nonstopmode -file-line-error -synctex=1 %O %S';
$pdf_mode = 1;

Other useful commands include

  • latexmk -C removes all automatically generated files
  • latexmk -pvc continuously recompiles

Continue reading →


zotero + emacs + latex = awesome

As a PhD student, I have to reference a lot of stuff, which I do with Zotero. It struck me a while ago that it would be nice if this integrated with my LaTeX editor of choice, and so I spent a morning doing just that. Now, I can add references straight from Firefox, and immediately add a BibTeX citation to them in Emacs with C-c [.

  1. Install Zotero and set it up.
  2. Install the fantastic AutoZotBib Zotero extension. Take care: it looks like a Firefox extension, but you install it from Zotero’s add-on menu not Firefox’s.
  3. Configure AutoZotBib to dump your Zotero library to a .bib file somewhere.
  4. Enable the RefTeX minor mode (which you should already have as part of Emacs). If using biber, you also have to tell RefTeX that \addbibresource gives the path to the bibliography.

    (add-hook 'LaTeX-mode-hook 'reftex-mode)
    (setq reftex-plug-into-AUCTeX t)
    (setq reftex-bibliography-commands
    ...

Continue reading →