Skip to content

Instantly share code, notes, and snippets.

View AdrianBinDC's full-sized avatar

Adrian AdrianBinDC

  • DC Metro Area
View GitHub Profile

Keybase proof

I hereby claim:

  • I am tiwoc on github.
  • I am dseither (https://keybase.io/dseither) on keybase.
  • I have a public key ASCYr5gKU4ekiCvicb4kcVSKr_ZxiSUC3Qo9Vf8w6BPpuQo

To claim this, I am signing this object:

@marciok
marciok / dijkstra.swift
Created June 22, 2016 21:15
Dijkstra's algorithm in Swift 3
/**
Dijkstra's algorithm in Swift 3
The idea is to create a more protocol oriented implementation.
Note: It could use some optimizations, if you wish to use in production.
*/
import Foundation
@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
@iwasrobbed
iwasrobbed / gist:5528897
Last active June 5, 2020 20:34
UICollectionView w/ NSFetchedResultsController & NSBlockOperation. Idea originated from Blake Watters (https://github.com/AshFurrow/UICollectionView-NSFetchedResultsController/issues/13)
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
self.shouldReloadCollectionView = NO;
self.blockOperation = [[NSBlockOperation alloc] init];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
__weak UICollectionView *collectionView = self.collectionView;
import UIKit
extension UIImage {
// colorize image with given tint color
// this is similar to Photoshop's "Color" layer blend mode
// this is perfect for non-greyscale source images, and images that have both highlights and shadows that should be preserved
// white will stay white and black will stay black as the lightness of the image is preserved
func tint(tintColor: UIColor) -> UIImage {
@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)
@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
import UIKit
extension UIImage {
// colorize image with given tint color
// this is similar to Photoshop's "Color" layer blend mode
// this is perfect for non-greyscale source images, and images that have both highlights and shadows that should be preserved
// white will stay white and black will stay black as the lightness of the image is preserved
func tint(tintColor: UIColor) -> UIImage {
@audiocommander
audiocommander / centerMapViewFromBBox.swift
Last active October 26, 2023 13:48 — forked from aaronpk/gist:6693579
Center a MKMapView given a GeoJSON bounding box
// prepare bbox
struct BoundingBox {
// latitudes range from -90 .. +90
// longitudes range from -180 .. +180
var latmin = 90.0
var latmax = -90.0
var lngmin = 180.0
var lngmax = -180.0
}
var bbox = BoundingBox()
@dionc
dionc / MapKitExtensions.swift
Last active January 27, 2024 00:54
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