Skip to content

Instantly share code, notes, and snippets.

View davelyon's full-sized avatar

Dave Lyon davelyon

View GitHub Profile
var fortunes=new Array(" One learns to itch where one can scratch. -- Ernest Bramah "," One meets his destiny often on the road he takes to avoid it. "," One monk said to the other, \"The fish has flopped out of the net! How will it live?\" The other said, \"When you have gotten out of the net, I'll tell you.\" "," Only that in you which is me can hear what I'm saying. -- Baba Ram Dass "," Only those who leisurely approach that which the masses are busy about can be busy about that which the masses take leisurely. -- Lao Tsu "," Paradise is exactly like where you are right now ... only much, much better. -- Laurie Anderson "," Perfection is reached, not when there is no longer anything to add, but when there is no longer anything to take away. -- Antoine de Saint-Exupery "," Perhaps the biggest disappointments were the ones you expected anyway. "," Philosophy will clip an angel's wings. -- John Keats "," Push where it gives and scratch where it itches. "," Reality always seems harsher in the early morning. ",
@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 / 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
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
Given "a user" do
@user = User.new
end
When "I activate that user" do
@user.avtivate!
end
# 10 other steps that all depend on/change "@user"