Skip to content

Instantly share code, notes, and snippets.

Reda Lemeden kaishin

Block or report user

Report or block kaishin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kaishin
kaishin / NSColor+isLight.h
Last active Sep 25, 2019
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/
View NSColor+isLight.h
#import <Cocoa/Cocoa.h>
@interface NSColor (isLight)
- (BOOL)isLight;
@end
View snapshot.swift
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 Jun 1, 2014
Log NSData size in a human-readable format.
View dataSize.m
NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:data.length countStyle:NSByteCountFormatterCountStyleFile]);
View ATS.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>redalemeden.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTKemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
@kaishin
kaishin / UIColor+isLight.h
Last active Jun 16, 2016
Get whether a color is dark or light using either luminance or lightness.
View UIColor+isLight.h
#import <UIKit/UIKit.h>
@interface UIColor (isLight)
- (CGFloat)lightness;
- (CGFloat)perceivedLightness;
- (CGFloat)perceivedLightnessW3C;
- (BOOL)isLight;
- (BOOL)isPerceivedLightW3C;
- (BOOL)isPerceivedLight;
@kaishin
kaishin / threadCheck.m
Last active Dec 27, 2015
My concurrency homie. Sprinkle some of it inside and around your blocks and concurrency will never come back to haunt you again.
View threadCheck.m
NSLog([NSThread currentThread] == [NSThread mainThread] ? @"❇️ Main thread, it is." : @"♒️ Doesn't look like main thread around here...");
@kaishin
kaishin / gray-with-lightness.scss
Created Oct 24, 2013
Return a gray color with a level of lightness.
View gray-with-lightness.scss
@function gray-with-lightness($level: 0.5) {
@if $level > 1 {
$level: 1.0;
} @else if $level < 0 {
$level: 0.0;
}
@return lighten(#000, percentage($level));
}
@kaishin
kaishin / asset.m
Created Jul 1, 2013
Get statusBar window
View asset.m
UIWindow *statusBar = [[UIApplication sharedApplication] performSelector:@selector(statusBarWindow)];
View WKScriptMessage+LeakFix.m
#import <mach-o/dyld.h>
#import <objc/runtime.h>
#import <WebKit/WebKit.h>
@interface WKScriptMessage (WKScriptMessageLeakFix)
@end
@implementation WKScriptMessage (WKScriptMessageLeakFix)
+ (void)load {
View clean.sh
#! /bin/sh
var1=`sudo du -sh /Users/$USER/Library/Logs`
var2=`sudo du -sh /Library/Caches`
var3=`sudo du -sh /Users/$USER/Library/Caches`
var4=`sudo du -sh /var/folders/*`
var5=`sudo du -sh /System/Library/Caches`
var7=`sudo du -sh /Users/$USER/Library/Safari/Downloads.plist`
var8=`sudo du -sh /Library/Logs`
sudo rm -rf /Library/Logs
You can’t perform that action at this time.