Skip to content

Instantly share code, notes, and snippets.

View fahied's full-sized avatar

Muhammad Fahied fahied

  • Emirates Airlines
  • Dubai
View GitHub Profile
@fahied
fahied / sample.swift
Created October 16, 2021 04:38 — forked from chriseidhof/sample.swift
SwiftUI View Inspection
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
}
}
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {
// Don't forget to add to the project:
// 1. DeepLabV3 - https://developer.apple.com/machine-learning/models/
// 2. CoreMLHelpers - https://github.com/hollance/CoreMLHelpers
enum RemoveBackroundResult {
case background
case finalImage
}
extension UIImage {
@fahied
fahied / jamf.md
Created November 1, 2020 06:03 — forked from prenagha/jamf.md
removing all restrictions on jamf managed macos device - Provided you have root access.

REMOVE JAMF RESTRICTIONS ON MAC

REMOVE ONLY RESTRICTIONS

sudo jamf removeMDMProfile removes all restrictions

sudo jamf manage brings back all restrictions and profiles

REMOVE ALL RESTRICTIONS AND DISABLE JAMF BINARIES WHILE KEEPING YOUR ACCESS TO VPN AND OTHER SERVICES

sudo jamf removeMDMProfile removes all restrictions

@fahied
fahied / modal-view.md
Created July 28, 2020 11:34 — forked from barbietunnie/modal-view.md
Swift Modal View Controller with transparent background

You can do it like this:

In your main view controller:

func showModal() {
    let modalViewController = ModalViewController()
    modalViewController.modalPresentationStyle = .OverCurrentContext
    presentViewController(modalViewController, animated: true, completion: nil)
}

iOS Swift - Cancellable Task with GCD

#iOSBySheldon

I think most of you guys know GCD pretty well. Basically, GCD is a high level API to handle multi-threading operations. We use GCD almost on daily basis to switch thread and execute codes like:

DispatchQueue.main.async { //execute some codes here } 
//switch to main queue and execute codes asynchronously

DispatchQueue.main.sync { //execute some codes here } 
//switch to main queue and execute codes synchronously
@fahied
fahied / etag
Created May 28, 2017 08:01 — forked from kevindelord/etag
How to integrate Etag in Swift
let API_HEADER_FIELD_NONE_MATCH : String = "If-None-Match"
let API_HEADER_FIELD_ETAG : String = "Etag"
let API_REQUEST_SUCCESS : Int = 200
func ETagForURL(urlString: String) -> String? {
// return the saved ETag value for the given URL
return NSUserDefaults.standardUserDefaults().objectForKey(urlString) as String?
}
@fahied
fahied / gist:9f7f8b7323641e4f44b4
Created October 5, 2015 15:59 — forked from saetia/gist:1623487
Clean Install – OS X 10.11 El Capitan

OS X Preferences


most of these require logout/restart to take effect

# Enable character repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false

# Set a shorter Delay until key repeat
@fahied
fahied / logger.xml
Created August 28, 2014 13:06 — forked from saml/logger.xml
<configuration>
<!-- this is plain logback config.
documentation: http://logback.qos.ch/manual/appenders.html
set -Dlogger.level like this:
/usr/java/latest/bin/java -Dconfig.file=/apps/YOURAPP/conf/application.conf -cp /apps/YOURAPP/staged/* -Dlogger.level=WARN play.core.server.NettyServer /apps/YOURAPP
-->

Common Save Patterns

Standard background save

Assuming that you don't care which NSManagedObjectContext is used, and you just want to make some changes and save them in the background, use the following method. 90% of the time, this is what you'll want.

NSManagedObjectSubclass *myObject = [NSManagedObjectSubclass MR_findFirst];

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
# Copyright: Benjamin Weiss (keyboardsurfer) https://github.com/keyboardsurfer
# Under CC-BY-SA V3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode)
# built application files
*.apk
*.ap_
*.jar
!gradle/wrapper/gradle-wrapper.jar
# lint folder