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
sharplet / Example.swift
Created Nov 3, 2017
An improved wrapper for UIImagePickerController
View Example.swift
// Here is a usage example. Refer to ImagePicker.swift below for the implementation!
// 1. Easily configure the picker
let cameraPicker = ImagePicker(sourceType: .camera)
let cropPicker = ImagePicker(sourceType: .photoLibrary, allowsEditing: true)
// Automatically includes both kUTTypeImage and kUTTypeLivePhoto
let livePhotoPicker = ImagePicker(sourceType: .photoLibrary, mediaTypes: [.livePhotos])
// 2. Use the picker
@sharplet
sharplet / DispatchSourceInterrupt.swift
Created Jun 18, 2019
Demo of DispatchSourceSignal for handling interrupts
View DispatchSourceInterrupt.swift
import Darwin.C
import Dispatch
signal(SIGINT, SIG_IGN)
let source = DispatchSource.makeSignalSource(signal: SIGINT, queue: .main)
var count = 0
source.setEventHandler {
@sharplet
sharplet / SimpleNetworkingExample.swift
Created Sep 14, 2017
Example Source Code for "A Simple Approach to Thread-Safe Networking in iOS Apps"
View SimpleNetworkingExample.swift
import Foundation
import PlaygroundSupport
enum URLResult {
case response(Data, URLResponse)
case error(Error, Data?, URLResponse?)
}
extension URLSession {
@discardableResult
View git-remove-submodule
#!/bin/sh
#
# Adam Sharp
# Aug 21, 2013
#
# Usage: Add it to your PATH and `git remove-submodule path/to/submodule`.
#
# Does the inverse of `git submodule add`:
# 1) `deinit` the submodule
# 2) Remove the submodule from the index and working directory
@sharplet
sharplet / Example.swift
Last active May 11, 2019
Mutable property lenses for ReactiveSwift with key paths
View Example.swift
struct User {
var name: String
}
let currentUser = MutableProperty(User(name: "Foo"))
currentUser[\.name] <~ nameTextField.reactive.textValues
@sharplet
sharplet / ContentViewEmbedding.swift
Created Feb 6, 2019
A protocol for view controllers with a replaceable content view controller
View ContentViewEmbedding.swift
import UIKit
/// For a view controller that has no content of its own, implement like so:
///
/// extension RootViewController: ContentViewEmbedding {
/// var contentView: UIView! {
/// return view
/// }
/// }
protocol ContentViewEmbedding {
@sharplet
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
sharplet / README.md
Last active Jun 8, 2018
Unearned Stack Overflow badges Dashing widget
View README.md

Badge Overflow

An exceptionally handsome way to track your Stack Overflow badges.

Created by Adam & Stephanie Sharp.

Unearned Badges widget

A Dashing widget that tracks your progress toward unearned badges on Stack Overflow.

@sharplet
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(*)
Lazy.new([nil]) do |yielder, _|
yielder << super
end
end
def join(separator="")
@sharplet
sharplet / rake.log
Last active Feb 3, 2018
Building a Swift framework, then building and running Quick specs, *without Xcode*
View rake.log
# View on GitHub: https://github.com/sharplet/Switch
# Try it yourself: git clone https://github.com/sharplet/Switch.git && cd Switch && rake
$ rake
mkdir -p Build
mkdir -p Build/Switch.framework
mkdir -p Build/Switch.framework/Versions/A/Modules/Switch.swiftmodule
ln -sf A Build/Switch.framework/Versions/Current
ln -sf Versions/Current/Modules Build/Switch.framework/Modules
ln -sf Versions/Current/Switch Build/Switch.framework/Switch
xcrun -sdk macosx swiftc -module-name Switch -emit-library -o Build/Switch.framework/Versions/Current/Switch -- Source/Array+Ext.swift Source/Option.swift Source/ParseResult.swift Source/Parser.swift Source/String+Ext.swift
You can’t perform that action at this time.