Skip to content

Instantly share code, notes, and snippets.

View RRCummins's full-sized avatar

Ryan Cummins RRCummins

View GitHub Profile
@swiftui-lab
swiftui-lab / grid-trainer.swift
Last active October 21, 2024 15:24
A grid trainer for Grid views
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: this learning tool is designed to showcase the different
// Grid and GridRow view options, added in SwiftUI 2022. It is part of the
// blog article: https://swiftui-lab.com/eager-grids
//
import SwiftUI
import UniformTypeIdentifiers
// The root view of the application
struct ContentView: View {
@yannxou
yannxou / ForegroundTextColor.swift
Created December 23, 2020 09:55
Foreground text color based on background color #SwiftUI
// Taken from Apple's App Dev Training: https://developer.apple.com/tutorials/app-dev-training/
/// This color is either black or white, whichever is more accessible when viewed against the scrum color.
var accessibleFontColor: Color {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: nil)
return isLightColor(red: red, green: green, blue: blue) ? .black : .white
}
@douglashill
douglashill / KeyboardScrollView.swift
Last active May 6, 2021 00:47
A UIScrollView subclass that allows scrolling using a hardware keyboard like NSScrollView. Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end.
// Douglas Hill, November 2019
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit
import UIKit
/// A scroll view that allows scrolling using a hardware keyboard like `NSScrollView`.
/// Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end.
/// Limitations:
/// - Paging scroll views (isPagingEnabled = true) are not supported yet.
/// - The scroll view must become its own delegate so setting the delegate is not supported yet.
@bradtraversy
bradtraversy / ssh.md
Last active April 30, 2025 03:35
SSH & DevOps Crash Course Snippets

SSH Cheat Sheet

This sheet goes along with this SSH YouTube tutorial

Login via SSH with password (LOCAL SERVER)

$ ssh [email protected]

Create folder, file, install Apache (Just messing around)

$ mkdir test

$ cd test

@dermotos
dermotos / MyView.swift
Created February 1, 2018 05:29
UIView extension to quickly add and fit or center a subview inside a superview, using constraints
class MyView : UIView {
func buildMyView() {
var indicatorView :UIActivityIndicatorView!
let indicatorSize : CGFloat = 120
loadingIndicator = UIView(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: indicatorSize, height: indicatorSize)))
loadingIndicator.backgroundColor = UIColor.darkGray.withAlphaComponent(0.7)
loadingIndicator.layer.cornerRadius = 10.0
indicatorView = UIActivityIndicatorView(activityIndicatorStyle: .white)
indicatorView.hidesWhenStopped = false
@williamhqs
williamhqs / GradientLine.swift
Last active December 12, 2019 22:08
CoreGraphics draw a line with gradient and lineCap
class GradientLineView: UIView {
override func draw(_ rect: CGRect) {
if let context = UIGraphicsGetCurrentContext() {
let startPoint1 = CGPoint(x: 20, y: rect.height/2)
let endPoint1 = CGPoint(x: rect.width-120, y: rect.height/2)
context.setLineWidth(15)
context.move(to: startPoint1)
context.addLine(to: endPoint1)
context.setLineCap(.round)
extension UIImage {
public func imageRotatedByDegrees(degrees: CGFloat) -> UIImage {
let radiansToDegrees: (CGFloat) -> CGFloat = {
return $0 * (180.0 / CGFloat(M_PI))
}
let degreesToRadians: (CGFloat) -> CGFloat = {
return $0 / (180.0 * CGFloat(M_PI))
}
// calculate the size of the rotated view's containing box for our drawing space
if {
something();
// } else {
// somethingElse();
}
extension Int {
func bottlesOfBeer() {
let bottles = "\(self) bottle" + (self == 1 ? "" : "s")
let what = " of beer on the wall"
println("\(bottles + what), \(bottles) of beer.")
print("Take one down, pass it around, ")
if self == 1 {
println("no more bottles\(what).")
@mathewa6
mathewa6 / Algorithms.swift
Last active August 11, 2018 17:33
A review of basic algorithms in Swift, started after reading http://bost.ocks.org/mike/algorithms/
//A review thanks to http://bost.ocks.org/mike/algorithms/
import Foundation
func exchange<T>(inout elementsIn array: [T], i: Int, j: Int)
{
let temp: T = array[i]
array[i] = array[j]
array[j] = temp
}