Skip to content

Instantly share code, notes, and snippets.

View karlding's full-sized avatar
🤔

Karl Ding karlding

🤔
View GitHub Profile
@karlding
karlding / itunes-artist-photos.md
Created March 3, 2016 05:17
Grab iTunes image artwork from the DOM using the Open Graph meta tags

iTunes Artist Photos

The iTunes API doesn't provide a way to grab artist images, but the iTunes website uses Open Graph meta tags, which embeds a meta tag with a property attribute value set to og:image. As it turns out, this seems to be the same image used in the iTunes artwork.

The URL structure is similar to the artworkUrl values returned by the API, but what concerns us here is the part I've indicated at the end of the URL.

http://is3.mzstatic.com/image/thumb/Music7/v4/68/68/41/68684190-833b-bfb4-5018-e5a2e6f69eb0/source/1200x630bf.jpg
                                                                                                   └─ widthxheight
@karlding
karlding / bs-sans.py
Last active July 19, 2019 09:56
Parse TTX dumps and grab ligatures substitution rules found in GSUB tables (using Sans Bullshit Sans as an example)
import xml.dom.minidom
import sys
data = "".join(sys.stdin)
dom = xml.dom.minidom.parseString(data)
ligature_sets = dom.getElementsByTagName('LigatureSet')
char_map = dom.getElementsByTagName('cmap')[0].getElementsByTagName('cmap_format_4')[0].getElementsByTagName('map')
for ligature_set in ligature_sets:
@karlding
karlding / jobmine4days.user.js
Last active September 26, 2016 17:01
Prevents uWaterloo's JobMine system from logging you out automatically
// ==UserScript==
// @name JobMine4Days
// @namespace https://github.com/karlding
// @version 1.1
// @description Prevents uWaterloo's JobMine system from logging you out automatically
// @author Karl Ding
// @include https://jobmine.ccol.uwaterloo.ca/psp/SS*
// @include https://jobmine.ccol.uwaterloo.ca/psc/SS*
// @include https://jobmine.ccol.uwaterloo.ca/psp/ES*
// @include https://jobmine.ccol.uwaterloo.ca/psc/ES*
@karlding
karlding / ceca-stats.js
Created April 28, 2016 23:32
Screenshot each page of the CECA employment statistics website using CasperJS, for "safekeeping". Follow the on-screen prompts for instructions.
var system = require('system');
var casper = require('casper').create({
pageSettings: {
loadImages: true,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'
}
});
// read from cin to prevent login credentials being stored in bash history
@karlding
karlding / android-flashing.md
Created May 8, 2016 21:16
How to flash a new Android Factory Image, and various tips and tricks post-installation

Android fastboot flashing

Here are some instructions on how to successfully flash a new Android System Image.

Preparation

First download and extract the Android System Image that you want to flash. I'll be using hammerhead-mob30h, which is the May security update for my Nexus 5 (2013).

Extract the archive and enter the directory. You'll also want to extract the image-*.zip file as well (image-hammerhead-mob30h.zip in my case), which contains the other img files.

cd ~/Downloads/image-hammerhead-mob30h
@karlding
karlding / camera-raw.md
Created August 16, 2017 03:32
Deleting the JPG previews while keeping the DNGs

On my Nexus 5, I started shooting in RAW mode with JPG previews. However, when I copy the DNGs over to my laptop for editing/archival, I don't care about the JPG files.

The camera app creates two files:

  1. filename.jpg: the JPG preview
  2. filename.dng: the RAW file

Basically, we want to remove any JPG files for which a RAW file also exists. I

@karlding
karlding / pyenv+virtualenv cheat sheet.md
Last active June 2, 2020 03:45
pyenv and virtualenv cheat sheet
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=2.5
@karlding
karlding / downloading-vagrant-boxes-manually.md
Created January 14, 2018 05:45
how to download vagrant boxes manually

Download Vagrant boxes manually

In this example, we're going to download the Midnight Sun box.

# The box URL is https://app.vagrantup.com/uwmidsun/boxes/box/versions/2.1.0
# In general, we just take the box URL, and then append the provider URL
# https://app.vagrantup.com/<organization name>/boxes/<box name>/versions/<version>/providers/<provider>.box
wget https://app.vagrantup.com/uwmidsun/boxes/box/versions/2.1.0/providers/virtualbox.box -O box-2.1.0.box
#!/bin/bash
# Backup all my music from my Windows Music folder
# (/media/karl/5A14316614314673/Users/Karl/Music) to my 2 TB external drive
# (/media/karl/A0D83FDAD83FAE02/bak/Users/Karl/Music) using rsync
WINDOWS_MEDIA_DIR="/media/karl/5A14316614314673/Users/Karl/Music"
EXTERNAL_DRIVE="/media/karl/A0D83FDAD83FAE02/bak/Users/Karl"
rsync -va "${WINDOWS_MEDIA_DIR}" "${EXTERNAL_DRIVE}"