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 / composite_task.rb
Last active Aug 29, 2015
Normally a rake task won't complete if one of its prerequisites fails. Define a composite task to allow them all to run, capturing exceptions and reporting them only after all have completed.
View composite_task.rb
# Take for example a convenience task, all_tests, that runs our app's
# test suite for multiple architectures:
#
# task :all_tests => [:test_64_bit, :test_32_bit]
#
# Defined as a regular task, Rake will bail out early if
# test_64_bit failed, never getting to the 32 bit tests.
#
# A composite task is almost identical in declaration:
#
@sharplet
sharplet / method.swift
Created Jan 13, 2015
Mapping with methods
View method.swift
/// Convert a free method into a regular funcion accepting an instance as the first parameter.
func method<A, B>(m: A -> () -> B) -> A -> B {
return { m($0)() }
}
let strings = ["1", "2", "3", "foo"]
strings.map(method(String.toInt))
// => [{Some 1}, {Some 2}, {Some 3}, nil]
@sharplet
sharplet / .clang-format
Created Apr 13, 2015
clang-format file for Objective-C projects
View .clang-format
AlignTrailingComments: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
BasedOnStyle: LLVM
BreakBeforeBraces: Attach
ColumnLimit: 120
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: false
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
@sharplet
sharplet / rake.log
Created Apr 15, 2015
Rake output building a framework and XCTest bundle from the command line
View rake.log
$ 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/Switch.swift
xcrun -sdk macosx swiftc -module-name Switch -emit-module-path Build/Switch.framework/Versions/A/Modules/Switch.swiftmodule/x86_64.swiftmodule -- Source/Switch.swift
touch Build/Switch.framework
View Kiwi.swift
import Kiwi
import XCTest
class KiwiSpec: KWSpec {
override class func buildExampleGroups() {
it("has a test") {
XCTAssert(1 + 1 == 2)
}
}
}
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
@sharplet
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/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
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]
@sharplet
sharplet / git
Created Aug 21, 2015
Disable git at the terminal, but still allow shelling out
View git
#!/bin/sh
if [ -t 1 ]; then
echo LOL >&2
exit 1
else
real_git=$(type -a git | head -2 | tail -1 | cut -d" " -f 3)
exec "$real_git" ${*}
fi
@sharplet
sharplet / swift_pros_and_cons.md
Created Oct 22, 2015
A list of pros and cons to adopting Swift on new projects
View swift_pros_and_cons.md

Swift Pros and Cons

Pros

  • 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
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")
}
}
You can’t perform that action at this time.