Skip to content

Instantly share code, notes, and snippets.

View epau's full-sized avatar

Ed Paulosky epau

View GitHub Profile
@epau
epau / LayoutConfig.swift
Created June 24, 2019 13:22
UICollectionViewCompositionalLayoutConfiguration
var scrollDirection: UICollectionView.ScrollDirection
var interSectionSpacing: CGFloat
var boundarySupplementaryItems: [NSCollectionLayoutBoundarySupplementaryItems]
@epau
epau / zip.swift
Last active May 20, 2019 23:27
Zipping a collection of N collections
// Input: [["A1", "A2", "A3"], ["B1", "B2", "B3", "B4"], ["C1", "C2"]]
// Output: ["A1", "B1", "C1", "A2", "B2", "C2", "A3", "B3", "B4"]
extension Collection where Element: Collection {
func zipped() -> [Element.Element] {
var result: [Element.Element] = []
var iterators = map { $0.makeIterator() }
let total = reduce(0) { $0 + $1.count }
while result.count < total {
for (index, iterator) in iterators.enumerated() {

Keybase proof

I hereby claim:

  • I am epau on github.
  • I am epau (https://keybase.io/epau) on keybase.
  • I have a public key ASAZm-NmA8hUAy1NWRAPOFkgJIRbnAK4QbGgNpXUU4nrOgo

To claim this, I am signing this object:

@epau
epau / MGLCoordinateBounds+Clamp.swift
Created July 31, 2017 20:52
Clamping MGLCoordinateBounds
extension MGLCoordinateBounds {
// Clamps by shifting and maintaing distance aka diff between ne.latitude and sw.latitude will remain the same
mutating func clamp(to bounds: MGLCoordinateBounds) {
// Clamp latitude
let neLatitudeDiff = ne.latitude - bounds.ne.latitude
if neLatitudeDiff > 0 {
ne.latitude = bounds.ne.latitude
sw.latitude = sw.latitude - neLatitudeDiff
} else {
let swLatitudeDiff = bounds.sw.latitude - sw.latitude
@epau
epau / unowned-and-weak.swift
Created July 6, 2017 14:16
When to use unowned vs weak
class Button: UIButton {
var onTap: (() -> ())?
init() {
super.init(frame: .zero)
}
required init?(coder aDecoder: NSCoder) {
super.init(frame: .zero)
- (void)observeNumberOfUnreadMessages
{
LYRQuery *query = [LYRQuery queryWithQueryableClass:[LYRMessage class]];
query.predicate = [LYRPredicate predicateWithProperty:@"isUnread" predicateOperator:LYRPredicateOperatorIsEqualTo value:@(YES)];
LYRQueryController *controller = [self.layerManager.layerClient queryControllerWithQuery:query];
controller.delegate = self;
self.unreadMessagesQueryController = controller;
}
#pragma mark - LYRQueryController Delegate
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"Piccadilly Circus, London, UK"
completionHandler:^(NSArray *placemarks, NSError *error) {
// Convert the CLPlacemark to an MKPlacemark
// Note: There's no error checking for a failed geocode
CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc]
initWithCoordinate:geocodedPlacemark.location.coordinate
addressDictionary:geocodedPlacemark.addressDictionary];
@epau
epau / robot-control.html
Created December 3, 2013 20:41
html code
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8"/>
<title>Robot</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<style>
.btn{width:96px; height:96px;}
.active{background-color: #afe123;}
</style>