Skip to content

Instantly share code, notes, and snippets.

@acolyer
acolyer / service-checklist.md
Last active January 30, 2024 17:39
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
@ka-interview
ka-interview / gist:a6478004c6cee552f225
Created October 14, 2014 23:57
Sketch of type safe, non-AnyObject-supporting data source
public protocol CountableCollectionType: CollectionType {
var count: Int { get }
}
extension Array: CountableCollectionType {}
public protocol CollectionViewCellFactoryType {
typealias Item
typealias Cell: UICollectionViewCell
func cellForItem(item: Item, inCollectionView collectionView: UICollectionView, atIndexPath indexPath: NSIndexPath) -> Cell
@chriseidhof
chriseidhof / :(
Created November 4, 2014 10:41 — forked from kostiakoval/:(
import Foundation
import ImageIO
infix operator >>= { associativity left }
func >>=<A,B>(l: A?, r: A -> B?) -> B? {
if let x = l {
return r(x)
}
return nil
@natecook1000
natecook1000 / NSTimer+Closure.swift
Last active January 6, 2024 07:23
Scheduled NSTimer with a Swift closure
extension NSTimer {
/**
Creates and schedules a one-time `NSTimer` instance.
- Parameters:
- delay: The delay before execution.
- handler: A closure to execute after `delay`.
- Returns: The newly-created `NSTimer` instance.
*/
@hmartiro
hmartiro / zeromq-vs-redis.md
Last active April 14, 2024 20:33
Comparison of ZeroMQ and Redis for a robot control platform

ZeroMQ vs Redis

This document is research for the selection of a communication platform for robot-net.

Goal

The purpose of this component is to enable rapid, reliable, and elegant communication between the various nodes of the network, including controllers, sensors, and actuators (robot drivers). It will act as the core of robot-net to create a standardized infrastructure for robot control.

Requirements:

@jacobsalmela
jacobsalmela / osx-set-all-names.sh
Created January 12, 2015 16:38
Set all four OS X computer names using a script.
#!/bin/bash
# Bonjour name ending in .local
scutil --set LocalHostName "My-iMac"
# Friendly name shown in System Preferences > Sharing
scutil --set ComputerName "My-iMac"
# The name recognized by the hostname command
scutil --set HostName "My-iMac"
# Save the computer's serial number in a variable so it can be used in the next command.
serialNum=$(ioreg -l | awk '/IOPlatformSerialNumber/ { split($0, line, "\""); printf("%s\n", line[4]); }')
# Set the NetBIOS name as the serial number
@thinkclay
thinkclay / Keychain.swift
Last active August 30, 2016 12:13
Dead simple keychain access
import Security
public class Keychain
{
public class func set(key: String, value: String) -> Bool
{
if let data = value.dataUsingEncoding(NSUTF8StringEncoding)
{
return set(key, value: data)
}
@JadenGeller
JadenGeller / Swift Coalesce Function.swift
Last active August 29, 2015 14:16
Swift Coalesce Function
/*
* coalesce takes in a list of optional values
* and returns the first one that is not nil
*/
func coalesce<T>(all: @autoclosure () -> T? ...) -> T? {
for f: () -> T? in all {
if let x = f() { return x }
}
return nil
@nicklockwood
nicklockwood / gist:21495c2015fd2dda56cf
Last active August 13, 2020 13:57
Thoughts on Swift 2 Errors

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post: