Skip to content

Instantly share code, notes, and snippets.

View palpatim's full-sized avatar

Tim Schmelter palpatim

View GitHub Profile
@palpatim
palpatim / ComparableWithOptionals.swift
Created June 28, 2016 16:28
Swift Comparable with Optionals
import Foundation
extension NSDate: Comparable {
func isLessThanDate(date: NSDate) -> Bool {
var result = false
if self.compare(date) == NSComparisonResult.OrderedAscending {
result = true
}
return result
}
import Foundation
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
class UnownedTester {
private static let testQueue = dispatch_queue_create("playground.unowned.tester", DISPATCH_QUEUE_SERIAL)
private static var instance: UnownedTester? = UnownedTester()
#!/bin/bash
##################################################
##################################################
# A template to use for writing new bash scripts.
# Includes argument parsing, verbose flag, and
# that's it.
##################################################
# SCRIPT METADATA
#!/usr/bin/env ruby
class AppShell
require "logger"
require "optparse"
@@BANNER = "A shell with app boilerplate & option parsing, suitable for subclassing"
@@VERSION = [0, 0, 1]
LOG_LEVELS = [ Logger::WARN, Logger::INFO, Logger::DEBUG ]
import Foundation
class Node<T: Comparable> {
let value: T
var left: Node?
var right: Node?
init(value: T, left: Node? = nil, right: Node? = nil) {
self.value = value
self.left = left
/* @flow */
type EnumName = string;
type EnumProperties = {[key: any]: any};
/// An abstract class that defines semantics for typesafe `enum` style implementations in JavaScript.
/// Relies on ES6 extensions to support static properties, and is therefore not suitable for all
/// projects.
///
/// Usage:
// @flow
function doAsyncWork(shouldSucceed: boolean): Promise<number> {
let p = new Promise(function asyncWorker(resolve, reject) {
setTimeout(function() {
if (shouldSucceed) {
resolve(42);
} else {
let error = new Error("rejected");
reject(error);
class Person {
name: string;
friends: Array<Person>;
constructor(name: string) {
this.name = name;
this.friends = [];
}
addFriends(friends: Array<Person>) {
import Foundation
protocol TestClassFactory {
static func make() -> TestClass
}
protocol TestClass {
var testValue: String { get set }
}
@palpatim
palpatim / CombineMergeSample.swift
Last active February 12, 2020 16:59
Combine Framework merge behavior
// Copy this into an Xcode Playground
import Foundation
import Combine
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let odds = PassthroughSubject<Int, Never>()
let evens = PassthroughSubject<Int, Never>()