## Making CD Mixtapes

If I’m making informal CD mixtapes (mixdiscs?), use Foobar2000 (or other software) to convert the tracks to WAV, and then use ImgBurn to create a CUE file (Tools > Create CUE file…), drag and drop the tracks in to the new window, and customise the disc before burning it.

EAC can also be used for this (and is likely the better choice for making clones of audio CDs), but seems to be a little unreliable on my laptop. And I don’t like to waste CDs, especially when I only have 2 or 3 of them!

## Caching git credentials on Windows

You may have already used the git credential cache to cache your remote credentials for some time, via something like:

git config --global credential.helper 'cache --timeout=3600'

However this will not work on Windows, as cache communicates over a Unix socket.

Fortunately, support for Windows’s built-in credential manager has been added to the Windows git distribution (along with msysgit). To leverage it, use the wincred helper:

git config --global credential.helper wincred

If, like me, you like to use your dotfiles across many platforms, you may not want to put this in your global .gitconfig. Instead, you can include an environment-specific config file globally and make a new file with the credential helper configuration inside:

git config --global include.path .gitconfig_env
git config --file ~/.gitconfig_env credential.helper wincred

If you want to remove, modify or otherwise manage your Windows credentials, use the Credential Manager. This can be found in Control Panel > Credential Manager.

PRO TIP: In Windows 8 and above, you can quickly get to the Control Panel by pressing Win+X, P.

## Dynamic DNS (DDNS) on Asus routers

When using the stock or Merlin firmware on various Asus routers (I have an RT-N66U), you can use dynamic DNS to get a web domain to point to your router’s IP address.

To use dynamic DNS, do the following:

