This file contains 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
NSLog(@"*** Listing available fonts ***"); | |
for (NSString *familyName in [UIFont familyNames]) { | |
NSLog(@"Family name: %@", familyName); | |
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { | |
NSLog(@"\t- Font name: %@", fontName); | |
} | |
} |
This file contains 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
SEL originalSelector = @selector(userInterfaceIdiom); | |
SEL swizzledSelector = @selector(padUserInterfaceIdiom); | |
Method originalMethod = class_getInstanceMethod([UIDevice class], originalSelector); | |
Method swizzledMethod = class_getInstanceMethod([UIDevice class], swizzledSelector); | |
BOOL didAddMethod = | |
class_addMethod([UIDevice class], | |
originalSelector, | |
method_getImplementation(swizzledMethod), |
This file contains 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 UIApplication (OrientationCorrectedStatusBarFrame) | |
//When device is in landscape orientation, we get CGRect(0, 0, 20, 1024) for statusBarFrame. This corrects the frame based on device orientation. | |
- (CGRect)orientationCorrectedStatusBarFrame | |
{ | |
return [self.delegate.window.rootViewController.view convertRect:self.statusBarFrame fromView:self.delegate.window]; | |
} | |
@end |
This file contains 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
+ (void)copyConstraintsFromView:(UIView *)sourceView toView:(UIView *)destinationView | |
{ | |
NSPredicate *firstPredicate = [NSPredicate predicateWithFormat:@"firstItem = %@", sourceView]; | |
NSPredicate *secondPredicate = [NSPredicate predicateWithFormat:@"secondItem = %@", sourceView]; | |
NSArray *viewConstraints = sourceView.constraints; | |
for (NSLayoutConstraint *constraint in [viewConstraints filteredArrayUsingPredicate:firstPredicate]) { | |
NSLayoutConstraint *replacementConstraint = [self duplicateForConstraint:constraint | |
withFirstItem:destinationView |
This file contains 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
public extension ResultType where Value: CollectionType { | |
public func reduce<U>(initial: U, @noescape combine: (U, Value.Generator.Element) -> Result<U, Error>) -> Result<U, Error> { | |
return analysis( | |
ifSuccess: { | |
$0.reduce(.Success(initial)) { (acc, item) in | |
return acc.flatMap { | |
combine($0, item) | |
} | |
} | |
}, |
This file contains 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 Result | |
public extension ResultType where Value: CollectionType { | |
/// Returns a new Result by mapping each of `Success`es’ values using `transform`, or re-wrapping `Failure`s’ errors. | |
public func mapByItem<U>(@noescape transform: Value.Generator.Element -> U) -> Result<[U], Error> { | |
return flatMapByItem { .Success(transform($0)) } | |
} | |
/// Returns the result of applying `transform` to each of `Success`es’ values, or re-wrapping `Failure`’s errors. | |
public func flatMapByItem<U>(@noescape transform: (Value.Generator.Element) -> Result<U, Error>) -> Result<[U], Error> { |
This file contains 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
static func getPrimes(to n: Int) -> [Int] { | |
let xmody = (1...n) | |
.map { x in (1...n).map { y in x % y } } | |
let primes = xmody | |
.map { mods in | |
mods.enumerate() | |
.filter { y, mod in mod == 0 } | |
.map { y, mod in y + 1 } // divisors for x | |
} |
This file contains 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
func makeThing(withRefTo inThing: Thing) -> Thing { | |
let outThing = Thing() | |
outThing.thing = inThing | |
return outThing | |
} | |
func makeChainOfThings(startingWith inThing: Thing, count: Int) -> Thing { | |
guard count > 1 else { return inThing } | |
let outThing = makeThing(withRefTo: inThing) |
This file contains 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
#delete the existing images | |
find '/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray' -name "*.png" -type f -delete | |
for i in `seq 0 9`; do | |
#edit Contents.json | |
sed -i '' "s/\"filename\" :.*@2x.*/\"filename\" : \"spinner-loop_0$i.png\",/g" "/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray/loading-spinner-frame0$i.imageset/Contents.json" | |
#rename the folder | |
mv "/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray/loading-spinner-frame0$i.imageset" "/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray/gray-spinner-frame0$i.imageset" | |
#copy the new images | |
cp ~/spinner-loop/spinner-loop_0$i.png "/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray/gray-spinner-frame0$i.imageset" |
This file contains 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 ( | |
"crypto/rand" | |
"crypto/rsa" | |
"crypto/x509" | |
"encoding/pem" | |
"errors" | |
"fmt" | |
"time" | |
"gopkg.in/square/go-jose.v2" |
OlderNewer