Skip to content

Instantly share code, notes, and snippets.

View karlding's full-sized avatar
🤔

Karl Ding karlding

🤔
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / mips.h
Created February 7, 2016 05:21
Register map for the subset of MIPS used in CS 241
// register map
#define ADD 0x20
#define SUB 0x22
#define MULT 0x18
#define MULTU 0x19
#define DIV 0x1a
#define DIVU 0x1b
#define MFHI 0x10
#define MFLO 0x12
#define LIS 0x14
@karlding
karlding / stackitup.cc
Created January 22, 2016 22:59
Stacks on stacks (implement a program that reads in push, pop, and inc operations, output the top of the stack at the end of each operation, prevent errors)
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main() {
string s;
stack<int> st;
while (cin >> s) {
int i;
@karlding
karlding / zigzagarray.cc
Created January 22, 2016 22:39
Because I'm silly and tried to use std::swap and make some "smart" optimizations without thinking on a HackerRank problem :(
// print out array in zigzag format
// time: O(n log n) = O(n log n) + O(n log n) + O(n)
// space: O(3n)
std::vector<int> zigZagArray(std::vector<int> intArray) {
std::vector<int> v(intArray);
// sort descending order
std::sort(intArray.rbegin(), intArray.rend());
// sort asc
std::sort(v.begin(), v.end());
@karlding
karlding / disable-narrator.reg
Created January 14, 2016 19:05
Disable Narrator
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\Narrator.exe]
"Debugger"="%1"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\AtBroker.exe]
"Debugger"="%1"
@karlding
karlding / Makefile
Created November 29, 2015 04:58
generic annotated Makefile
# set the compiler name
CXX = g++
# set the compiler flags
# Wall: show all warnings
# MMD: create dependency files
# g: compile binaries with debugging info
CXXFLAGS = -Wall -MMD -g
# object files