Skip to content

Instantly share code, notes, and snippets.

View keybuk's full-sized avatar

Scott James Remnant keybuk

View GitHub Profile
@keybuk
keybuk / README.md
Last active July 21, 2021 11:22
SwiftUI Custom Alignments
@keybuk
keybuk / BindingAndState.swift
Last active June 7, 2019 00:35
Homebrew binding and state to understand how it works
@propertyDelegate
public struct Binding<Value> {
public var value: Value {
get { getValue() }
nonmutating set { setValue(newValue) }
}
public init(getValue: @escaping () -> Value, setValue: @escaping (Value) -> Void) {
self.getValue = getValue
self.setValue = setValue
import Foundation
import RaspberryPi
// Shutdown PWM1, clear FIFO
let pwm = try! PWM()
pwm[1].isEnabled = false
pwm.clearFifo()
// Stop the PWM clock
let clock = try! Clock()

This is a test

PATH=$PATH:/opt/swift/bin
swift --version
Swift version 4.1 (swift-4.1-RELEASE)
Target: armv7-unknown-linux-gnueabihf
@keybuk
keybuk / serial.log
Created April 20, 2018 17:11
WORKING
2018-04-20 09:23:44,536 - Changing monitoring state from "Offline" to "Detecting serial port"
2018-04-20 09:23:44,572 - Serial port list: ['/dev/ttyACM0']
2018-04-20 09:23:44,573 - Connecting to: /dev/ttyACM0
2018-04-20 09:23:44,630 - Changing monitoring state from "Detecting serial port" to "Opening serial port"
2018-04-20 09:23:44,633 - Connected to: Serial<id=0x6b756a30, open=True>(port='/dev/ttyACM0', baudrate=250000, bytesize=8, parity='N', stopbits=1, timeout=10.0, xonxoff=False, rtscts=False, dsrdtr=False), starting monitor
2018-04-20 09:23:44,634 - Changing monitoring state from "Opening serial port" to "Connecting"
2018-04-20 09:23:44,641 - Send: N0 M110 N0*125
2018-04-20 09:23:45,696 - Recv: start
2018-04-20 09:23:45,705 - Recv: echo:Marlin 1.1.5
2018-04-20 09:23:45,707 - Send: N0 M110 N0*125
@keybuk
keybuk / OctoPrint.log
Created April 20, 2018 17:10
WORKING
2018-04-19 21:07:57,068 - octoprint.server - INFO - --- Log roll over detected ---------------------------------------------------
2018-04-19 21:07:57,069 - octoprint.server - INFO - OctoPrint 1.3.8
2018-04-19 21:07:57,071 - octoprint.plugin.core - INFO - 12 plugin(s) registered with the system:
| Announcement Plugin (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/announcements
| Core Wizard (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/corewizard
| CuraEngine (<= 15.04) (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/cura
| Discovery (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/discovery
| Firmware Updater (1.0.0) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_firmwareupdater
| Logging (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/logging
| OctoPi Support Plugin (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/octopi_support
2018-04-19 21:07:57,068 - octoprint.server - INFO - --- Log roll over detected ---------------------------------------------------
2018-04-19 21:07:57,069 - octoprint.server - INFO - OctoPrint 1.3.8
2018-04-19 21:07:57,071 - octoprint.plugin.core - INFO - 12 plugin(s) registered with the system:
| Announcement Plugin (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/announcements
| Core Wizard (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/corewizard
| CuraEngine (<= 15.04) (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/cura
| Discovery (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/discovery
| Firmware Updater (1.0.0) = /home/pi/oprint/local/lib/python2.7/site-packages/octoprint_firmwareupdater
| Logging (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/logging
| OctoPi Support Plugin (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/octopi_support
@keybuk
keybuk / Pwm.swift
Created December 13, 2016 02:13
Raspberry PI PWM
#if os(Linux)
import Glibc
#else
import Darwin
let O_SYNC: Int32 = 0
#endif
import Dispatch
@keybuk
keybuk / ifwhere.md
Last active February 15, 2021 07:26
Why the `where` clause in Swift's `for` loops matter

An important goal in Swift is clarity at the point of use, this appears in the API Design Guidelines as a fundamental, but also pervades the design of the Swift language itself.

I think that removing the where clause from Swift's for loops reduces clarity.

It may be that there are other ways to express the same code result, but "only one way to do it" has never been a Swift goal that I'm aware of, and an identical result does not necessarily equate to an identical intent.

Consider the following, which was actually a source of brief confusion for me while reading some of your code.

Example 1:

@keybuk
keybuk / FetchedResultsController.swift
Created April 21, 2016 00:21
NSFetchedResultsController replacement
//
// SectionedFetchedResults.swift
// DungeonMaster
//
// Created by Scott James Remnant on 3/14/16.
// Copyright © 2016 Scott James Remnant. All rights reserved.
//
import CoreData
import Foundation