View README.md

In the course of time, I found myself wanting to run RSpec automatically in response to file changes. I found a nice tool called fswatch to handle the file events, but I wanted a "smarter" pipeline. Following the Unix philosophy, I wrote a few tiny command line tools which I've provided the source to.

  • specname — maps a file in a rails project to its corresponding spec file.
  • debounce — makes sure multiple rapid saves don't trigger as many RSpec runs.
  • throttle — could be used to collect multiple file changes into one RSpec run, but I haven't figured that last part out yet.

The core functions are fully generic and have no dependencies on anything but Foundation, so they could be easily incorporated into a larger project if there's a use for them.

View Final-Tagless Views.rb
class View
def self.image(url:)
Image.new.tap { |img| img.url = url }
end
def self.button(title:)
Button.new.tap { |btn| btn.title = title }
end
def self.stack(subviews)
View new-data-literal.md

New literal for Data from contents of file

  • Proposal: SE-NNNN
  • Authors: Michael Bates
  • Review Manager: TBD
  • Status: Awaiting implementation

Introduction

In Swift today, literals give us the ability to embed files, images, and colors directly into our programs. This proposes a new literal that will embed the contents of a file as Data. The proposed syntax is…

View AbsoluteDirectory.rb
class AbsoluteDirectory < AbstractPath
def self.root
AbsoluteDirectory.new(nodes: [])
end
def initialize(nodes:)
raise "Last node cannot be a file, got (#{nodes.last.class})" if nodes.last&.file?
if nodes.first&.root?
super(nodes: nodes)
elsif nodes.first&.current?
View any_enumerable.rb
class AnyEnumerable
include Enumerable
def initialize(&each_impl)
@each_impl = each_impl
end
def each(&block)
@each_impl.call(&block)
end
View Token.swift
/// Useful for maintaining a strong reference to
/// something which would otherwise be deinitialized.
public final class Token<A> {
public let id: A
private let dispose: (A) -> Void
/// Create a new token
///
/// - Parameters:
/// - id: A unique identifier for this token.
View Collection+random.swift
import Darwin
extension RandomAccessCollection {
// Fails if collection is larger than UInt32.max
var randomIndex: Index {
guard !isEmpty else { return endIndex }
let fullDistance = UInt32(distance(from: startIndex, to: endIndex))
let randomDistance = IndexDistance(arc4random_uniform(fullDistance))
return index(startIndex, offsetBy: randomDistance)
}
View Identifier.swift
/// Useful as a type-safe String identifier for objects, records, etc.
/// Generic type A is the type of the object being "identified".
public struct Identifier<A>: Equatable, Hashable, Comparable {
public let string: String
public init(_ string: String) {
self.string = string
}
public var hashValue: Int {
View Algebra.swift
// A Number-like type that can represent algebraic expressions.
public enum Algebra {
case scalar(Double)
case variable(name: String, () -> Double)
indirect case add(Algebra, Algebra)
indirect case subtract(Algebra, Algebra)
indirect case multiply(Algebra, by: Algebra)
indirect case divide(Algebra, by: Algebra)
indirect case magnitude(Algebra)
indirect case raise(Algebra, toPower: Int)
View algebra.rb
# A Numeric-like class that can represent algebraic expressions.
# Uses typecases to define what operations are representable.
class Algebra
include Enum
# Represents number literals
typecase :scalar, value: Numeric do
def to_s
value.to_s
end