Skip to content

Instantly share code, notes, and snippets.

@rajohns08
rajohns08 / ActionAlert.java
Last active May 5, 2016 03:45
Android - ActionAlert dialog for yes/no type of dialog where the user is asked to confirm some action or cancel
public class ActionAlert {
public static void show(Context context, String title, String message, String actionText, DialogInterface.OnClickListener actionCallback) {
new AlertDialog.Builder(context)
.setTitle(title)
.setMessage(message)
.setPositiveButton(actionText, actionCallback)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@rajohns08
rajohns08 / docker.txt
Last active December 30, 2022 00:28
Docker - Popular Docker commands
# Show running containers
docker container ls
# Show all containers
docker container ls -a
# Create container from image
# -d run as daemon in background
# -p say what port to map in container
# --name give container a name
@rajohns08
rajohns08 / Map.java
Created November 17, 2015 14:15
Android / Maps v2 - United States of America (USA) map coordinates. Placing map camera at USA.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(38, 263), 3.0f));
@rajohns08
rajohns08 / LoadingButton.swift
Created November 13, 2015 04:55
iOS / Swift - UIButton subclass for showing loading spinner aka activity indicator inside button
import UIKit
class LoadingButton: UIButton {
var originalButtonText: String?
var activityIndicator: UIActivityIndicatorView!
func showLoading() {
originalButtonText = self.titleLabel?.text
self.setTitle("", forState: UIControlState.Normal)
@rajohns08
rajohns08 / BaseTextField.swift
Created November 12, 2015 04:41
iOS / Swift - UITextField subclass for handling dismissing when return key tapped, padding for placeholder text, turning off auto correction, and enabling clear button
import UIKit
@IBDesignable
class BaseTextField: UITextField {
let leftPadding: CGFloat = 20
override func awakeFromNib() {
self.delegate = self
self.returnKeyType = UIReturnKeyType.Done
@rajohns08
rajohns08 / HighlightButton.swift
Last active September 29, 2021 14:59
iOS / Swift - UIButton subclass to highlight when tapped
import UIKit
class HighlightButton: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setTitleColor(<#button text color when tapped#>, forState: .Highlighted)
}
override init(frame: CGRect) {
@rajohns08
rajohns08 / BorderButton.swift
Last active November 14, 2017 09:00
iOS / Swift - IBDesignable and IBInspectable working example for a UIButton subclass with a border
import UIKit
@IBDesignable
class BorderButton: UIButton {
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
@rajohns08
rajohns08 / OkAlert.swift
Last active July 8, 2016 00:31
iOS / Swift - Helper class for showing a simple dialog
import UIKit
class OkAlert {
class func show(inViewController viewController: UIViewController, title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
viewController.presentViewController(alert, animated: true, completion: nil)
}
@rajohns08
rajohns08 / BaseViewController.swift
Created November 9, 2015 02:51
iOS / Swift - A base view controller for dismissing keyboard and applying color theme
import UIKit
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
listenForTapsOnViewToDismissKeyboard()
applyGlobalColorTheme()
}
@rajohns08
rajohns08 / README.md
Last active June 17, 2016 13:41
Android - Spinner subclass to make populating easier

Usage

List of Strings

List<String> items = new ArrayList<>();
items.add("your stuff");
items.add("more stuff");
simpleSpinner.populate(this, items);