Since Twitter doesn't have an edit button, it's a suitable host for JavaScript modules.
Source tweet: https://twitter.com/rauchg/status/712799807073419264
const leftPad = await requireFromTwitter('712799807073419264');
~$ ARCHFLAGS='-arch i386 -arch x86_64' | |
~$ rvm install 1.8.7 --debug --reconfigure -C --enable-shared=yes | |
~$ wget http://sourceforge.net/projects/rubycocoa/files/RubyCocoa/1.0.0/RubyCocoa-1.0.0.tar.gz/download | |
~$ tar xzf RubyCocoa-1.0.0.tar.gz && rm RubyCocoa-1.0.0.tar.gz && cd RubyCocoa-1.0.0 | |
~/RubyCocoa-1.0.0$ ruby install.rb config --build-universal=yes | |
~/RubyCocoa-1.0.0$ ruby install.rb setup | |
~/RubyCocoa-1.0.0$ sudo ruby install.rb install |
*.strings utf16 diff=localizablestrings |
enum Either<A, B> { | |
case Left(A) | |
case Right(B) | |
} | |
func isLeft<A,B>(it : Either<A,B>) -> Bool { | |
switch it { case .Left: return true; case .Right: return false } | |
} | |
func isRight<A,B>(it : Either<A,B>) -> Bool { |
import Foundation | |
/// converts a string representing an unlocalized date with fixed-format to NSDate using Unix methods (suggested in Apple's Date Formatting guide: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html) | |
public func timeStringToDate(timeString: NSString, formatString: NSString) -> NSDate { | |
var t = tm() | |
return withUnsafeMutablePointer(&t) { t -> NSDate in | |
strptime_l(timeString.UTF8String, formatString.UTF8String, t, nil) | |
return NSDate(timeIntervalSince1970: NSTimeInterval(mktime(t))) | |
} | |
} |
Since Twitter doesn't have an edit button, it's a suitable host for JavaScript modules.
Source tweet: https://twitter.com/rauchg/status/712799807073419264
const leftPad = await requireFromTwitter('712799807073419264');
struct OverflowLayout: Layout { | |
var spacing = CGFloat(10) | |
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { | |
let containerWidth = proposal.replacingUnspecifiedDimensions().width | |
let sizes = subviews.map { $0.sizeThatFits(.unspecified) } | |
return layout(sizes: sizes, containerWidth: containerWidth).size | |
} | |
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { |