Skip to content

Instantly share code, notes, and snippets.

@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}"
#!/bin/sh -e
adb start-server || adb start-server
echo "adb is started"
date
while [ "$(adb shell echo 1)" ]; do sleep 5; done
date
echo "adb is broken, restarting:"
Joes-MacBook-Pro-2:~ jhansche$ while [ true ]; do time bin/monitor-adb ; done
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
adb is started
Thu Aug 18 19:15:54 EDT 2016
error: no devices/emulators found
Thu Aug 18 19:33:18 EDT 2016
adb is broken, restarting:
error: protocol fault (couldn't read status): Connection reset by peer
* daemon not running. starting it now on port 5037 *
@jhansche
jhansche / MoPubHost.java
Created June 8, 2015 16:16
Workaround for mopub/mopub-android-sdk#171
// Replace the MoPubViewFactory so we can return instances of MoPubView2 instead.
MoPubViewFactory.setInstance(new MoPubViewFactory() {
@Override
protected MoPubView internalCreate(final Context context) {
return new MoPubView2(context);
}
});
@jhansche
jhansche / getimagesizefromstring.php
Created September 19, 2012 18:55
getimagesizefromstring() replacement
function getmimetypefromstring($data)
{
// Most image types can be determined in 25 bytes or less.
$data = substr($data, 0, 32);
$uri = 'data://application/octet-stream;base64,' . base64_encode($data);
return exif_imagetype($uri);
}