Skip to content

Instantly share code, notes, and snippets.

@rajohns08
rajohns08 / UITextFieldTestingTests.swift
Last active April 8, 2021 22:50
iOS / Swift - Unit test for verifying text field limit not exceeded
func testTextFieldLimit() {
// Set up view before interacting with the text field
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType))
let vc = storyboard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
vc.loadView()
// Test maximum number of allowable characters
let atTheLimitString = String(count: maxNumCharacters, repeatedValue: Character("a"))
let atTheLimitResult = vc.textField(vc.textField, shouldChangeCharactersInRange: NSRange(location: 0, length: 0), replacementString: atTheLimitString)
XCTAssertTrue(atTheLimitResult, "The text field should allow \(maxNumCharacters) characters")
@rajohns08
rajohns08 / states.xml
Last active November 3, 2015 13:20
Android - US states string array
<string-array name="state_array">
<item>AL</item>
<item>AK</item>
<item>AZ</item>
<item>AR</item>
<item>CA</item>
<item>CO</item>
<item>CT</item>
<item>DE</item>
<item>FL</item>
@rajohns08
rajohns08 / months.xml
Last active August 10, 2022 07:15
Android - string array for months
<string-array name="months_array">
<item>January</item>
<item>February</item>
<item>March</item>
<item>April</item>
<item>May</item>
<item>June</item>
<item>July</item>
<item>August</item>
<item>September</item>
@rajohns08
rajohns08 / days.xml
Last active November 3, 2015 13:19
Android - string array for days in month
<string-array name="days_array">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
@rajohns08
rajohns08 / LogcatRemoveTag.txt
Last active November 3, 2015 13:22
Sublime / Android - Remove the tag portion of logcat output
.*mytagname﹕
@rajohns08
rajohns08 / OkAlert.java
Last active November 3, 2015 13:18
Android - Simple confirmation dialog with only one 'Ok' button
package com.rentalgeek.android.utils;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
/**
* Created by rajohns on 9/19/15.
*
*/
@rajohns08
rajohns08 / adb.txt
Last active December 3, 2015 04:31
Android / Emulator - Uninstall and install apk via command line using adb tool from android sdk
// Get list of available emulators
$ emulator -list-avds
// Start an emulator
$ emulator -avd <emulator-name> -scale 0.33
// Install app on running emulator
$ adb shell
$ pm list packages | grep "something in your package name" // This lists package names for all apps currently installed on device that adb is connected to
$ exit
@rajohns08
rajohns08 / layout_fullscreen_image.xml
Last active November 3, 2015 13:16
Android - For showing a full screen image for something like a detail photo view of photo in a gallery
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@rajohns08
rajohns08 / background_image_layout.xml
Last active November 3, 2015 13:16
Android - Skeleton layout for using a background image for a layout while maintaining the image's aspect ratio
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/background_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
@rajohns08
rajohns08 / ssn.java
Last active November 30, 2021 08:50
Android - Add hyphens to an SSN EditText field while the user is typing
ssnEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// if user is typing string one character at a time
if (count == 1) {