Skip to content

Instantly share code, notes, and snippets.

View JRHeaton's full-sized avatar

John Heaton JRHeaton

View GitHub Profile
@JRHeaton
JRHeaton / printer.cfg
Last active June 1, 2022 20:38
Ender 3 Pro 4.2.2
[skew_correction]
[display_status]
[pause_resume]
[respond]
[gcode_arcs]
@JRHeaton
JRHeaton / segfault_10_2_1.swift
Created July 1, 2019 19:08
Issue causing segmentation fault (Xcode 10.2.1, Swift 4.2.1)
/* === This code segfaults, and only through much trial & error + commenting out code did I narrow it down to this. === */
/*
protocol PaymentService {
typealias Error = Swift.Error & CustomStringConvertible & Equatable
associatedtype LogInError: PaymentService.Error
}
// MyPaymentService.LogInError does not conform to Swift.Error
*/
/* === This code compiles fine. I believe this is a bug in the compiler (conforming to the typealias,
@JRHeaton
JRHeaton / generic_bug.swift
Created May 24, 2016 05:29
Swift bug w/ generic class initializer
import UIKit
enum X: ErrorType {}
/**
error: declared closure result 'UICollectionView' is incompatible with contextual type '_'
createItemView: { () -> UICollectionView in
(it should be inferring LoadStateView.ItemView as the return type of this closure)
*/
~> cat test.swift
print((0, 1) == (0, 1))
/tmp
~> sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
/tmp
~> swift test.swift
test.swift:1:14: error: binary operator '==' cannot be applied to two '(Int, Int)' operands
print((0, 1) == (0, 1))
~~~~~~ ^ ~~~~~~
/tmp
@JRHeaton
JRHeaton / carthage.fish
Created November 20, 2015 21:54
Command completion for Carthage
function add_command
complete -c carthage -a $argv[1] -d $argv[2] -f
end
function add_command_option
complete -c carthage -n "contains $argv[1] (commandline -poc)" -l $argv[2] -d $argv[3]
end
# Add all top level commands
add_command archive "Archives a built framework into a zip that Carthage can use"
@JRHeaton
JRHeaton / swift_warning_issue.swift
Last active October 27, 2015 16:40
Swift compiler does not detect the `try` expression given to the Result initializer unless broken up into its own expression
// warning: 'catch' block is unreachable because no errors are thrown in 'do' block
public func requestJSON<ModelType: MTLModel>(target: CocoaBlocAPI) -> SignalProducer<ModelType, NSError> {
return tryGetJSONObjectForKey(requestJSON(target), key: "data")
.attemptMap { (value: [NSObject:AnyObject]) -> Result<ModelType, NSError> in
do {
return Result(try MTLJSONAdapter.modelOfClass(ModelType.self, fromJSONDictionary: value) as! ModelType)
}
catch let error as NSError {
return .Failure(error)
}
@JRHeaton
JRHeaton / avr_lcd.cpp
Last active September 20, 2015 08:50
// 8mhz internal
#define F_CPU 8000000
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
// 8 bit LCD logic pins
#define LCD_DATA_DIRECTION DDRB
#define LCD_DATA_PORT PORTB
@JRHeaton
JRHeaton / brainfuck.swift
Last active August 29, 2015 14:18
Brainfuck parser + interpreter in Swift 1.2 made w/ @danzimm
import Madness
import Prelude
struct Brainfuck {
class State {
var bytes = ContiguousArray<UInt8>(count: 30_000, repeatedValue: 0)
var pointer: UInt16 = 0
var deref: UInt8 {
get {
return bytes[Int(pointer)]
@JRHeaton
JRHeaton / pcomb2.swift
Last active August 29, 2015 14:18
more parser combinator fun (i have no idea what i'm doing :D)
class Box<T>: Printable {
let unbox: T
init(_ value: T) {
self.unbox = value
}
var description: String {
return toString(unbox)
}
@JRHeaton
JRHeaton / tupleparse.swift
Last active August 29, 2015 14:18
using rob rix's madness to parse lowercase/numeric tuples cuz that's what we do when we learn
func flatten(x: [String]) -> String {
return reduce(x, "", +)
}
let x = "(1,2,(3,4,(5, potato,7)),8,(9))"
enum Type: Printable {
case Element(String)
case Tuple([Type])