Skip to content

Instantly share code, notes, and snippets.

View wildthink's full-sized avatar

Jason Jobe wildthink

  • 21:53 (UTC -04:00)
View GitHub Profile
import Foundation
protocol Currency { static var sign: String { get } }
enum GBP: Currency { static let sign = "£" }
enum EUR: Currency { static let sign = "" }
enum USD: Currency { static let sign = "$" }
protocol _Money {
associatedtype C: Currency
var amount: NSDecimalNumber { get }
@vasanthk
vasanthk / System Design.md
Last active October 28, 2025 05:19
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@eonist
eonist / TranslucentWin.swift
Created January 27, 2016 14:09
Translucent NSWindow Example
class TranslucentWin:NSWindow, NSApplicationDelegate, NSWindowDelegate{
/**
*
*/
override init(contentRect: NSRect, styleMask aStyle: Int, backing bufferingType: NSBackingStoreType, `defer` flag: Bool) {
super.init(contentRect: Win.sizeRect, styleMask: NSTitledWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask|NSFullSizeContentViewWindowMask, backing: NSBackingStoreType.Buffered, `defer`: false)
self.contentView!.wantsLayer = true;/*this can and is set in the view*/
self.backgroundColor = NSColor.greenColor().alpha(0.2)
self.opaque = false
self.makeKeyAndOrderFront(nil)//moves the window to the front
@stefc
stefc / BitArray.swift
Last active January 10, 2023 11:55
BitArray based on CFBitVector Swift implementation
//
// BitArray.swift
// xFuncs
//
import Foundation
public class BitArray : CollectionType {
public typealias Index = Int
@hsavit1
hsavit1 / transducer-type.swift
Created December 12, 2015 06:31 — forked from mbrandonw/transducer-type.swift
How to get a transducer type without higher kinds
import Foundation
// A bunch of convenience things
func const <A, B> (b: B) -> A -> B {
return { _ in b }
}
func repeat <A> (n: Int) -> A -> [A] {
return { a in
return map(Array(1...n), const(a))
}
@plumhead
plumhead / NSTextViewExtensions.swift
Created November 13, 2015 16:38
Useful NSTextView extensions
extension NSTextView {
func rectForRange(range: NSRange) -> NSRect? {
guard let layout = self.layoutManager, container = self.textContainer else {return nil}
let rng = layout.glyphRangeForCharacterRange(range, actualCharacterRange: nil)
let rct = layout.boundingRectForGlyphRange(rng, inTextContainer: container)
return NSOffsetRect(rct, self.textContainerOrigin.x, self.textContainerOrigin.y)
}
func rectForSelectedRange() -> NSRect? {
return rectForRange(self.selectedRange())
@DonaldHays
DonaldHays / UUID.swift
Created November 3, 2015 08:09
A UUID type built in pure Swift
import Swift
/// `UUID` represents a 128-bit value suitable for uniquely identifying things.
public struct UUID: Hashable {
// MARK: -
// MARK: Public Properties
/// The raw bytes of the UUID.
public let data: Data
@JadenGeller
JadenGeller / Reduce1.swift
Last active October 16, 2016 16:12
Reduce1
#if swift(>=3.0)
extension Sequence {
func reduce(combine: @noescape (Iterator.Element, Iterator.Element) throws -> Iterator.Element) rethrows -> Iterator.Element? {
var iterator = makeIterator()
guard var result = iterator.next() else { return nil }
while let element = iterator.next() {
result = try combine(result, element)
}
return result
}
@plumhead
plumhead / SwiftExpr.swift
Created September 24, 2015 15:22
Playing with Swift Pattern Matching for Mathematical Expressions (run in playground)
import Cocoa
//: # An exercise in specifying and simplifying Maths functions using Swift
/*: This is cut-down version of some code I've been working on to parse, simplify and display mathematical expressions. The source below shows some of the power of pattern matching and (recursive) enumerated types within Swift in defining and evaluating the expression domain. Note, it doesn't cover all cases but is intended to give a flavour of what can be achieved.
No optimisations applied
*/
//: # Supporting functions
//: ### Function Pipeline
@smarr
smarr / truffle-material.md
Last active April 2, 2025 18:27
Truffle: Languages and Material