Skip to content

Instantly share code, notes, and snippets.

@sveinungkb
sveinungkb / extract_assets.py
Last active July 17, 2020 13:51
Small python script to pull out all versions of one or more drawables or resources, recreating their paths for all densities. Run with e.g.: python extract_assets.py ic_launcher
import sys, os
def findAsset(asset, folder):
for file in os.listdir(folder):
if os.path.isdir(folder + "/" + file):
findAsset(asset, folder + "/" + file)
if asset in file:
inFile = "%s/%s" % (folder, file)
outFolder = "exported/%s" % (folder)
outFile = "%s/%s" % (outFolder, file)
@sveinungkb
sveinungkb / build.gradle
Created February 9, 2019 17:01
Gradle tasks and classes to read Android version (versionName, versionCode) from properties and store an incremented build number
android{
defaultConfig {
...
versionCode readVersion().versionCode()
versionName readVersion().versionName()
....
class Version {
Integer major
Integer minor
@sveinungkb
sveinungkb / AutomationTest.java
Created May 12, 2016 18:10
Convenient parent class for UI automation tests to ensure successful runs. Will wake screen, unlock if necessary and optionally show the home screen.
import android.app.Activity;
import android.app.Application;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
@sveinungkb
sveinungkb / github-history.py
Last active October 22, 2015 17:34
Simple script that will use Github's API to read a number of repo's commit history into .csv so it can be processed in other tools (Excel, R, Matlab)
import requests
import re
import os
import datetime
OAUTH_TOKEN = 'YOUR-TOKEN
ORGANIZATION = "org"
REPOS = ["repo1", "repo2"]
# Uncomment to get all repos for org
# REPOS = []
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@sveinungkb
sveinungkb / android-screen-gif.sh
Last active May 23, 2017 14:41
Bash script to record screenshots on Android until interrupted, then assemble all screenshots to an animated GIF. Useful for demos etc. Requires ImageMagick's (convert) to be on your path.
#!/bin/sh
PREFIX="Screenshot-$(date +%Y%m%d-%H%M%S)"
BASE="/sdcard/$PREFIX"
DELAY=300
trap ctrl_c INT
function clean_up() {
rm -f $PREFIX*.png
@sveinungkb
sveinungkb / tc-grep-set-parameter.py
Created March 24, 2015 22:58
This python script will look for a regexp pattern in whatever is piped to it, and echo back a Team City service message to set this as a build time variable using a service message.
import fileinput
import sys
import re
valuePair = sys.argv[1]
name = valuePair.split("=")[0]
valuePattern = valuePair.split("=")[1]
if not (name and valuePattern):
print("Call like this 'echo \"Lorem ipsum doler sit\" | python tc-grep-set-parameter.py 'jibberish=(ipsum)'")
@sveinungkb
sveinungkb / generate-report.py
Last active October 28, 2020 06:42
HP Unified Functional Testing report to ANT JUnit XML
# By Sveinung Kval Bakken @ iHeartRadio
# http://tech.iheart.com
#
# This script will parse any HP Unified Functional Testing reports and generate ANT JUnit XML reports
# for use with Team City / Jenkins
import sys
from xml.dom import minidom
from xml.dom.minidom import Document, Element
@sveinungkb
sveinungkb / SystemProperties.java
Created March 18, 2015 14:25
Provides access to Android's system properties (read only)
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software