Skip to content

Instantly share code, notes, and snippets.

View froggomad's full-sized avatar

Kenny Dubroff (froggomad) froggomad

View GitHub Profile
@froggomad
froggomad / starId.swift
Last active June 4, 2020 15:37
firstTwoChars = * and lastTwoChars = *
// Created by Kenny Dubroff on 10/14/18.
var str = "p123869"
var chars = Array(str)
//first 2 characters are always 0 and 1
chars[0] = "*"
chars [1] = "*"
///endIndex is always one greater than the last index
import Foundation
protocol Fightable {
var hitPoints: Int { get set }
var damageDone: Int { get set }
var damageAbsorbed: Int { get set }
}
protocol IDAble {
var id: Int { get }
@froggomad
froggomad / style.css
Last active September 16, 2020 01:53
.note {
max-width: 600px;
border-radius: 8px;
background-color: lightgray;
padding: 4px;
margin: 8px;
}
pre {
background: black;
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
//connect to db func
if(!function_exists('connectToDb')) {
function connectToDb($host, $username, $password, $db_name) {
$link;
try {
$link = new mysqli($host, $username, $password, $db_name);
$link->set_charset("utf8mb4");
} catch(Exception $e) {
import SwiftUI
struct GridView: View {
@StateObject var viewModel = FrameworkGridViewModel()
let frameworks = MockData.frameworks
init() {
UITableView.appearance().backgroundView = BackgroundView.UIKitBackgroundView()
@froggomad
froggomad / NetworkMonitor.swift
Last active January 3, 2021 19:21
Network Monitor with UIDelegate - notify when connection drops
// Dependency: rwbutler/Connectivity https://github.com/rwbutler/Connectivity
import Foundation
import Connectivity
// MARK: - Delegate Protcol -
protocol NetworkMonitorDelegate: class {
func updateUser(connected: Bool)
}
@froggomad
froggomad / sirenLights.py
Created January 15, 2021 06:57
Raspberry pi - Flash 2 LEDs on and off triggered by a button press (button is wired with pulldown resistor)
# Write your code here :-)
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# Define LEDs
GREEN_LED=14
RED_LED=4
# Setup LEDs
@froggomad
froggomad / BorderView.swift
Last active February 13, 2021 22:36
BorderView protocol
// blueprint
/// This protocol is constrained to types that conform to UIView - which is most UI elements
protocol BorderView: UIView {
func addBorder(borderWidth: CGFloat, borderColor: CGColor)
}
// default implementation (optional)
extension BorderView {
func addBorder(borderWidth: CGFloat = 1, borderColor: CGColor = UIColor.lightGray.cgColor) {
self.layer.borderWidth = borderWidth
@froggomad
froggomad / ExampleTableViewController.swift
Created February 20, 2021 03:36
edit rows only when vc is in editing mode
// ExampleTableViewController.swift
// Nestor
//
// Created by Kenneth Dubroff on 2/19/21.
//
import UIKit
class ExampleTableViewController: UITableViewController {
@froggomad
froggomad / UIViewController+alert.swift
Created March 4, 2021 15:48
Present alerts in extension
import UIKit
extension UIViewController {
/// Show an alert with a title, message, and OK button
/// - Parameters:
/// - title: The Alert's Title
/// - message: The Alert's Message
func presentAlert(title: String, message: String, completion: @escaping (UIAlertAction) -> Void = {_ in }) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)