Skip to content

Instantly share code, notes, and snippets.

View dwaite's full-sized avatar
💭
Wondering what status is for

David Waite dwaite

💭
Wondering what status is for
View GitHub Profile
; WebAuthn create()
PublicKeyCredentialCreationRequest = {
publicKey: {
rp: PublicKeyCredentialRpEntity,
user: PublicKeyCredentialUserEntity,
challenge: bstr,
pubKeyCredParams: [* PublicKeyCredentialParameters],
? timeout: int,
? excludeCredentials: [* PublicKeyCredentialDescriptor] .default [],
@dwaite
dwaite / gen.swift
Last active November 17, 2017 14:03 — forked from blainerothrock/gen.swift
A Very Simple Genetic Algorithm Written in Swift 3
#!/usr/bin/env xcrun swift -O
/*
gen.swift is a direct port of cfdrake's helloevolve.py from Python 2.7 to Swift 3
-------------------- https://gist.github.com/cfdrake/973505 ---------------------
gen.swift implements a genetic algorithm that starts with a base
population of randomly generated strings, iterates over a certain number of
generations while implementing 'natural selection', and prints out the most fit
string.
The parameters of the simulation can be changed by modifying one of the many
@dwaite
dwaite / se-nnnn-fulfill-protocol-requirements.md
Last active April 7, 2017 08:15
[SE-NNNN] Fullfill protocol requirements explicitly with extensions and types

Fullfil protocol requirements explicitly with extensions and types

Introduction

Types implementing protocols with optional features (either through default implementations on extensions, or optional methods on objective-C protocols) do not have a way to detect typos or upstream changes to the protocol will result in behavioral changes. This proposal attempts to rectify that in a manner similar to override on subclassed types.

enum Booly {
case truth
case falsehood
static let yes:Booly = truth
static let no:Booly = falsehood
static func defaulted() -> Booly {
return truth
}
import Foundation
public class Foo : NSObject {}
public class Bar : NSObject {}
public func ==(lhs:Bar, rhs:Bar) -> Bool {return true}
Foo() == Foo() // NSObject variant - false
Bar() == Bar() // our variant - true
#!/usr/bin/ruby
# Set two thread locals
Thread.current["foo"] = "fooval"
Thread.current["bar"] = "barval"
puts [Thread.current["foo"], Thread.current["bar"]]
# prints:
# fooval
# barval
We couldn’t find that file to show.
#include <stdio.h>
/* prints 78.882004 */
int main(int argc, char** argv) {
float f = 78.882;
printf("%f\n", f);
return 0;
}
$ RBXOPT=-Xprofile\ -Xprofiler.graph\ -Xprofiler.full_report rbx -S rspec spec -f p &>foo
bash-3.2$ vim foo
bash-3.2$ grep Array#map foo
0.00 0.22 1 Array#map [74]
[74] 0.3 0.00 0.22 1 Array#map [74]
0.00 0.22 1 Array#map [74]
0.00 0.22 4 Array#map [76]
[76] 0.3 0.00 0.22 4 Array#map [76]
0.00 0.22 4 Array#map [76]
0.00 0.22 1 Array#map [80]
ruby-1.9.2-p180 :008 > z = Fiber.new{Thread.current}.resume
=> #<Thread:0x00000100887678 run>
ruby-1.9.2-p180 :009 > Thread.current
=> #<Thread:0x00000100887678 run>
ruby-1.9.2-p180 :010 > z = Fiber.new{Thread.current.object_id}.resume
=> 2151955260
ruby-1.9.2-p180 :011 > Thread.current.object_id
=> 2151955260