Skip to content

Instantly share code, notes, and snippets.

View calda's full-sized avatar

Cal Stephens calda

View GitHub Profile
@calda
calda / BulgarianSolitairePlayer.java
Last active October 11, 2016 19:16
Statistical analysis of Bulgarian Solitaire
//scroll down for statistical analysis
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
public class BulgarianSolitairePlayer{
static List<Integer> moves = new ArrayList<Integer>();
@calda
calda / ViewController.swift
Created October 20, 2014 23:49
The view controller for my Inflation Calculator
//
// ViewController.swift
// Inflation Calculator
//
// Created by Cal on 10/4/14.
// Copyright (c) 2014 Cal. All rights reserved.
//
import UIKit
@calda
calda / GistList!.md
Created December 15, 2014 13:32
Try GistList for iOS! http://gistlist.io/

##alt text GistList: TODO for coders alt text

@IBDesignable
class CornerRadiusView : UIView {
@IBInspectable var cornerRadius: CGFloat = -1
override func draw(_ rect: CGRect) {
self.layer.cornerRadius = cornerRadius
}
}
@calda
calda / tikz
Created March 14, 2017 03:45
tikz
\begin{tikzpicture}[auto, node distance=2cm, every loop/.style={},
thick,main node/.style={circle,draw,font=\sffamily\large\bfseries},graph node/.style={}]
\node[main node] (1) {$v_1$};
\node[main node] (2) [below left of=1] {$v_2$};
\node[main node] (3) [below right of=1] {$v_3$};
\node[main node] (4) [below left of=3] {$v_4$};
\node[main node] (5) [below left of=4] {$v_5$};
\node[main node] (6) [below right of=4] {$v_6$};
\node[main node] (7) [below right of=5] {$v_7$};
@calda
calda / SortDescriptor.swift
Created July 20, 2018 00:45
SortDescriptor.playground
import Foundation
// MARK: SortDescriptor
/// Type-erased Sort Descriptor (can store multiple in the same array
/// regardless of the underlying KeyPath
public struct SortDescriptor<Element> {
private let comparator: (Any, Any) -> Bool
@calda
calda / SortDescriptor.swift
Created July 20, 2018 00:58
SortDescriptors (July 18)
public struct SortDescriptor<Element> {
private let keyPath: PartialKeyPath<Element>
private let comparator: (Any, Any) -> ComparisonResult
// For abitrary `Value` types, the consumer has to provide the entire Comparator
public init<Value>(
_ keyPath: KeyPath<Element, Value>,
using comparator: @escaping (Value, Value) -> ComparisonResult)
{
@calda
calda / schwartzian.swift
Created September 18, 2018 19:35
Schwartzian Transform experiment
import QuartzCore
// MARK: Extensions
extension Sequence {
func sorted<T: Comparable>(by value: (Element) -> T) -> [Self.Element] {
return self.sorted(by: { lhs, rhs in
@calda
calda / sort-playground.swift
Created September 18, 2018 19:39
`sort` ergonomics
// MARK: Collection + Sort Imprvements
extension Collection {
// an equivalent set of mutating `sort(by:)` methods would also be made available.
func sorted<T: Comparable>(by value: (Element) throws -> T) rethrows -> [Element] {
return try self.sorted(by: { lhs, rhs in
return (try value(lhs)) < (try value(rhs))
@calda
calda / DateFormatterHelpers.swift
Created April 2, 2019 21:32
LoggingManager.swift
//
// DateFormatterHelpers.swift
// WindowKit
//
// Created by Cal Stephens on 1/20/19.
// Copyright © 2019 Cal Stephens. All rights reserved.
//
import Foundation