Skip to content

Instantly share code, notes, and snippets.

View davelyon's full-sized avatar

Dave Lyon davelyon

View GitHub Profile
@davelyon
davelyon / section-delete-bug.swift
Created April 27, 2020 21:26
Demonstrates a weird bug with SwiftUI where a Section with a `isEnabled` false will allow swipe-to-delete, but not manual deletion where it should prevent both.
import SwiftUI
struct ItemView: View {
@ObservedObject var collection: ItemCollection
@ObservedObject var item: Item
var body: some View {
HStack(alignment: .firstTextBaseline) {
Text("Item: ")
Text(item.value)
@davelyon
davelyon / autolayout-demo.swift
Created August 25, 2016 03:23
AutoLayout animated expansion demo
import UIKit
import PlaygroundSupport
@objc class ViewExpander: NSObject {
var viewToChange: UIView
var heightConstraint: NSLayoutConstraint
init(viewToChange: UIView, heightConstraint: NSLayoutConstraint) {
self.viewToChange = viewToChange
self.heightConstraint = heightConstraint
@davelyon
davelyon / NSLayoutConstraint+Priority.swift
Created August 22, 2016 18:13
NSLayoutConstraint+Priority.swift
extension NSLayoutConstraint {
func withPriority(_ p: UILayoutPriority) -> Self {
self.priority = p
return self
}
}
@davelyon
davelyon / NSLayoutConstraints+visualGroup.swift
Created January 22, 2015 19:54
Swift helpers for multiple visual constraints
extension NSLayoutConstraint {
public class func visualConstraintsWithMetrics(metrics: [String : CGFloat], views: [String : UIView], options: NSLayoutFormatOptions = nil, strings: String...) -> [NSLayoutConstraint] {
return map(strings, { string in
return NSLayoutConstraint.constraintsWithVisualFormat(string, options: options, metrics: metrics, views: views) as [NSLayoutConstraint]
}).reduce([], +)
}
public class func visualConstraintsWithViews(views: [String : UIView], options: NSLayoutFormatOptions = nil, strings: String...) -> [NSLayoutConstraint] {
return map(strings, { string in
@davelyon
davelyon / iOSFonts.txt
Created December 16, 2014 23:45
iOS Font Equivalents
UIFontTextStyleHeadline
font-family: ".HelveticaNeueInterface-MediumP4"
font-weight: bold
font-style: normal
font-size: 17.00pt
UIFontTextStyleBody
font-family: ".HelveticaNeueInterface-Regular"
font-weight: normal
font-style: normal
font-size: 17.00pt
colorscheme railscasts
set number
if !exists('g:rails_projections')
let g:rails_projections = {}
endif
call extend(g:rails_projections, {
\ "app/domain/*.rb": {
\ "command": "domain",
@davelyon
davelyon / .ctags
Created October 2, 2013 19:14
Ctags dotfile
--regex-ruby=/(^|[:;])[ \t]*([A-Z][[:alnum:]_]+) *=/\2/c,class,constant/
--regex-ruby=/(^|;)[ \t]*(has_many|belongs_to|has_one|has_and_belongs_to_many)\(? *:([[:alnum:]_]+)/\3/f,function,association/
--regex-ruby=/(^|;)[ \t]*(named_)?scope\(? *:([[:alnum:]_]+)/\3/f,function,named_scope/
--regex-ruby=/(^|;)[ \t]*expose\(? *:([[:alnum:]_]+)/\2/f,function,exposure/
--regex-ruby=/(^|;)[ \t]*event\(? *:([[:alnum:]_]+)/\2/f,function,aasm_event/
--regex-ruby=/(^|;)[ \t]*event\(? *:([[:alnum:]_]+)/\2!/f,function,aasm_event/
@davelyon
davelyon / gist:5405303
Created April 17, 2013 15:35
Always nice to have in your .gitconfig
[branch]
autosetuprebase = always
[color]
ui = auto
[push]
default = tracking
[alias]
st = status
ci = commit
co = checkout
cp = cherry-pick
put = push origin HEAD
fixup = !sh -c 'git commit -m \"fixup! $(git log -1 --format='\\''%s'\\'' $@)\"' -
squash = !sh -c 'git commit -m \"squash! $(git log -1 --format='\\''%s'\\'' $@)\"' -
ri = rebase --interactive
br = branch
class ApplicationController < ActionController::Base
def self.present as, from, klass
if from.to_s.singularize == from.to_s
expose(as) { klass.new send(from) }
else
expose(as) { send(from).map { |orig| klass.new(orig) } }
end
end
end