Skip to content

Instantly share code, notes, and snippets.

Adam Sharp sharplet

Block or report user

Report or block sharplet

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
sharplet / BitMask.swift
Created Jul 11, 2017
Playing around with a high-level API for working with bit masks
View BitMask.swift
struct BitMask<T: FixedWidthInteger>: RandomAccessCollection {
typealias SubSequence = BitMask<T>
var rawValue: T {
var rawValue: T = 0
for bit in self {
rawValue |= bit
return rawValue
sharplet / scalars.swift
Last active Apr 7, 2017
Swift program to print out all the unicode scalars in a Foundation CharacterSet.
View scalars.swift
// Prints out all the unicode scalars in a Foundation CharacterSet.
// Compile: swiftc -O scalars.swift
// Run: ./scalars <character set name>
import Foundation
extension UnicodeScalar {
static var allScalars: AnySequence<UnicodeScalar> {
let numbers = sequence(first: 0, next: { $0 + 1 })
sharplet / Actor.swift
Last active Apr 5, 2017
Simple GCD-based actors in Swift
View Actor.swift
import Dispatch
/// Wraps some `Base` type so that all method calls become
/// "message sends", e.g., `async { $ }` or `sync { $ }`.
public final class Actor<Base> {
private var instance: Base
private let queue: DispatchQueue
public init(_ instance: Base, target: DispatchQueue? = nil) {
self.instance = instance
sharplet / trap.swift
Created Nov 23, 2015
Simple signal handling in Swift
View trap.swift
import Darwin
enum Signal: Int32 {
case HUP = 1
case INT = 2
case QUIT = 3
case ABRT = 6
case KILL = 9
case ALRM = 14
case TERM = 15
sharplet / GreetingFeature.swift
Created Oct 25, 2015
Cucumber inspired syntax for Xcode UI tests
View GreetingFeature.swift
final class GreetingFeature: Feature {
override func scenarios() {
Scenario("Greeting on first load")
.Given("the app has launched")
.Then("the text 'Hello, world!' is on screen")
sharplet /
Created Oct 22, 2015
A list of pros and cons to adopting Swift on new projects

Swift Pros and Cons


  • Code tends to be shorter & clearer
  • Value types are a super valuable design pattern (see what I did there)
  • Optionals are amazing
  • Online resources tend to be in Swift these days
  • Swift 2 is a lot better than Swift 1.2
  • Trending towards stability
sharplet / git
Created Aug 21, 2015
Disable git at the terminal, but still allow shelling out
View git
if [ -t 1 ]; then
echo LOL >&2
exit 1
real_git=$(type -a git | head -2 | tail -1 | cut -d" " -f 3)
exec "$real_git" ${*}
sharplet / lazy_reduce.rb
Created Aug 7, 2015
Lazy `#reduce` and `#join` in Ruby
View lazy_reduce.rb
require "rspec/autorun"
class Enumerator::Lazy
def reduce(*)[nil]) do |yielder, _|
yielder << super
def join(separator="")
sharplet / xcode_prebuilt_framework_debugger_crash.log
Created Jul 19, 2015
Xcode crash log when loading debug symbols from another machine
View xcode_prebuilt_framework_debugger_crash.log
Process: Xcode [56151]
Path: /Applications/
Version: 6.3.2 (7718)
Build Info: IDEFrameworks-7718000000000000~2
App Item ID: 497799835
App External ID: 812404257
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [56151]
View UIApplication+SHReactiveBackgroundTask.h
/// An API for managing UIKit background tasks by composing signals.
@interface UIApplication (SHReactiveBackgroundTask)
/// Creates a signal that wraps an underlying signal in a background task.
/// Upon subscription, starts a background task, and then automatically ends
/// the background task when the underlying signal completes or errors.
/// If the background task expires, the subscription to the underlying signal
/// will automatically be disposed of.
/// @note If the call to `-beginBackgroundTaskWithExpirationHandler:` returns
You can’t perform that action at this time.