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
//based on the solution of iamamused : https://gist.github.com/iamamused/1955318 | |
@implementation UIImage (ImageFromPDF) | |
+ (UIImage *)imageLoadedFromPDF:(NSString *)filePath fitSize:(CGSize)fitSize shouldCacheAsAFile:(BOOL)storeInFile{ | |
// Determine if the device is retina. | |
BOOL isRetina = [UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0; | |
// Create a file manager so we can check if the image exists and store the image. | |
NSFileManager *fileManger = [NSFileManager defaultManager]; |
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
//Create an image about the screen of the iOS device | |
+ (UIImage *) screenshot{ | |
UIWindow *mainWindow = [[[UIApplication sharedApplication] windows] firstObject]; | |
if(UIGraphicsBeginImageContextWithOptions != NULL) | |
{ | |
UIGraphicsBeginImageContextWithOptions(mainWindow.frame.size, NO, 0.0f); | |
} else { | |
UIGraphicsBeginImageContext(mainWindow.frame.size); |
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
/** | |
* Upload an image to twitter to get media_id for is | |
* | |
* @param img The image (UIImage or NSData) to be uploaded | |
* @param completion | |
*/ | |
- (void)sendTweetWithImage:(id)img withCompletion:(void(^)(NSNumber *mediaID, NSError *error))completion { | |
NSURL *requestURL = [[NSURL alloc] initWithString:@"https://upload.twitter.com/1.1/media/upload.json"]; |
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)sendTweetWithExperienceInfo:(NSDictionary*)info withCompletion:(void(^)(NSError *error))completion | |
{ | |
//Create basic post info. | |
NSString *status = [self tweetWithDescrition:[expInfo objectForKey:@"statusMessage"] withHeyLetsShortURL:expInfo[@"url"]]; | |
__block NSMutableDictionary *message = [@{ | |
@"status": status, | |
} mutableCopy]; |
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) postTwitterStatus:(NSDictionary *)statusParameters withCompletion:(void(^)(NSError *error))completion { | |
NSAssert(twitterIsSetUp && self.accounts.count > 0, @"To post something to twitter, the twitter API should be set up already"); | |
ACAccount *twitterAccount = [self.accounts objectAtIndex:0]; | |
NSURL * requestURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"]; | |
SLRequest *postRequest = [SLRequest | |
requestForServiceType:SLServiceTypeTwitter |
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
protocol LoadableView { | |
static func loadViewFromNibName(nibName: String) -> Self | |
} | |
extension LoadableView { | |
/** | |
Default protocol implementation to load a view from nib! | |
*/ | |
static func loadViewFromNibName(nibName: String) -> Self { | |
let nibViews = NSBundle.mainBundle().loadNibNamed(nibName, owner: nil, options:nil) |
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
extension NSObjectProtocol where Self: NSManagedObject { | |
static func findAllWithPredicate(searchTerm: NSPredicate?, inContext context: NSManagedObjectContext = NSManagedObjectContext.MR_defaultContext()) -> [Self] { | |
//You can implement the fetchrequest here by yourself, but now I'm using MagicalRecord service to keep it simple | |
return self.MR_findAllWithPredicate(searchTerm, inContext: context) as! [Self] | |
} | |
} | |
Usage (There is no cast required here, but the result is a [AnswerObject]): |
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
// Codility - CountFactors | |
// Count factors of given number n. | |
// https://codility.com/demo/take-sample-test/count_factors/ | |
function solution(N) { | |
// write your code in JavaScript (Node.js 6.4.0) | |
if (N <= 2) { | |
return N; | |
} |
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
// Solution for CountNonDivisible (Codility) | |
// Not the best, just O(N^2)... | |
// https://codility.com/programmers/lessons/11-sieve_of_eratosthenes/count_non_divisible/ | |
function solution(A) { | |
// write your code in JavaScript (Node.js 6.4.0) | |
const divisors = A.map(e => 0); | |
for (let i = 0; i<A.length; i++) { |
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
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
// Not so optimal... | |
// Lesson: https://codility.com/programmers/lessons/17-dynamic_programming/min_abs_sum/ | |
function solution(A) { | |
if (!A.length) { | |
return 0; | |
} |
OlderNewer