Category Archives: Uncategorized

Building CyanogenMod without the device

Lately I’ve been working on a research project concerning android’s dalvik vm. Unfortunately, to compile cyanogenmod (at least for the Nexus 7), some proprietary drivers from the device are required (i.e. via ./ in the build guide for grouper ).

Now it may be inconvenient for you to actually attach the device (like if you are using a build server). So how to get the drivers? Surprisingly google didn’t offer any hints, but there is a straightforward way to do it… extract them from a cyanogenmod nightly build!


To make it even easier, here is a modified that pulls them from the extracted grouper build of your choice


# A hack to pull the binary files from a pre-existing build
# of this cyanogenmod (i.e. a nightly)
# Alex Knaust 2013-05-02


# Path to the unzipped nightly with the correct blobs


mkdir -p $BASE
for FILE in `cat proprietary-blobs.txt | grep -v "^#"`; do
    cp -v $NIGHTLY/$FILE $BASE/


Subsample directories of files

This script will allow you to trim a folder(s) full of files to a fixed number of files, sampling randomly. My use case was to select a subsample of training images for CV research, but it could be used for whatever you like!

# Programmed by Alex Knaust 2013-03-12

import os, sys, random

def sampleFiles(k, dirs):
	'''Deletes a random sample of files, leaving k remaining
	from each directory. The directories must have identical filenames
	and identical filecounts, otherwise we are in trouble
	totalFiles = len(os.listdir(dirs[0]))
	if k >= totalFiles:
		print 'Not enough files to sample from'
	# python magic at work
	stuff = [sorted([os.path.join(d, p) for p in os.listdir(d)]) for d in dirs]
	destroy = random.sample(zip(*stuff), totalFiles - k)
	return destroy

if __name__ == '__main__':
	if len(sys.argv) < 3:
		print('Pass number of files to sample, and directories to sample from')
	k = int(sys.argv[1])
	dirs = sys.argv[2:]
	destroy = sampleFiles(k, dirs)
	ans = raw_input('Will delete %d files, OK? y/n : ' % (len(destroy) * len(dirs)))
	if ans[0].lower() == 'n':
		print 'Goodbye'
	#do the actual deletion
	for files in destroy:
		for f in files: