Skip to content

Instantly share code, notes, and snippets.

View wongzigii's full-sized avatar
🎯
Focusing

W0n9 wongzigii

🎯
Focusing
  • Loopring
View GitHub Profile
@Kemmey
Kemmey / gist:b18964d42c5617b2247fa7bacbfa2638
Created May 31, 2020 07:53
Tesla API values to image url - ish
func loadVehicleImage() -> () {
if (!TeslaController.shared().vehicleBackgroundEnabled) {
self.vehicleImage = UIImage()
return
}
//TODO: Currently only show background images for 3 and Y - S and X require more option codes...
if self.vehicleData?.vehicle_config?.car_type == "model3" || self.vehicleData?.vehicle_config?.car_type == "modely"
{
let networking = Networking(baseURL: "https://static-assets.tesla.com")
networking.downloadImage("/v1/compositor/?model=\(carTypeToCode(self.vehicleData?.vehicle_config?.car_type))&view=STUD_3QTR&size=400&bkba_opt=1&options=\(colorNameToCode(self.vehicleData?.vehicle_config?.exterior_color)),\(wheelTypeToCode(self.vehicleData?.vehicle_config?.wheel_type))") { result in
import Foundation
@propertyWrapper struct Notifier<Value> {
private let identifier: String
var wrappedValue: Value? {
didSet {
NotificationCenter.default.post(name: Notification.Name(identifier), object: wrappedValue)
}
}
@x011
x011 / gmail_attachment_downloader.py
Last active January 12, 2024 10:18
Gmail Attachment Downloader 2020
# Made for: https://stackoverflow.com/questions/61366836/download-attachment-from-mail-using-python/
import os
from imbox import Imbox # pip install imbox
import traceback
# enable less secure apps on your google account
# https://myaccount.google.com/lesssecureapps
host = "imap.gmail.com"
@keith
keith / exclusivity.md
Last active May 6, 2021 00:47
The matrix of Xcode build settings to compiler flags for Swift memory exclusivity
  • Compiler flag: -enforce-exclusivity=<value>
  • Build setting: SWIFT_ENFORCE_EXCLUSIVE_ACCESS

Xcode 10.1 & Swift 4.2

  • Compiler default for non optimized builds if you pass no argument is the same as if you passed checked
  • Compiler default for optimized builds if you pass no argument is the same as if you passed unchecked
Configuration Compiler Flag Value Build Setting Description Build Setting Value Notes
@inamiy
inamiy / RxSwift-KVO-methodInvoked-collision.swift
Created April 16, 2018 13:17
RxSwift v4.0.0 KVO + methodInvoked collision
example("Crash") {
let scrollView = UIScrollView()
scrollView.rx.observe(CGSize.self, "contentSize").subscribe()
scrollView.rx.methodInvoked(#selector(UIScrollView.layoutSubviews)).subscribe()
// --- Unhandled error happened: Collision between RxCocoa interception mechanism and KVO. To resolve this conflict please use this interception mechanism first. example ---
// Unhandled error happened: Collision between RxCocoa interception mechanism and KVO. To resolve this conflict please use this interception mechanism first.
// Target: <UIScrollView: 0x7fa397810600; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x60c000042820>; layer = <CALayer: 0x60c00002d660>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0}>
// subscription called from:
@tomisacat
tomisacat / CountDownTimer.swift
Last active November 5, 2021 12:46
A simple count down timer using RxSwift
import RxSwift
func count(from: Int, to: Int, quickStart: Bool) -> Observable<Int> {
return Observable<Int>
.timer(quickStart ? 0 : 1, period: 1, scheduler: MainScheduler.instance)
.take(from - to + 1)
.map { from - $0 }
}
@mahmudahsan
mahmudahsan / ios_detect.swift
Last active July 9, 2021 09:07
iPhone X and other iOS device detection by Swift and Objective-C
struct Device {
// iDevice detection code
static let IS_IPAD = UIDevice.current.userInterfaceIdiom == .pad
static let IS_IPHONE = UIDevice.current.userInterfaceIdiom == .phone
static let IS_RETINA = UIScreen.main.scale >= 2.0
static let SCREEN_WIDTH = Int(UIScreen.main.bounds.size.width)
static let SCREEN_HEIGHT = Int(UIScreen.main.bounds.size.height)
static let SCREEN_MAX_LENGTH = Int( max(SCREEN_WIDTH, SCREEN_HEIGHT) )
static let SCREEN_MIN_LENGTH = Int( min(SCREEN_WIDTH, SCREEN_HEIGHT) )
@lattner
lattner / TaskConcurrencyManifesto.md
Last active April 25, 2024 18:22
Swift Concurrency Manifesto
@mbuchetics
mbuchetics / json.swift
Created June 30, 2017 09:28 — forked from reckenrode/json.swift
Decoding arbitrary JSON with the new Decoder in Swift 4
enum JSON: Decodable {
case bool(Bool)
case double(Double)
case string(String)
indirect case array([JSON])
indirect case dictionary([String: JSON])
init(from decoder: Decoder) throws {
if let container = try? decoder.container(keyedBy: JSONCodingKeys.self) {
self = JSON(from: container)

Note

Apple will reject apps that are using private url schemes (Ugh, Apple....) if they are pretty much obvius. Some apps are rejected and others are not, so, be aware of this issue before implementing any of those URL's in your app as a feature.

Updates

  • [UPDATE 4] iOS 10 update: apparently settings now can be reached using App-Pref instead of prefs
  • [UPDATE 3] For now you just can use url schemes to open your apps's settings with Swift 3.0 (Xcode 8). I'll keep you informed when OS preferences can be reached
  • [UPDATE 2] The openURL() method of UIApplication is now deprecated. You should use application(_:open:options:) instead
  • [UPDATE 1] Not yet tested in iOS 10. It will fail because of policies changes in URL scheme handling.