Skip to content

Instantly share code, notes, and snippets.

View kaishin's full-sized avatar

Reda Lemeden kaishin

View GitHub Profile
@kaishin
kaishin / Example.swift
Last active March 18, 2023 12:14
StickySheet – A sticky sheet implementation for SwiftUI
enum PresentedSheet: String, Identifiable {
case sticky, standard
var id: String {
return self.rawValue
}
}
extension String: Identifiable {
public var id: String {
@kaishin
kaishin / NSColor+isLight.h
Last active October 14, 2022 01:09
Programmatically determine the perceived lightness of a color. More details on: http://robots.thoughtbot.com/closer-look-color-lightness + Online tool: http://thoughtbot.github.io/color-lightness-test/
#import <Cocoa/Cocoa.h>
@interface NSColor (isLight)
- (BOOL)isLight;
@end
SwiftUI Headers
#snippets
import Combine
import CoreData
import CoreFoundation
import CoreGraphics
import CoreText
import Darwin
@kaishin
kaishin / ContentView.swift
Created June 10, 2022 07:59
PhotosPicker WWDC Sample
import PhotosUI
import CoreTransferable
import SwiftUI
struct ContentView: View {
@ObservedObject var viewModel: FilterModel = .shared
var body: some View {
NavigationStack {
Gallery()
@kaishin
kaishin / UIColor+isLight.h
Last active May 19, 2021 06:22
Get whether a color is dark or light using either luminance or lightness.
#import <UIKit/UIKit.h>
@interface UIColor (isLight)
- (CGFloat)lightness;
- (CGFloat)perceivedLightness;
- (CGFloat)perceivedLightnessW3C;
- (BOOL)isLight;
- (BOOL)isPerceivedLightW3C;
- (BOOL)isPerceivedLight;
@kaishin
kaishin / snapshot.swift
Created January 10, 2016 14:29
NSView Snapshot
extension NSView {
var snapshot: NSImage {
guard let bitmapRep = bitmapImageRepForCachingDisplayInRect(bounds) else { return NSImage() }
bitmapRep.size = bounds.size
cacheDisplayInRect(bounds, toBitmapImageRep: bitmapRep)
let image = NSImage(size: bounds.size)
image.addRepresentation(bitmapRep)
return image
}
}
@kaishin
kaishin / dataSize.m
Created June 1, 2014 21:17
Log NSData size in a human-readable format.
NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:data.length countStyle:NSByteCountFormatterCountStyleFile]);
@kaishin
kaishin / ATS.plist
Created November 6, 2016 17:35
ATS Sample
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>redalemeden.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTKemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
@kaishin
kaishin / threadCheck.m
Last active December 27, 2015 14:59
My concurrency homie. Sprinkle some of it inside and around your blocks and concurrency will never come back to haunt you again.
NSLog([NSThread currentThread] == [NSThread mainThread] ? @"❇️ Main thread, it is." : @"♒️ Doesn't look like main thread around here...");
@kaishin
kaishin / asset.m
Created July 1, 2013 10:35
Get statusBar window
UIWindow *statusBar = [[UIApplication sharedApplication] performSelector:@selector(statusBarWindow)];