Skip to content

Instantly share code, notes, and snippets.

View tayloraswift's full-sized avatar

taylorswift tayloraswift

View GitHub Profile
import sys
text = sys.argv[1]
def hue(angle):
h = angle / 60
x = 1 - abs(h % 2 - 1)
return ((1, x, 0), (x, 1, 0), (0, 1, x), (0, x, 1), (x, 0, 1), (1, 0, x))[int(h)]
def hexcolor(rgb):
import func Glibc.atan2
infix operator <> :MultiplicationPrecedence // dot product
infix operator >< :MultiplicationPrecedence // cross product
infix operator &<> :MultiplicationPrecedence // wrapping dot product
infix operator &>< :MultiplicationPrecedence // wrapping cross product
infix operator ~~ :ComparisonPrecedence // distance test
infix operator !~ :ComparisonPrecedence // distance test
import func Glibc.sin
import func Glibc.cos
import func Glibc.tan
import func Glibc.asin
import func Glibc.acos
import func Glibc.atan
import func Glibc.atan2
infix operator <> :MultiplicationPrecedence // dot product
infix operator >< :MultiplicationPrecedence // cross product
@tayloraswift
tayloraswift / vectormanifesto.md
Last active June 28, 2020 01:54
the vector manifesto

Vector manifesto

Vectors, understood as 2, 3, or 4-component numerical aggregates, are a fundamental currency type across many domains of programming. This document seeks to lay out a cohesive vision for adding standard vector support to the Swift language, with consideration for relevant long-term goals for the language type system.

Past discussions: 1 2, 3, 4, 5

Past pitches: 1

Vectors and fixed-size arrays

@tayloraswift
tayloraswift / stop-converting-data-to-string.md
Last active October 23, 2018 18:36
stop converting data to string dot mp3

Stop converting Data to String

Operating on [UInt8] text buffers (“bytestrings”) is a common programming task. A popular approach among some Swift users is to (ab)use the String API, and attempt to spell familiar C-idioms using its syntax. This has the major bonus of readability, but leaves users vulnerable to many pitfalls.

A common mistake is to convert bytestrings to Strings and compare them to other Strings. Given two bytestrings a:[UInt8], b:[UInt8], many users assume that

String(decoding: a, as: Unicode.ASCII.self) == 
String(decoding: b, as: Unicode.ASCII.self)
protocol Convolvable
{
static
func convolve(_ a:Self, _ b:Self) -> Self
static
func generate() -> Self
}
extension Int:Convolvable
@tayloraswift
tayloraswift / integer-convertible-character-literals.md
Last active October 31, 2021 19:38
Integer-convertible character literals
import func Glibc.asin
import func Glibc.acos
import func Glibc.atan2
protocol RandomBinaryGenerator
{
associatedtype RandomNumber where RandomNumber:UnsignedInteger,
RandomNumber:FixedWidthInteger
mutating func generate() -> RandomNumber
@tayloraswift
tayloraswift / rbtree.swift
Last active November 22, 2017 00:59
std::map? idk her
struct UnsafeBalancedTree<Element>:Sequence
{
fileprivate
struct NodeCore
{
enum Color
{
case red, black
}
struct QueueCore<Element>
{
// capacity always power of 2
private
var buffer:UnsafeMutableBufferPointer<Element> =
UnsafeMutableBufferPointer<Element>(start: nil, count: 0),
zero:Int = 0
public private(set)
var count:Int = 0