1. Go to your router’s administration console (sometimes available at http://router.asus.com) and head to WAN > DDNS. There is also a link on the Network Map page.
2. Enable the DDNS client, set Server to Custom and set the hostname to the web domain you will be updating (e.g. example.com).
3. Connect to the router. I tend to enable SSH (and disable Telnet) via Administration > System.
4. Create the script that will update your DDNS at /jffs/scripts/ddns-start. My favoured tactic here is to run:

cat > /jffs/scripts/ddns-start

Then paste the code, ensure the cursor is on a blank line (press Enter if not), then press Ctrl+D.

5. Finally, ensure the script is executable:

chmod +x /jffs/scripts/ddns-start

In my case, I’m updating an address using the http://afraid.org service. I get my private key from the dynamic section of the Afraid.org site, and I use a script taken almost verbatim from the Merlin wiki:

#!/bin/sh

curl "https://freedns.afraid.org/dynamic/update.php?<PRIVATE_KEY_HERE>"

if [ $? -eq 0 ]; then /sbin/ddns_custom_updated 1 else /sbin/ddns_custom_updated 0 fi ## Kodi with Sony Bravia TVs I’ve been setting up Kodi on my Sony Bravia Android TV — you can install it from the Google Play Store. Here are a few notes to help set things up how I like them: • My favourite skin so far is Arctic: Zephyr as it doesn’t have lots of gaudy images, runs fast, and displays long titles reasonably well (good for both music and long video names). • I’ve added some useful functions to the Sony remote control; install the Keymap Editor add-on and then make the following adjustments: • Information (i+) button: Global > Navigation > Context Menu • Red button : Global > Window > Open Home • Green button: Global > Window > Open Favourites • Yellow button: Global > Window > Open Fullscreen Video (allows you to return to a video if you go in to a menu) • Blue button: Nothing yet! Update 2017-05-14: The new Estuary skin that comes as default in Kodi 17 is exactly to my tastes so I use that now. ## Building and Testing a Jekyll website with Docker on Windows I’ve recently talked about [how I’ve changed my website to be created with Jekyll][migrate-to-jekyll]. One of the big reasons was to simplify how the site is built and run. Well, if it’s so simple now, then I should be able to modify it on the go within Windows, right? I’ve recently been using an openSUSE VM to modify the site, but figured I could do one better and operate (mostly) natively. This article describes my solution. It is assumed that you already have a Jekyll site to work with. Much of this will also work for anyone using the Linux or Mac OS X versions of Docker Toolbox, but I’m approaching with a view to running this on Windows. [migrate-to-jekyll]: {% post_url 2015-10-04-migrating-from-wordpress-to-jekyll %} # Install Docker Toolbox Install Docker Toolbox. If you’re not familiar with Docker or Docker Toolbox, I highly recommend you go through their tutorials. One note: If you already have VirtualBox installed or prefer to install it yourself, uncheck the VirtualBox option in the installer. # Create a Docker Machine Docker Toolbox creates a couple of shortcuts for you. If you run Docker Quickstart Terminal, a machine called default will be automatically created for you. Alternatively, you can create one with your own name from the command line: docker-machine create --driver virtualbox dev As you’ll see later on, I decided to go the route of managing this myself with my build script. # Create Dockerfile To run Jekyll in Docker, you need to build a Docker image! It struck me as simplest to build my own: FROM debian:latest # Install jekyll dependencies RUN apt-get update && apt-get -y install \ gcc \ make \ nodejs \ python \ ruby \ ruby-dev \ && gem install bundler # Install site dependencies WORKDIR /site COPY Gemfile Gemfile.lock /site/ RUN bundle install # Copy site files COPY . /site/ CMD ["bundle", "exec", "jekyll", "serve", "--port=4000", "--host=0.0.0.0"] EXPOSE 4000 I chose port 4000 as it isn’t either 8000 or 8080, which can be commonly used by other applications. You’ll note that Gemfile and Gemfile.lock are copied first. Docker creates a layer out of each instruction (e.g. RUN, COPY) in the Dockerfile, and caches them. This means a layer only needs to be rebuilt if it or one of its parents has changed. These copied files are used to install your website’s dependencies, and since this is generally quite a slow operation compared to actually building the site, I opt to get the install done first and utilise Docker’s layer cache. # Create .dockerignore (and why it’s needed) Docker builds work by archiving and sending the entire contents of the current working directly to the Docker daemon — the build does not happen on your local machine, but entirely on the remote machine. This means that if you have many temp, cache or large files that are not needed for the build, they will needlessly slow the build down. to counter this, a .dockerfile can be created to tell the local Docker client which files the remote Docker daemon will not need. .dockerignore works very similar to .gitignore. I’ll make a very simple one that ignores _site, just in case a build has happened locally: _site # Create PowerShell build script I created a build script, build.ps1, at the root of my website. In this build script I create a Docker machine (if it doesn’t exist) or start it (if it does), configure Docker to communicate with it, print out instructions on how to see the website, and finally build and serve it: # Site building script for Powershell and Docker Toolbox # Set the name of the machine set machine dev # Set up and/or start the machine -- note that create also starts the machine docker-machine create --driver virtualbox$machine
docker-machine start $machine # Set up Docker's env vars so it can connect docker-machine env --shell=powershell$machine | Invoke-Expression

# We now need a means to connect to the website once it runs.  there are two methods:
# Method 1: Enable forwarding the port -- with thanks to http://stackoverflow.com/a/32175164
#   Only problem with this method is that it needs VBoxManage to be a part of the PATH -- this is a manual change.
#VBoxManage modifyvm $machine --natpf1 "jekyll,tcp,127.0.0.1,4000,,4000" # Method 2: Connect to the docker machine's IP directly without port forwarding # Example address: http://192.168.99.100:4000/ docker-machine ip$machine | set ip
echo "Building website; will be available in a few moments. Press Ctrl+C when done."
echo "Connect to: http://${ip}:4000" # Build and serve the website (docker build -t blog .) -and (docker run -it --rm --publish=4000:4000 blog) Note: The very last command, with the -and in the middle, will absorb all stdout, meaning that things will look very quiet. Rest assured that if the script doe not end, then things are working fine. If you update the site and want to see what the changes look like, or are simply finished, press Ctrl+C and then re-run the build script as desired. # Profit While not certainly not as easy to modify as when I’m on a Linux machine, this is certainly a big improvement on local testing than trying to run a Wordpress stack on Windows! I’ve also learnt a lot about docker-machine. It may or may not be possible to mount the Windows website directory on to the docker machine in order to allow rebuilds on file modification, but I suspect that may turn out to be difficult, complicated or fragile, and the method described above works for me. If I change my mind, I’ll inevitably describe what I do! Hopefully this guide helps you out, as well as future me! ## Deploying Jekyll website on git commit One reason for [migrating to static site generation][migrate-to-jekyll] is that the site becomes more straightforward to keep in version control systems such as git. And I do like version control; I naturally ran git init before I ran jekyll new! In my workflow, once I have made and committed changes locally, I push the changes remotely. But now I need to build and deploy the new version of the site. What if I could get that to happen automatically? To do this, I set up my web server to accept git commands; this is a topic unto itself which I might write about some time. I then create a bare repo: git init --bare blog.git After setting permissions as appropriate, I can now push my git repo to the web server: git remote add origin https://user@your.website.tld/git/blog.git git push -u origin master I then modified an example git-hook I found on the Jekyll website to be more robust and meet my needs. There are a few things to take note of here: • I switched from using the git-receive hook as per Jekyll’s recommendation to post-receive. This is because the level of info git-receive, ahem, receives seems a bit overkill — post-update provides the names of the modified branches, and that’s all we need. • DEPLOY_REF_REGEX is a regex that matches git-refs, such as branches. The value in my script means that it’ll only deploy the website when changes are pushed to master. This means you are free to experiment on non-master branches. I haven’t gone so far as to deploy different branches different places! • GIT_REPO is the path to your site’s git repo. Ensure it can be read by the webserver. • PUBLIC_WWW is where the website needs to be deployed to be visible on the web. Ensure it is writable by the webserver. To use this hook, create a file called post-update in your remote bare repo’s hooks directory. Ensure it is executable by your webserver! #!/bin/bash # Builds and deploys blog when new commits are pushed to the specified branches (default master). # # Despite the Jekyll site recommending to use the post-receive hook, we do not # need the level of information that post-receive gets. post-update receives # each ref that was updated as an argument, and so is sufficient for this # script's needs. # # The script also adds the commit ID of the deployed commit to the site, so you are able # to tell exactly what is live by visiting /deployed_commit. # # Originally taken from: http://jekyllrb.com/docs/deployment-methods/#git-post-receive-hook # DEPLOY_REF_REGEX=refs/heads/master GIT_REPO=/shared/code/git/blog.git PUBLIC_WWW=/var/www/blog DEPLOY= for ref in "$@"; do
if [[ $ref =~$DEPLOY_REF_REGEX ]]; then
DEPLOY=true
break
fi
done

if [ $DEPLOY ]; then TMP_GIT_CLONE=$(mktemp -d)
git clone "$GIT_REPO" "$TMP_GIT_CLONE"
echo $(GIT_DIR=.git git -C "$TMP_GIT_CLONE" rev-parse HEAD) > "$TMP_GIT_CLONE/deployed_commit" jekyll build -s "$TMP_GIT_CLONE" -d "$PUBLIC_WWW" rm -Rf "$TMP_GIT_CLONE"
else
echo "Updated refs did not match; not deploying."
fi

exit

You’ll get output like the following:

\$ git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 3.15 KiB | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Cloning into '/tmp/tmp.TkcxSnfVnb'...
remote: done.
remote: Configuration file: /tmp/tmp.TkcxSnfVnb/_config.yml
remote:             Source: /tmp/tmp.TkcxSnfVnb
remote:        Destination: /var/www/blog
remote:       Generating...
remote:                     done.
remote:  Auto-regeneration: disabled. Use --watch to enable.
To https://user@your.website.tld/git/blog.git
df05e56..ce42b80  master -> master

If the deploy succeeds, then website should be available on the internet and you are done! If the deploy fails, the push will be cancelled and you’ll need to investigate why that might be. I would first check the permissions on all of the directories mentioned above.

Finally, as a little bonus, the script creates a deployed_commit file which contains the commit SHA of the commit the build was based on; useful if something goes wrong or you just want to check what you last deployed. You can even check my site’s deployed commit (update: now defunct)!

[migrate-to-jekyll]: {% post_url 2015-10-04-migrating-from-wordpress-to-jekyll %}

## JavaScript Promises Notes

Some notes to remind future me why Promises are pretty neat.

# What do they give me?

• They let you regain error handling for asynchronous operations.
• They let you avoid nested callbacks (and the pyramid indentation that comes with them).

# Can I use them?

They were initially formalised in the Promises/A+ specification, and have been officially adopted in to JavaScript with ES6.

They’ve been supported in all major browsers (except IE) for a while now. A polyfill exists for browsers that do not support them.

# Any important details?

• Promises can start executing the instant they have been instantiated. However, this does not strictly mean that they will be.
• If you call .then(success_function, failure_function) on a Promise, the appropriate function will not be called until a Promise has settled — either fulfilled or rejected.
• Calling .catch() is equivalent to calling .then(null, function).

# I need help visualising them

Try Promisees — it’ll visualise and animate the promise-y code you give it. You can also slow down the animation and record animated GIFs!

## Fix installing packages for python2 in openSUSE

If you have both python2 and python3 installed on openSUSE, you might find when you use pip to install packages that they install for python3, not python2!

This seems to be because the pip command that is run comes directly from the python3 install.

To fix it, install the python-pip SUSE package, then use it as default:

zypper install -n python-pip
update-alternatives --config pip

When prompted for which pip to use, ensure you select the python2 version.

Now when you use pip, you’re modifying python2. To modify python3, run pip3.

## Enable spell checking in Sublime Text just for Markdown (or any individual syntax)

1. Open or create a Markdown document (or another file type you want to enable spell-checking for)
2. Go to Preferences > Settings - More > Syntax Specific - User