Skip to content

Instantly share code, notes, and snippets.

View liminal's full-sized avatar

Karl Åström liminal

  • Stockholm/Sweden
View GitHub Profile
@liminal
liminal / build.gradle
Created March 15, 2021 09:25
Add tasks to uninstall apks
// Add helper tasks for uninstalling the apk from devices/emulators
android.applicationVariants.all { variant ->
tasks.create(name: "uninstall${variant.name.capitalize()}Apk", type: Exec, group: "uninstall") {
ignoreExitValue = true
commandLine android.getAdbExe(), 'uninstall', variant.applicationId
}
}
@liminal
liminal / java_8_everything_build.gradle
Created December 10, 2018 12:03
The "I just want everything to be Java 8" root build.gradle additions
// Just add these to the root build.gradle of any project where
// you just want everything to be Java 8 by default
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin" == plugin.class.name
|| "com.android.build.gradle.LibraryPlugin" == plugin.class.name) {
project.android.compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
@liminal
liminal / new_laptop_setup.sh
Last active September 7, 2018 12:46
New Laptop Setup
COMPUTER_NAME=<shade of green>
# Setup hostname
# Type the following command to change the primary hostname of your Mac:
# This is your fully qualified hostname, for example myMac.domain.com
sudo scutil --set HostName $COMPUTER_NAME
#Type the following command to change the Bonjour hostname of your Mac:
#This is the name usable on the local network, for example myMac.local.
sudo scutil --set LocalHostName $COMPUTER_NAME
@liminal
liminal / PrintKeyHash.java
Created April 3, 2018 09:16
[print keyhash] Code to quickly print the signing keyhash (sometimes useful for getting api keys) #android
public static String printKeyHash(Activity context) {
PackageInfo packageInfo;
String key = null;
try {
//getting application package name, as defined in manifest
String packageName = context.getApplicationContext().getPackageName();
//Retriving package info
packageInfo = context.getPackageManager().getPackageInfo(packageName,
PackageManager.GET_SIGNATURES);
@liminal
liminal / reasonable_rx_errorhandler.kt
Last active April 3, 2018 09:17
[Reasonable app error-handling for RxJava2] #android #rx
RxJavaPlugins.setErrorHandler(
{ err ->
var e = err
if (e is UndeliverableException) {
e = e.cause
}
when (e) {
is IOException, is SocketException -> return@setErrorHandler // fine, irrelevant network problem or API that throws on cancellation
is InterruptedException -> return@setErrorHandler // fine, some blocking code was interrupted by a dispose call
is NullPointerException, is IllegalArgumentException -> {
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<!-- Set AppTheme.Launcher for launcher activity -->
<activity
android:name=".MainActivity"
android:theme=”@style/AppTheme.Launcher”>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
@liminal
liminal / build.gradle
Created March 29, 2017 12:50 — forked from DariusL/build.gradle
A gradle task to upload android build artifacts to dropbox
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
task pushDropbox << {
def outName;
if (System.getenv("GITLAB_CI")) {
outName = "app-debug-${System.getenv("CI_BUILD_REF_NAME")}-SNAPSHOT.apk"
} else {
outName = "app-debug.apk"
}
@liminal
liminal / publish-apk.gradle
Created February 23, 2017 19:21
snippet for uploading your apks to a nexus repository manager
apply plugin: 'maven-publish'
publishing {
repositories {
maven {
url "http://localhost:8081/repository/maven-releases/"
credentials {
username "admin"
password 'admin123'
@liminal
liminal / 0_reuse_code.js
Created March 13, 2016 11:32
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@liminal
liminal / example_permission_setter.sh
Created December 2, 2015 22:27 — forked from RussellCollins/example_permission_setter.sh
Set write and read external storage permission prior to a test run so that a screenshot on fail listener can work on device targets running Android 6.0+
SDK=`adb shell getprop ro.build.version.sdk | tr -d '\r'`
echo "Device SDK level is: " $SDK
if (( "$SDK" >= 23 )) ; then
echo "Enabling read and write external storage permissions before running tests on Android 6.0+"
adb shell pm grant com.replace.with.your.app.package android.permission.WRITE_EXTERNAL_STORAGE
adb shell pm grant com.replace.with.your.app.package android.permission.READ_EXTERNAL_STORAGE
fi