Skip to content

Instantly share code, notes, and snippets.

@zef
zef / StickyFooterScrollView.swift
Last active December 9, 2022 04:56
A reusable view where you can include content in a scroll view, with a footer that stays on the bottom of the screen until there is enough content to push it down further.
// Created by Zef Houssney on 12/8/22.
//
import SwiftUI
struct StickyFooterScrollView<Content, Footer>: View where Content: View, Footer: View {
let mainView: Content
let footer: Footer
init(@ViewBuilder mainView: () -> Content, @ViewBuilder footer: () -> Footer) {
@zef
zef / CollectionView.swift
Created January 16, 2020 22:50
A layout similar to a CollectionViewFlowLayout, but in SwiftUI.
// Created by Zef Houssney on 1/9/20.
// This takes some inspiration from https://gist.github.com/chriseidhof/3c6ea3fb2102052d1898d8ea27fbee07
// but uses a different approach.
// Instead of trying to calculate the position of each item and placing them manually using calculated coordinates,
// this calculates the amount of space each item wants to take up, then splits the items into rows that should fit
// within the available width.
// Then, the views are distributed into rows, made up of an HStack for each row inside a VStack.
//
// This seems non-conventional, but I was having trouble getting the frame of my top-level view to be respected when returning
// This is a 3d printable tailgate latch rod clip that fits my 1995 Toyota T100.
// intended to be printed as oriented, with the insert pin facing up
// Using dependencies helps keep me sane. Please excuse the inconvenience of installation :)
// https://github.com/revarbat/BOSL/wiki
//
// Installation instructions: https://github.com/revarbat/BOSL/wiki
include <BOSL/constants.scad>
@zef
zef / Puralizable.swift
Last active December 17, 2019 17:50
A simple protocol to enable a collection of Pluralizable objects to return either the singular or the plural, depending on the count of the collection.
protocol Pluralizable {
static var singular: String { get }
// Override with the correct plural, if simply appending an "s" is incorrect
static var plural: String { get }
}
extension Pluralizable {
static var singular: String {
return String(describing: self)
}
@zef
zef / Reusable.swift
Created March 14, 2019 21:17
Reusable cells for iOS
//
// Reusable.swift
//
// Created by Zef Houssney
//
import UIKit
protocol Reusable {
static var reuseIdentifier: String { get }
@zef
zef / gist:10904278
Created April 16, 2014 16:37
Was messing with replacing color in an image with another color. Didn't work that well, mostly saturation and brightness problems
- (UIImage *)imageByShiftingFromColor:(UIColor *)startColor toColor:(UIColor *)endColor
{
CGFloat startHue, startSaturation, startBrightness, startAlpha;
BOOL parsedStartColor = [startColor getHue:&startHue saturation:&startSaturation brightness:&startBrightness alpha:&startAlpha];
NSLog(@"start success: %i hue: %0.2f, saturation: %0.2f, brightness: %0.2f, alpha: %0.2f", parsedStartColor, startHue, startSaturation, startBrightness, startAlpha);
CGFloat endHue, endSaturation, endBrightness, endAlpha;
BOOL parsedEndColor = [endColor getHue:&endHue saturation:&endSaturation brightness:&endBrightness alpha:&endAlpha];
NSLog(@"end success: %i hue: %0.2f, saturation: %0.2f, brightness: %0.2f, alpha: %0.2f", parsedEndColor, endHue, endSaturation, endBrightness, endAlpha);
@zef
zef / keybase.md
Created April 7, 2016 04:14
keybase.md

Keybase proof

I hereby claim:

  • I am zef on github.
  • I am zef (https://keybase.io/zef) on keybase.
  • I have a public key whose fingerprint is F64A 8E5B F886 3060 D810 54AC D97C 988F 6778 C42C

To claim this, I am signing this object:

@zef
zef / value-enumerable.swift
Last active January 21, 2016 14:56
Example of Swift enum with allValues array containing constructors for cases with associated values
protocol ValueEnumerable {
static var allValues: [Any] { get }
}
enum ColorScheme: ValueEnumerable {
typealias SchemeTuple = (name: String, background: UIColor, foreground: UIColor, border: UIColor)
case Light
case Dark
case custom(SchemeTuple)
@zef
zef / check_image_dimensions.rb
Created December 3, 2013 18:39
Prints a list of @2x assets that have odd dimensions. Requires imagemagick and the mini_magick gem.
require 'mini_magick'
root_path = '/Users/zef/Dropbox/code/some_project'
local_path = 'some_project/assets'
path = File.join(root_path, local_path, '**.png')
list = []
Dir.glob(path).each do |file|
@zef
zef / NSURL+QueryDictionary.swift
Created October 16, 2015 17:14
Swift NSURL extension to turn the query into a dictionary
extension NSURL {
var queryDictionary: [String: String] {
guard let components = NSURLComponents(string: absoluteString), items = components.queryItems else { return [:] }
return items.reduce([:]) { dictionary, item in
var dictionary = dictionary
dictionary[item.name] = item.value
return dictionary
}
}