Skip to content

Instantly share code, notes, and snippets.

View AdrianBinDC's full-sized avatar

Adrian AdrianBinDC

  • DC Metro Area
View GitHub Profile
@cplpearce
cplpearce / country_codes
Created March 23, 2022 21:54
Country Codes with Bounding Box
{
"aw": {
"name": "Aruba",
"alpha-2": "AW",
"alpha-3": "ABW",
"country-code": "533",
"iso_3166-2": "ISO 3166-2:AW",
"region": "Americas",
"sub-region": "Latin America and the Caribbean",
"intermediate-region": "Caribbean",
[
"Africa/Abidjan",
"Africa/Accra",
"Africa/Addis_Ababa",
"Africa/Algiers",
"Africa/Asmara",
"Africa/Bamako",
"Africa/Bangui",
"Africa/Banjul",
"Africa/Bissau",
import PlaygroundSupport
import Foundation
import Combine
// MARK: - Network Controller
protocol NetworkControllerProtocol: class {
typealias Headers = [String: Any]
func get<T>(type: T.Type,
url: URL,
@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
@yossan
yossan / calculate_bearing.swift
Created May 15, 2018 14:26
Calculates bearing between two points
import Foundation
import CoreLocation
/*
θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )
where φ1,λ1 is the start point, φ2,λ2 the end point (Δλ is the difference in longitude)
*/
func calculateBearing(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D) -> Double {
let x1 = from.longitude * (Double.pi / 180.0)
@dionc
dionc / MapKitExtensions.swift
Last active September 21, 2024 10:17
Create an MKCoordinateRegion from an array of coordinates. Safely handles coordinates that cross the 180th meridian.
import MapKit
extension MKCoordinateRegion {
init?(coordinates: [CLLocationCoordinate2D]) {
// first create a region centered around the prime meridian
let primeRegion = MKCoordinateRegion.region(for: coordinates, transform: { $0 }, inverseTransform: { $0 })
// next create a region centered around the 180th meridian
@adamcichy
adamcichy / ImageDarkness.swift
Created March 15, 2017 15:28
Determine if a UIImage is generally dark or generally light in Swift 3
extension CGImage {
var isDark: Bool {
get {
guard let imageData = self.dataProvider?.data else { return false }
guard let ptr = CFDataGetBytePtr(imageData) else { return false }
let length = CFDataGetLength(imageData)
let threshold = Int(Double(self.width * self.height) * 0.45)
var darkPixels = 0
for i in stride(from: 0, to: length, by: 4) {
let r = ptr[i]
@kharrison
kharrison / CoreDataController.swift
Last active January 31, 2023 22:36
Swift wrapper for NSPersistentContainer - Easy Core Data Setup with iOS 10
//
// CoreDataController.swift
//
// Created by Keith Harrison http://useyourloaf.com
// Copyright (c) 2017 Keith Harrison. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright
@patpohler
patpohler / Big List of Real Estate APIs.md
Last active November 14, 2024 00:20
Evolving list of Real Estate APIs by Category

Big List of Real Estate APIs

Listings / Property Data

####Rets Rabbit http://www.retsrabbit.com

Rets Rabbit removes the nightmare of importing thousands of real estate listings and photos from RETS or ListHub and gives you an easy to use import and Web API server so you can focus on building your listing search powered website or app.

@michaelevensen
michaelevensen / PagingCollectionViewController.swift
Last active April 10, 2024 08:46
An example of perfectly paging horizontal UICollectionViewController with overflowing cells. Works great with Storyboard — no need to set any specific attributes, just add this Class to the Controller and set your desired size for the cells like you would normally.
import UIKit
private let reuseIdentifier = "Cell"
class CollectionViewController: UICollectionViewController {
/* Custom scrollView for paging */
let pagingScrollView = UIScrollView()
/* Return item size */