Skip to content

Instantly share code, notes, and snippets.

View eoghain's full-sized avatar

Rob Booth eoghain

View GitHub Profile
@eoghain
eoghain / FeatureFlag.swift
Created April 7, 2022 00:02
Feature Flags
import UIKit
/// Struct identifying a Feature Flag that is used to enable/disable access to a feature
///
/// example:
/// ```
/// // Only allow this feature on iPhones in the US if the flag is enabled
/// let featureFlag = FeatureFlag(name: "EnableMyFeature", localeRestrictions: ["en_US"], deviceTypes: [.phone])
/// guard featureFlag.isEnabled else { return }
/// ```
@eoghain
eoghain / SingleItemCarouselFlowLayout.swift
Last active January 7, 2021 23:47
/// Snaps nearest cell to center of collection view
final class SingleItemCarouselFlowLayout: UICollectionViewFlowLayout {
override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
guard let collectionView = collectionView else {
return super.targetContentOffset(forProposedContentOffset: proposedContentOffset, withScrollingVelocity: velocity)
}
var offsetAdjustment: CGFloat = .greatestFiniteMagnitude
@eoghain
eoghain / SwiftUIParallax.swift
Created December 2, 2019 22:40
Swift UI Parallax Playground
import UIKit
import PlaygroundSupport
import SwiftUI
// Requires 2 images author.jpg and header.jpg in the Resources folder to work
struct ContentView: View {
var body: some View {
ScrollView {
ParallaxView()
@eoghain
eoghain / CustomInteractiveAnimationNavigationController.swift
Last active September 21, 2023 07:33
UINavigationController that implements swipe to push/pop in an interactive animation. Just implement the InteractiveNavigation protocol on your ViewControllers you add to the nav stack to get custom transitions. Or implement a single animation and return it instead of the nil's in the UIViewControllerTransitioningDelegate and all transitions wil…
import UIKit
protocol InteractiveNavigation {
var presentAnimation: UIViewControllerAnimatedTransitioning? { get }
var dismissAnimation: UIViewControllerAnimatedTransitioning? { get }
func showNext()
}
enum SwipeDirection: CGFloat, CustomStringConvertible {
@eoghain
eoghain / UIFontExtensions.swift
Last active June 20, 2021 14:29
A UIFont extension in swift to load fonts from within a bundle
import UIKit
public extension UIFont {
class func loadAllFonts(bundleIdentifierString: String) {
registerFontWithFilenameString(filenameString: "icon-font.ttf", bundleIdentifierString: bundleIdentifierString)
// Add more font files here as required
}
static func registerFontWithFilenameString(filenameString: String, bundleIdentifierString: String) {
@eoghain
eoghain / himawari8.py
Last active February 23, 2016 00:44
Download and stitch together images from the Himawari8 satellite and create a movie from them. https://en.wikipedia.org/wiki/Himawari_8
#!/usr/bin/env python
# Easy Combine output movies
# ls -tr himawari8_*.mp4 | perl -ne 'print "file $_"' | ffmpeg -f concat -i - -c copy FullMovie.mp4
# Requirements
# brew install libtiff libjpeg webp little-cms2 ffmpeg
# pip install Pillow
import datetime
@eoghain
eoghain / ViewController.m
Created November 6, 2015 01:47
Countdown ViewController - example of simple countdown view
//
// ViewController.m
// countdown
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIView *container;
@property (strong, nonatomic) IBOutlet UILabel *label1;
@eoghain
eoghain / MapClusterPinView.h
Created October 10, 2015 06:23
UIView that can be used as a map marker on GoogleMaps. marker.icon = [[[MapClusterPinView alloc] initWithCount:12] image];
//
// MapClusterPinView.h
//
// Created by Rob Booth on 10/9/15.
// Copyright © 2015 Rob Booth. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface MapClusterPinView : UIView
@eoghain
eoghain / CircleImageVIew.h
Created October 5, 2015 16:41
Draw Circle Image w/Border - IBDesignable so it's live in IB
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface CircleImageVIew : UIView
@property (assign) IBInspectable BOOL showFrame;
@property (nonatomic, strong) IBInspectable UIImage *image;
@property (nonatomic, strong) IBInspectable UIColor *borderColor;
@property (nonatomic, strong) IBInspectable UIColor *borderStrokeColor;
@eoghain
eoghain / FrameworkProcessing.sh
Last active August 29, 2015 14:24
Script to use in the Build Phases to create frameworks for simulator and device.
################
# Creating usable frameworks:
#
# 1. Install this script in your frameworks Build Phases as the last item
# 2. Build for the simulator
# 3. Archive for device
# 4. Package contents of _Archive directory
#
# Using created framework
#