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
let testBundle = Bundle(for: type(of: self)) | |
let fileURL = bundle.url(forResource: "imageName", withExtension: "png") |
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
Product.group_by{|x| [x.legacy_id, x.company]} | |
.flat_map{|_,x| x.drop(1)} | |
.delete_all | |
Product.where.not(id: Product.group(:legacy_id, :company).pluck('min(products.id)')) | |
.delete_all | |
delete from products | |
where id not in ( | |
select min(p.id) from products p group by p.legacy_id, p.company |
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
MyViewClass* myViewObject = [[[NSBundle mainBundle] loadNibNamed:@"MyViewClassNib" owner:self options:nil] objectAtIndex:0] |
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
AVAsset *asset = [AVAsset assetWithURL:url]; | |
CMTime duration = [asset duration]; | |
CMTime snapshot = CMTimeMake(duration.value * progress, duration.timescale); | |
AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset]; | |
CGImageRef imageRef = [generator copyCGImageAtTime:snapshot actualTime:nil error:nil]; | |
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef]; | |
CGImageRelease(imageRef); |
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
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center | |
NULL, // observer | |
onNotifyCallback, // callback | |
CFSTR("com.apple.system.config.network_change"), // event name | |
NULL, // object | |
CFNotificationSuspensionBehaviorDeliverImmediately); | |
static void onNotifyCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) | |
{ | |
NSString* notifyName = (NSString*)name; |
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 setDefaultRealmForUser(username: String) { | |
var config = Realm.Configuration() | |
config.fileURL = config.fileURL!.deletingLastPathComponent().appendingPathComponent("\(username).realm") | |
Realm.Configuration.defaultConfiguration = config | |
} |
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
+ (instancetype)sharedInstance { | |
static dispatch_once_t once; | |
static id instance; | |
dispatch_once(&once, ^{ | |
instance = [self new]; | |
}); | |
return instance; | |
} |