This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
/** | |
hack to avoid crashes on window close, and remove the window from the | |
NSApplication stack, ie: avoid leaking window objects | |
*/ | |
fileprivate final class WindowDelegate: NSObject, NSWindowDelegate { | |
func windowShouldClose(_ sender: NSWindow) -> Bool { | |
NSApp.removeWindowsItem(sender) | |
return true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A type that has an "empty" representation. | |
public protocol EmptyRepresentable { | |
static func empty() -> Self | |
} | |
extension Array: EmptyRepresentable { | |
public static func empty() -> Array<Element> { | |
return Array() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import CoreGraphics | |
extension NSScreen { | |
var displayID: CGDirectDisplayID { | |
return deviceDescription["NSScreenNumber"] as? CGDirectDisplayID ?? 0 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@testable import <#project#> | |
class StringMD5Test: XCTestCase { | |
func testMD5() { | |
let string = "soroush khanlou" | |
XCTAssertEqual(string.md5, "954d741d14b14002d1ba88f600eee635") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIScrollView+RACSupport.h | |
// Taskworld | |
// | |
// Created by Kittinun Vantasin on 8/5/15. | |
// Copyright (c) 2015 Taskworld. All rights reserved. | |
// | |
@import UIKit; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------- | |
//declaration in PRIVATE scope (for using only in your class) | |
// ---------------------------------- | |
// declare in .m | |
static const int kTweetMaxCharacters = 140; | |
static NSString * const kHelloString = @"HELLO!"; | |
// ---------------------------------- | |
// declaration in PUBLIC scope (for using in other classes too) | |
// ---------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
func first() -> Element? { | |
if isEmpty { | |
return nil | |
} | |
return self[0] | |
} | |
func last() -> Element? { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation UIImage (scale) | |
/** | |
* Scales an image to fit within a bounds with a size governed by | |
* the passed size. Also keeps the aspect ratio. | |
* | |
* Switch MIN to MAX for aspect fill instead of fit. | |
* | |
* @param newSize the size of the bounds the image must fit within. | |
* @return a new scaled image. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIInterfaceOrientationMask vs. UIInterfaceOrientation | |
// As far as I know, a function like this isn't available in the API. I derived this from the enum def for | |
// UIInterfaceOrientationMask. | |
inline BOOL OrientationMaskSupportsOrientation(UIInterfaceOrientationMask mask, UIInterfaceOrientation orientation) { | |
return (mask & (1 << orientation)) != 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
branch=$(git name-rev --name-only HEAD) | |
git rebase --onto HEAD~2 HEAD~1 HEAD | |
git cherry-pick ORIG_HEAD~1 | |
git update-ref refs/heads/$branch $(git rev-parse HEAD) | |
git checkout --quiet $branch | |
# Instead of creating an independant bash script with the code above, | |
# consider simply creating a git alias using the command below. |
NewerOlder