Skip to content

Instantly share code, notes, and snippets.

View fethica's full-sized avatar
:octocat:

Fethi El Hassasna fethica

:octocat:
View GitHub Profile
@SergLam
SergLam / DebouncingVC.swift
Created March 9, 2021 09:44
Debounce user input to text / search field - native Swift implementation
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var mySrchBar: UISearchBar!
private var lastSearchTxt = ""
override func viewDidLoad() {
super.viewDidLoad()
}
@artemnovichkov
artemnovichkov / Logging.swift
Created November 21, 2019 04:28
Swift Property Wrapper for logging
@propertyWrapper
struct Logging<T> {
var value: T
init(wrappedValue value: T) {
self.value = value
}
var wrappedValue: T {
@dannote
dannote / final-cut-pro-trial-reset.swift
Last active July 21, 2024 22:00
Final Cut Pro X trial reset
#!/usr/bin/swift
import Foundation
let path = URL(fileURLWithPath: NSString(string: "~/Library/Application Support/.ffuserdata").expandingTildeInPath)
let data = try! NSData(contentsOf: path) as Data
let dictionary = try! NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as! NSDictionary
let mutableDictionary = dictionary.mutableCopy() as! NSMutableDictionary
for (key, value) in mutableDictionary {
@Ravi61
Ravi61 / CustomDateCoding.swift
Created July 13, 2017 15:16
Custom Date Encoding/Decoding
// Custom Date Decoding
jsonDecoder.dateDecodingStrategy = .custom({ (decoder) -> Date in
let data = try decoder.singleValueContainer().decode(String.self)
//perform your operation on obtained string
let disturbance = "01-07-1977"
let formatter = DateFormatter()
formatter.dateFormat = "dd-MM-yyyy"
if data == "First disturbance in force" {
return formatter.date(from: disturbance) ?? Date()
} else {
@shoheiyokoyama
shoheiyokoyama / DispatchWorkItem-cancel.swift
Last active August 15, 2023 17:33
DispatchWorkItem cancel()
let queue = DispatchQueue(label: "queue", attributes: .concurrent)
let workItem = DispatchWorkItem {
print("done")
}
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
queue.async(execute: workItem) // not work
}
workItem.cancel()
@guycalledseven
guycalledseven / manual-uninstall-paragon-ntfs.sh
Last active July 10, 2024 21:30
Manually remove Paragon NTFS v15 leftovers MacOS
# after appcleaner does his magic, do this
sudo rm -rf "/Library/Application Support/Paragon Software/"
sudo rm /Library/LaunchDaemons/com.paragon-software.installer.plist
sudo rm /Library/LaunchDaemons/com.paragon-software.ntfs.loader.plist
sudo rm /Library/LaunchDaemons/com.paragon-software.ntfsd.plist
sudo rm /Library/LaunchAgents/com.paragon-software.ntfs.notification-agent.plist
sudo rm -rf /Library/Filesystems/ufsd_NTFS.fs/
sudo rm -rf /Library/PrivilegedHelperTools/com.paragon-software.installer
sudo rm -rf /Library/Extensions/ufsd_NTFS.kext/
@simme
simme / debounce-throttle.swift
Created December 20, 2016 10:04
Swift 3 debounce & throttle
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
class AppRestService : IAppRestService {
override fun getAppRestService(): IRestService {
val httpClient = OkHttpClient().newBuilder()
val interceptor = Interceptor { chain ->
val request = chain?.request()?.newBuilder()?.addHeader("SomeHeader", "SomeHeaderProperty")?.build();
chain?.proceed(request)
}
httpClient.networkInterceptors().add(interceptor)
val customGson = GsonBuilder().registerTypeAdapter(MyClassCloud::class.java, MyClassCloudDeserializer("1")).create()
val retrofit = Retrofit.Builder().baseUrl(IRestService.URL_BASE).addConverterFactory(GsonConverterFactory.create(customGson)).client(httpClient.build()).build()
@SlaunchaMan
SlaunchaMan / After.swift
Created June 17, 2015 18:38
Getting the Next Element in a Swift Array
extension Array {
func after(item: T) -> T? {
if let index = find(self, item) where index + 1 < count {
return self[index + 1]
}
return nil
}
}
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],