Skip to content

Instantly share code, notes, and snippets.

Max Howell mxcl

Block or report user

Report or block mxcl

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
View UIImage+darken.swift
extension UIImage {
func darkened() -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 0)
defer { UIGraphicsEndImageContext() }
guard let ctx = UIGraphicsGetCurrentContext(), let cgImage = cgImage else {
return nil
}
// flip the image, or result appears flipped
View PMK5.swift
import Foundation
// Caveats (specify fixes alongside)
// * Promise { throw E.dummy } is interpreted as `Promise<() throws -> Void>` of all things
// * Promise(E.dummy) is interpreted as `Promise<E>`
// Remarks:
// * We typically use `.pending()` to reduce nested insanities in your backtraces
View swift-self-build
#!/bin/bash
#
# Faster toolchain build: skips as much as possible.
#
# To use this toolchain from the command line:"
# export TOOLCHAINS=$(whoami)
#
# we build to the same prefix every time (instead of building
# to a versioned prefix) because every time the prefix changes
# *everything* rebuilds.
@mxcl
mxcl / Lockfile.md
Last active Mar 13, 2016 — forked from aciidb0mb3r/Lockfile.md
Lock file proposal
View Lockfile.md

Dependency Locking with the Swift Package Manager

Introduction

In a vibrant packaging ecosystem, dependencies update continuously with bug-fixes and feature improvements. When working against a collection of dependencies, especially in a team, it is vital to lock the graph and update it so that all team members receive the exact same graph at the same time.

The typical flow for this in dependency management is to create and use a dependency “Lockfile”.

Motivation

View pmk-swift2.swift
firstly {
NSURLSession.GET(url)
}.then { (dict: NSDictionary) in
//
}.catch { (err: Error.JSONError) in
// The token `JSONError` is defined in PromiseKit
}.catch { (err: Error.HTTPError) in
switch err.statusCode {
case 400: //
//
View mergesort.swift
import Darwin //.C.stdlib
// updated for Swift 2.0 beta4
private func merge<T: Comparable>(a: ArraySlice<T>, _ b: ArraySlice<T>, mergeInto acc: ArraySlice<T> = []) -> ArraySlice<T> {
guard let aF = a.first, bF = b.first else {
return acc + a + b
}
return aF < bF
? merge(dropFirst(a), b, mergeInto: acc + [aF])
View XMPPFramework.podspec.json
{
"name": "XMPPFramework",
"version": "3.6.4",
"platforms": {
"ios": "5.0",
"osx": "10.7"
},
"license": {
"type": "BSD",
"file": "copying.txt"
View gist:2102a833a33e25b382be
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
float y = scrollView.contentOffset.y;
////// parallax
CGAffineTransform transform;
BOOL clip = YES;
y -= 320;
if (y < -320) {
float const required_scale = y / -320;
View BlurryVC.swift
import UIKit
class BlurryVC: UIViewController {
override func loadView() {
view = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
}
}
class ViewController: UIViewController {
View gist:e83aa653da7fec6f3ce4
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) in
if error == nil {
self.latitudeArray = objects.map{ $0["latitude"]! as Double }
} else {
println(error)
}
}
You can’t perform that action at this time.