Skip to content

Instantly share code, notes, and snippets.

View AdrianBinDC's full-sized avatar

Adrian AdrianBinDC

  • DC Metro Area
View GitHub Profile
@AdrianBinDC
AdrianBinDC / Unofficial-APOD.md
Last active July 3, 2018 16:03
Unofficial APOD

Unofficial APOD

Unofficial APOD utilizes Alamofire to request data from NASA's APOD servers. The response data is returned in JSON format. Unofficial APOD utilizes structs conforming to Swift's Codable protocol to parse the JSON returns and persists the data in Core Data. Prior to requesting information from NASA's servers, Unofficial APOD first checks to see if it has already retrieved the data before making a network request.

NASA returns a JSON with text data about the image, but no binary data is returned. Unofficial APOD utilizes AlamofireImage to download the most recent 60 days' worth of non-copywritten images on a background thread and persists them locally to speed up performance for the user.

Copywritten images are not stored on the device. So the user doesn't see an empty screen, the UICircularProgressRing framework is configured to display the status of the image download.

Giv

@AdrianBinDC
AdrianBinDC / ConvertDistances.md
Last active December 15, 2023 02:12
Convert Distances in Swift using Measurement

Distance conversion in Swift

As of iOS 10, the Measurement class was introduced, which obviates the need lookup values and create constants to convert values. Here is a simple extension to convert distances.

extension Double {
  func convert(from originalUnit: UnitLength, to convertedUnit: UnitLength) -> Double {
    return Measurement(value: self, unit: originalUnit).converted(to: convertedUnit).value
  }
}
@AdrianBinDC
AdrianBinDC / gist:a8da4748181d86203689bc369fa01ed2
Last active July 5, 2018 14:09
Set MKMapRegion to display a specific zoom scale

Set Zoom Scale on Map Region in Swift

MKCoordinateRegionMakeWithDistance can be used to make a region with a specified distance (in meters).

Here is the method signature:

func MKCoordinateRegionMakeWithDistance(_ centerCoordinate: CLLocationCoordinate2D, 
                                        _ latitudinalMeters: CLLocationDistance, 
                                        _ longitudinalMeters: CLLocationDistance) -> MKCoordinateRegion

Use an extension to get your desired distance and convert it into meters.

@AdrianBinDC
AdrianBinDC / MapRegionUtility.swift
Last active May 19, 2023 01:13
Generate a MKCoordinateRegions for continents and major oceans
//
// MapRegionUtility.swift
// QuakeData
//
// Created by Adrian Bolinger on 7/9/18.
// Copyright © 2018 Adrian Bolinger.
//
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@AdrianBinDC
AdrianBinDC / ConnectivityUtil.swift
Last active July 28, 2018 03:17
Connectivity Utility Implementation using Reachability
//
// ConnectivityUtility.swift
//
// Created by Adrian Bolinger on 7/10/18.
// Copyright © 2018 Adrian Bolinger. All rights reserved.
//
import UIKit
import Reachability
@AdrianBinDC
AdrianBinDC / ConvertDistances.swift
Created July 11, 2018 03:07
Convert distances from one unit of measurement to another
extension Double {
func convert(from originalUnit: UnitLength, to convertedUnit: UnitLength) -> Double {
return Measurement(value: self, unit: originalUnit).converted(to: convertedUnit).value
}
}
/*
let miles = 26.2
let meters = miles.convert(from: .miles, to: .meters)
*/
@AdrianBinDC
AdrianBinDC / new-in-4-2.md
Created August 5, 2018 00:30
New in Swift 4.2

New in Swift 4.2

Summary from HackingWithSwift.com

CaseIterable

The CaseIterable protocol provides an allCases method that turns all of your cases into an array.

enum Pasta: String, CaseIterable {

case canneloni = "Cannelloni pasta"

@AdrianBinDC
AdrianBinDC / ChatEngine Sketch
Created June 3, 2020 13:23
Stub implementation for ChatEngine for Pursuit Students
import UIKit
/*
This is a high-level physics for poets sketch of an implementation for
sending and receiving messages. YOU'LL NEED TO REFINE IT.
If you want to implment encryption, I'd use a framework like CryptoKit,
or some well-known, public framework w/ a lotta stars, recent commits,
and not a lot of issues on the GitHub page.

Issues

CocoaPod Bloat

  • There's a ton of CocoaPods in the project. Do you need them all?
    • I see two types of cocoapods for image caching

Lack of Tests

  • there are only tests for one class and they don't pass
  • I should be able to download the repo, install the cocoapods and run the tests and they should all pass without having to jump through special hoops.me.com

Review

S3 and IAM Summary

  • IAM consists of the following
    • Users
    • Groups
    • Roles
    • Policies
      • Policies are in a JSON file