Skip to content

Instantly share code, notes, and snippets.

View paulyoung's full-sized avatar
💭
Type check and prove things

Paul Young paulyoung

💭
Type check and prove things
View GitHub Profile
//
// Signal+Extensions.swift
// Khan Academy
//
// Created by Nacho Soto on 10/1/15.
// Copyright © 2015 Khan Academy. All rights reserved.
//
import ReactiveCocoa
@chriseidhof
chriseidhof / Brian.swift
Last active January 23, 2016 00:48
Encoding
struct User {
let firstName: String
let lastName: String
let year: Int
}
enum JSONValue {
case JSONString(String)
case JSONInt(Int)
}
@rnapier
rnapier / map-0-box.swift
Last active February 3, 2018 22:59
Another Swift box for [Protocol]
// Yet another Swift box....
// I had never run into this explicitly until Andrew Spiess (@ninjazoete) asked about it a couple of days ago:
// https://twitter.com/ninjazoete/status/669530132919525377
// Now it's springing up all over the place in my work.
//
// I'm calling it "map-$0-boxing" for the moment ("identity boxing" is more accurate, but "map-$0" better
// matches the actual code). Anyone have a better or clearer implementation?
//
@antonycourtney
antonycourtney / DiamondExample.md
Last active May 6, 2024 05:21
A real world example of recombinant / diamond wiring and feedback with RxJS

A realistic RxJS app with diamond wiring

Consider the following user interface (inspired by Strava) for looking at time-series charts of network data:

esnet-estes-charts

Notes on this interface and my Rx implementation of it:

  • Each chart (stacked vertically) charts a different metric (latency, packet loss and throughput) but over the same time period.
  • As the user moves the mouse left and right on any chart, the vertical line (called the tracker) moves to track the mouse position on all charts. The number displayed in the gray box on the right is the value underneath the tracker for that metric.
@rnapier
rnapier / 1-simplejson.swift
Last active February 3, 2018 22:59
Yeah, @krzyzanowskim is probably right. What problem were we solving?
import Foundation
// All the complexity needed to avoid this code probably isn't worth it in the majority of cases.
// Particularly note that the data model doesn't 100% line up with the JSON (some keys have
// slightly different names for instance). A system flexible enough to handle that (say, something
// like Go's json.Marshal) would be nice, but this code, while slightly tedious, isn't really bad.
// Basically I'm saying that a richer JSON<->Swift system built into stdlib would be nice, but the
// bar is pretty high to go pulling in a helper library.
//
// That said, compare the Go code below, and I think it really is much simpler, and scales much better
@nikita-leonov
nikita-leonov / generic-protocols.swift
Created October 31, 2015 05:54
`Generic` Protocols
class Container<T> {
private var containedValue: T
init(_ value: T) {
containedValue = value
}
}
protocol ContainerProtocol {
typealias ValueType
@plumhead
plumhead / StringSize.swift
Created September 15, 2015 13:34
String extension to find the layout size of a String with specified attributes.
extension String {
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect {
let storage = NSTextStorage(string: self)
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height))
let layout = NSLayoutManager()
layout.addTextContainer(container)
storage.addLayoutManager(layout)
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length))
container.lineFragmentPadding = 0.0
let _ = layout.glyphRangeForTextContainer(container)
@anaisbetts
anaisbetts / AccentColors.cs
Created August 18, 2015 17:54
Render the accent background of a Windows Store-style icon
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
// https://raw.githubusercontent.com/maxtruxa/AccentColors/master/AccentColors/AccentColor.cs
@kentcdodds
kentcdodds / README.md
Last active October 27, 2015 13:41
One page site for First Timers Only concept

First Timers Only website idea

I wrote a blogpost on Medium last week about something I've been doing with my open source project. Check that out first: https://medium.com/@kentcdodds/first-timers-only-78281ea47455

It's had a fantastic response and people are enthusiastic about the idea. In an effort to encourage more projects to participate, I decided to file an issue on the up-for-grabs website repo and ask them if they would be willing to have a section dedicated to projects with first-timers-only issues.

If you checkout that issue, you see that Scott Hanselman has bought the domain firsttimersonly.com and wants to turn it into a one pager about the idea with links/resources/etc.

------------
Conformances
------------
protocol AbsoluteValuable
Conformances:
Comparable
IntegerLiteralConvertible
SignedNumberType