This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max="$1" | |
date | |
echo "url: $2 | |
rate: $max calls / second | |
additional header: $3" | |
START=$(date +%s); | |
get () { | |
curl -s -v --header "$2" "$1" 2>&1 | tr '\r\n' '\\n' | awk -v date="$(date +'%r')" '{print $0"\n-----", date}' >> /tmp/perf-test.log | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create an ImageView with a set height and a scalable width that is scaled based on | |
* a provided image. | |
* Returns a null ImageView if image was not found. | |
*/ | |
private ImageView getScaledImageView(String imagePath) { | |
int desiredHeightPx = 75; | |
ImageView iv = null; | |
File imageFile = new File(imagePath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void encryptFile(SecretKeySpec key, IvParameterSpec iv, String inputFilePath, String outputFilePath) { | |
try { | |
Cipher encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); | |
encryptCipher.init(Cipher.ENCRYPT_MODE, key, iv); | |
File inFile = new File(inputFilePath); | |
File outFile = new File(outputFilePath); | |
Files.touch(outFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.view.ViewTreeObserver; | |
import android.widget.LinearLayout; | |
/** | |
* A simple progress bar for Android. | |
* | |
* Usage: | |
* - initialize with a LinearLayout of suitable size, the number of progress events you expect, and the desired bar colour | |
* - call increase(x) to increase the progress bar by x progress events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.net.ConnectivityManager; | |
import android.net.NetworkInfo; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.os.Message; | |
/** | |
* Checks for a network connection at intervals until connection is found, or timeout has been reached. | |
* Result is sent via a message containing {"connected":boolean} sent to passed-in Handler. | |
* Log output is sent via a message containing {"log":string} sent to passed-in Handler. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static <T> List<List<T>> batchList(List<T> inputList, final int maxSize) { | |
List<List<T>> sublists = new ArrayList<>(); | |
final int size = inputList.size(); | |
for (int i = 0; i < size; i += maxSize) { | |
// Math.min... size will be smaller than i + maxSize for the last batch (unless perfectly divisible), | |
// including the first batch if size is smaller than max size | |
sublists.add(new ArrayList<>(inputList.subList(i, Math.min(size, i + maxSize)))); | |
} |