Skip to content

Instantly share code, notes, and snippets.

View Sloy's full-sized avatar

Rafa Vázquez Sloy

View GitHub Profile
@alexismp
alexismp / index.js
Last active November 8, 2022 21:58
Node.js 8 Cloud Function to write to a Google Sheets document
// Copyright 2018 Google LLC.
// SPDX-License-Identifier: Apache-2.0
const { google } = require("googleapis");
const { Storage } = require("@google-cloud/storage");
exports.csv2sheet = async (data, context) => {
var fileName = data.name;
// basic check that this is a *.csv file, etc...
if (!fileName.endsWith(".csv")) {
@cketti
cketti / android-28-sources.md
Created August 7, 2018 16:21
Build your own android-28 sources

Build "Sources for Android 28" so you can comfortably browse the Android API source in Android Studio.

  1. Collect source files
mkdir android-sdk-source-build
cd android-sdk-source-build

mkdir -p frameworks/base
@hvisser
hvisser / DemoModeEnabler.kt
Created January 23, 2018 11:44
Enables demo mode on a device for the purpose of taking screenshots
class DemoModeEnabler {
fun enable() {
executeShellCommand("settings put global sysui_demo_allowed 1")
sendCommand("exit")
sendCommand("enter")
sendCommand("notifications", "visible" to "false")
sendCommand("network", "wifi" to "hide")
sendCommand("battery", "level" to "100", "plugged" to "false")
sendCommand("clock", "hhmm" to "1000")
@drewhannay
drewhannay / FinishingActivityTestRule.java
Last active June 21, 2017 18:25
Android Espresso Activity Clean Up
/**
* Copyright (C) 2017 Drew Hannay
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
@Sloy
Sloy / InjectedInstrumentationTest.java
Last active June 7, 2018 11:15
Injector (Dagger 1)
public class InjectedInstrumentationTestRule implements MethodRule {
private final Object testModule;
public InjectedInstrumentationTestRule(Object testModule) {
this.testModule = testModule;
}
@Override
public Statement apply(final Statement statement, FrameworkMethod frameworkMethod, final Object testClassInstance) {
@jhansche
jhansche / watch-fds.sh
Created October 28, 2016 20:39
Simple script to monitor the number open file descriptors for an Android application.
#!/bin/sh
# Usage: ./watch-fds.sh <application_id> [delay_secs = 5]
APP_ID=${1:?missing application id}
DELAY=$(( ${2:-5} ))
DEVICE_LIMIT=$(( $(adb shell ulimit -n) ))
WARN_THRESHOLD=$(( ${DEVICE_LIMIT} / 3 ))
echo "Will warn at ${WARN_THRESHOLD}"
@rocboronat
rocboronat / PopularBrowser.java
Last active July 21, 2016 15:58
Use the more popular browser in the user's phone to open a URL
package com.fewlaps.quitnow;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.util.ArrayList;
import java.util.List;
@rocboronat
rocboronat / PermissionGranter.java
Last active December 26, 2022 07:05
Tap the "allow" button while running an Android instrumental test using UIAutomator
package com.fewlaps.android.permissiongranter;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.support.v4.content.ContextCompat;
@jamsinclair
jamsinclair / shrug.md
Last active July 19, 2022 06:34
Markdown Escaped Shrug

¯\_(ツ)_/¯

@dlew
dlew / File.java
Created March 1, 2016 20:46
Automated onError() message generation
public static Action1<Throwable> crashOnError() {
final Throwable checkpoint = new Throwable();
return throwable -> {
StackTraceElement[] stackTrace = checkpoint.getStackTrace();
StackTraceElement element = stackTrace[1]; // First element after `crashOnError()`
String msg = String.format("onError() crash from subscribe() in %s.%s(%s:%s)",
element.getClassName(),
element.getMethodName(),
element.getFileName(),
element.getLineNumber());