Skip to content

Instantly share code, notes, and snippets.

View jimbrayrcp's full-sized avatar
😀

Jim Bray jimbrayrcp

😀
  • San Antonio, Texas
View GitHub Profile
@jimbrayrcp
jimbrayrcp / Alert .alert.swift
Created May 6, 2020 16:10
Swift 5: iOS: 13.1 Insert into any method for an alert
let alertTitle = "Test"
let alertMessage = "Test Message"
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { action in
// Add Actions to this closure
print("Test Response")
}))
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
self.present(alert, animated: true)
@jimbrayrcp
jimbrayrcp / Swipe Trailing (Left Swipe).swift
Created May 6, 2020 16:19
Swift 5: iOS: 13.1 - tableView Swipe Left Delete Action (or any function you want to add) Uses system images
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .normal, title: "Delete", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
// *** add the object you want to delete here ***
// object.delete
success(true)
})
deleteAction.backgroundColor = .red
deleteAction.image = UIImage(systemName: "trash.fill")
deleteAction.backgroundColor = .green
@jimbrayrcp
jimbrayrcp / TableView Separater Height.swift
Created May 7, 2020 22:39
Increases the separator size between cells by adding a border. Also, corner radius can be removed or added if desired.
let tableCellBGClight: UIColor = systemBlue
// ****** cellForRowAt ******
cell.layer.masksToBounds = true
cell.layer.cornerRadius = 10
cell.layer.borderWidth = 2
cell.layer.shadowOffset = CGSize(width: -1, height: 1)
@jimbrayrcp
jimbrayrcp / Notification - Observer.swift
Last active May 9, 2020 13:51
Swift 5: iOS: 13.1 Runs a script in another viewController: in this gists example, you can reload data in a TableView from a different ViewController
// --------------- VIEW CONTROLLER 1 -----------------------
// MARK: NOTIFICATION
extension Notification.Name {
static let reload = Notification.Name("reload")
}
// MARK: CALLER
NotificationCenter.default.post(name: .reload, object: nil)
// --------------- VIEW CONTROLLER 2 -----------------------
@jimbrayrcp
jimbrayrcp / Transparent Navigation Bar.swift
Last active July 11, 2023 01:52
Swift 5: iOS: 13.1 removes the navigation bar on a per-viewcontroller basis. Use this method if you want to show full screen image with no navigation bar obscuring your view. Title and Prompt can be added if desired
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Provide a clear background for the navigaion bar
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.isTranslucent = true
}
override func viewWillDisappear(_ animated: Bool) {
@jimbrayrcp
jimbrayrcp / Text Field Character Count.swift
Created June 10, 2020 19:18
For Swift UI: a simple text field character counter with return value into another text field.
import SwiftUI
import Combine
class TextCountMgr: ObservableObject {
@Published var counted = "0"
@Published var text = "" {
didSet {
counted = String(text.count)
}
@jimbrayrcp
jimbrayrcp / main.py
Created April 16, 2021 00:28
return system info from pycharm
import sys
import os
import pkg_resources
from pprint import pprint
pprint({
'sys.version_info': sys.version_info,
'sys.prefix': sys.prefix,
'sys.path': sys.path,
@jimbrayrcp
jimbrayrcp / Dictionary & List Comprehension (pandas).py
Created April 21, 2021 21:01
pandas library, python 3.9, using the following format : dictionary_comprehension = {NEW_KEY: NEW_VALUE for (INDEX, ROW) in DATA.iterrows()} list_comprehension = [NEW_ITEM for ITEM in LIST]
# pandas library,
# python 3.9,
# using the following format :
# dictionary_comprehension = {NEW_KEY: NEW_VALUE for (INDEX, ROW) in DATA.iterrows()}
# list_comprehension = [NEW_ITEM for ITEM in LIST]
import pandas
new_dict = {
'letter': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
@jimbrayrcp
jimbrayrcp / Find Matching List Value in a dictionary.py
Created April 21, 2021 21:01
Find a matching value in a dictionary from values found in a list you can choose to match on the key or the value with the conditional test :: Python3.9
# COMBINING DICTIONARY AND LIST COMPREHENSION
# python 3.9,
# Find a matching value in a dictionary from values found in a list.
# you can choose to match on the key or the value with the conditional test
# depending the type of dictionary
a_list = [1, 2, 3]
b_dict = {1: "Bill", 2: "Joe", 3: "Oscar", 4: "Paul", 5: "Sally"}
new_dict = dict((key, value) for key, value in b_dict.items() if key in a_list)
@jimbrayrcp
jimbrayrcp / Find Matching Value from two lists.py
Created April 21, 2021 21:01
Python List Compensation to compare single list of numbers in two text files extracting the matching numbers into a single list
# # PYTHON LIST COMPENSATION
# compare single list of numbers
# in two text files extracting the matching numbers into a single list
# NOTE: in file1 & file2 the numbers are a single column in each list.
with open('file1.txt') as f:
file1 = [int(n) for n in f]