Skip to content

Instantly share code, notes, and snippets.

Michael Bates mklbtz

Block or report user

Report or block mklbtz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mklbtz
mklbtz / displays.scpt
Created Sep 26, 2018
AppleScript that will open System Preferences and rotate displays to a preconfigured orientation
View displays.scpt
on launchDisplaysPane()
tell application "System Preferences"
activate
set displayPane to pane "com.apple.preference.displays"
set displayTab to anchor named "displaysDisplayTab" of displayPane
reveal displayTab
delay 0.5
end tell
end launchDisplaysPane
@mklbtz
mklbtz / Stopwatch.py
Last active Oct 8, 2018
Stopwatch - A simple class for taking time hacks.
View Stopwatch.py
from datetime import datetime, timedelta
import sys
class Stopwatch:
def __init__(self):
self._hacks = []
@property
def laps(self):
return len(self._hacks) - 1
@mklbtz
mklbtz / longings.py
Last active Dec 20, 2018
Things I already wish I had in Python
View longings.py
from __future__ import print_function
class NoneError(TypeError):
pass
class maybe:
"""
A two-state monad that represents the presents or absence of a value.
Think of it as a collection of zero or one values.
"""
@mklbtz
mklbtz / SketchSystems.spec
Last active Jun 1, 2018
No Opportunities*
View SketchSystems.spec
No Opportunities*
parts uploaded -> Estimate Requested
Estimate Requested
Reviewing Parts*
Unclean*
redact prints -> Reviewing Parts
upload dummies -> Reviewing Parts
all parts clean -> Clean
Clean
@mklbtz
mklbtz / README.md
Last active May 22, 2018
Some Unix-y command line tools written in Swift
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.

@mklbtz
mklbtz / Final-Tagless Views.rb
Created May 21, 2018
Demonstrating the "final tagless" approach to the "Expression Problem" in Ruby
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)
@mklbtz
mklbtz / new-data-literal.md
Created Mar 24, 2018
SE Proposal: New literal for Data from contents of file
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…

@mklbtz
mklbtz / AbsoluteDirectory.rb
Last active Oct 13, 2017
A DSL for safely building file paths
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?
@mklbtz
mklbtz / any_enumerable.rb
Last active Sep 25, 2017
A quick way to make enumerable objects from an arbitrary block
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.
You can’t perform that action at this time.