Skip to content

Instantly share code, notes, and snippets.

View soapyigu's full-sized avatar
🎯
Focusing

Soap soapyigu

🎯
Focusing
  • Netflix
  • San Francisco
View GitHub Profile
@soapyigu
soapyigu / GetImage.swift
Created January 22, 2023 22:21
Get an image from a url
// Convention: using GCD and URLSession
import Foundation
import UIKit
enum NetworkError: Error {
case invalidURL
case noData
case failedRequest
case returnedError
}
class NotificationCenter {
static let shared = NotificationCenter()
// notification to (class name and closures)
private var notificationsStorage = [String: [(String: [(String, Any) -> Void)]]]()
private init() { }
func addObserver(_ class: Any?, name: String, closure: @escaping (String, Any) -> Void) { }
// https://stackoverflow.com/questions/26028918/how-to-determine-the-current-iphone-device-model
import SystemConfiguration
import UIKit
public extension UIDevice {
static let modelName: String = {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
// https://stackoverflow.com/questions/26028918/how-to-determine-the-current-iphone-device-model
func machineName() -> String {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
return machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
#import <FBRetainCycleDetector/FBRetainCycleDetector.h>
self.block = ^{
NSLog(@"%@", self);
};
FBRetainCycleDetector *detector = [FBRetainCycleDetector new];
[detector addCandidate:self];
NSSet *retainCycles = [detector findRetainCycles];
NSLog(@"%@", retainCycles);
@interface ViewController ()
@property (nonatomic, copy) void (^block)(void);
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
@soapyigu
soapyigu / WorldCup.ics
Created June 13, 2018 06:26
FIFA 2018 WORLD CUP SCHEDULE
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY: [A] 🇷🇺Russia vs. 🇸🇦Saudi Arabia
DTSTART;TZID=America/Los_Angeles:20180614T080000
DTEND;TZID=America/Los_Angeles:20180614T094500
END:VEVENT
@interface Queue<__covariant ObjectType> : NSObject
- (void)enqueue:(ObjectType)value;
- (ObjectType)dequeue;
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Queue<Sub *> *subQueue = [[Queue alloc] init];
Queue<Sup *> *supQueue = subQueue; // Warning: Incompatible pointer types initializing 'Queue<Base *>' with an expression of type 'Queue<Sub *>'
[supQueue enqueue:[Sub new]];
}
return 0;
int main(int argc, const char * argv[]) {
@autoreleasepool {
Queue<NSString *> *stringQueue = [[Queue alloc] init];
[stringQueue enqueue:@"abc"]
Queue<NSNumber *> *numberQueue = [[Queue alloc] init];
[numberQueue enqueue:@123];
[numberQueue enqueue:@"abc"]; // Warning: Incompatible pointer types sending 'NSString *' to parameter of type 'NSNumber *'