Skip to content

Instantly share code, notes, and snippets.

🦅
Swifting

Harlan Haskins harlanhaskins

🦅
Swifting
Block or report user

Report or block harlanhaskins

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
View if-configs.swift
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/Test~partial.swiftmodule -module-name Test -primary-file %s
// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/Test.swiftmodule %t/Test~partial.swiftmodule
// RUN: %target-swift-ide-test -print-module -module-to-print=Test -source-filename=x -I %t | %FileCheck %s
// RUN: %target-swift-frontend -emit-interface-path %t.swiftinterface -enable-resilience -emit-module -o /dev/null %s
// RUN: %FileCheck %s < %t.swiftinterface
// CHECK: func hasClosureDefaultArg(_ x: () -> Void = {
// CHECK-NEXT: })
@harlanhaskins
harlanhaskins / BitArray.swift
Created Jul 20, 2018
Swift BitArray that behaves like an array of bools.
View BitArray.swift
import Foundation
extension BinaryInteger {
/// Gets the bit at the specified bit index in the receiver, reading from
/// least to most-significant bit.
///
/// For example,
/// ```
/// 0b0010.bit(at: 0) == false
/// 0b0010.bit(at: 1) == true
@harlanhaskins
harlanhaskins / BitstreamWriter.swift
Created Jun 19, 2018
LLVM Bitstream Writer in Swift
View BitstreamWriter.swift
import Foundation
typealias UnsignedIntegralType = UnsignedInteger & ExpressibleByIntegerLiteral
struct BitstreamRecord {
private(set) var values = [UInt32]()
mutating func append<IntType: UnsignedIntegralType>(_ int: IntType) {
values.append(UInt32(int))
}
View call-of-deleted-method.swift
import Foundation
import SwiftSyntax
/*:
# Syntax Rewriting
SwiftSyntax provides a class called `SyntaxRewriter`, which will walk a Syntax tree and
perform transformations over the nodes.
By default, these transformations don't do anything. It's the subclass's job to
@harlanhaskins
harlanhaskins / StringScanner.swift
Last active Aug 19, 2018
Swift String Scanner
View StringScanner.swift
import Foundation
/// `StringScanner` is a fast scanner for Strings and String-like objects.
/// It's used to extract structured bits from unstructured strings, while
/// avoiding making extra copies of string bits until absolutely necessary.
/// You can build Scanners over Substrings, allowing you to scan
/// parts of strings and use smaller, more specialized scanners to extract bits
/// of that String without needing to reuse another scanner.
public struct StringScanner<Input: StringProtocol> {
let input: Input
View gist:4a084e4a33f6f075317347b4c8708e69
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -module-name NIOOpenSSL -incremental -emit-dependencies -emit-module -emit-module-path /Users/harlan/Code/Swift/WWDC-Photohunt/.build/x86_64-apple-macosx10.10/debug/NIOOpenSSL.swiftmodule -output-file-map /Users/harlan/Code/Swift/WWDC-Photohunt/.build/x86_64-apple-macosx10.10/debug/NIOOpenSSL.build/output-file-map.json -parse-as-library -num-threads 8 -c /Users/harlan/Code/Swift/WWDC-Photohunt/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/NIOOpenSSL/IdentityVerification.swift /Users/harlan/Code/Swift/WWDC-Photohunt/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/NIOOpenSSL/OpenSSLClientHandler.swift /Users/harlan/Code/Swift/WWDC-Photohunt/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/NIOOpenSSL/OpenSSLHandler.swift /Users/harlan/Code/Swift/WWDC-Photohunt/.build/checkouts/swift-nio-ssl.git-1370587408992578247/Sources/NIOOpenSSL/OpenSSLServerHandler.swift /Users/harlan/C
@harlanhaskins
harlanhaskins / scryfall-example.swift
Created Mar 5, 2018
ScryfallAbstractionsExample
View scryfall-example.swift
import Foundation
enum Result<Value> {
case success(Value)
case failure(Error)
func promote() throws -> Value {
switch self {
case .success(let value):
return value
@harlanhaskins
harlanhaskins / ArduinoUtils.h
Last active Jan 27, 2018
A C++API for Arduino
View ArduinoUtils.h
#include <Arduino.h>
#ifndef ARDUINO_UTILS_H
#define ARDUINO_UTILS_H
/// DigitalPin is a base class for digital I/O pins. On its own, it just
/// declares the data layout -- it's up to subclasses to implement features
/// that are specific to input or output.
class DigitalPin {
protected:
View keybase.md

Keybase proof

I hereby claim:

  • I am harlanhaskins on github.
  • I am harlanhaskins (https://keybase.io/harlanhaskins) on keybase.
  • I have a public key ASAaLSbIdUmM-i3WHBBB-TdELlHJc_NXNetHa6sBSxxqzAo

To claim this, I am signing this object:

@harlanhaskins
harlanhaskins / swift-format.swift
Created Oct 26, 2017
Simple Swift Formatter using SwiftSyntax
View swift-format.swift
import Foundation
import SwiftSyntax
func main() throws {
guard CommandLine.arguments.count > 1 else {
print("usage: swift-format [file]")
exit(-1)
}
let url = URL(fileURLWithPath: CommandLine.arguments[1])
You can’t perform that action at this time.