Skip to content

Instantly share code, notes, and snippets.

extension UIImage {
@objc public func clipWith(_ path: UIBezierPath) -> UIImage? {
let shotest = min(size.width, size.height)
let outputRect = CGRect(x: 0, y: 0, width: shotest, height: shotest)
UIGraphicsBeginImageContextWithOptions(outputRect.size, false, 0)
defer {
UIGraphicsEndImageContext()
}
BOOL PSPDFSystemFunctionOverriddenInCategory(Class theClass, SEL selector, NSString *__autoreleasing* categoryName) {
NSCParameterAssert(theClass);
NSCParameterAssert(selector);
Dl_info info;
if (dladdr(class_getMethodImplementation(theClass, selector), &info)) {
// /System/Library/Frameworks is a common denominator, some methods are in /usr/lib/libobjc.A.dylib
// Custom app is in /private/var/mobile/Containers/Bundle/Application/<UID>/PSPDFCatalog.app/PSPDFCatalog
if (!strstr(info.dli_fname, "/System/Library") && !strstr(info.dli_fname, "/usr/lib")) {
if (categoryName) *categoryName = @(info.dli_sname);
@edwardean
edwardean / PSPDF_KEYPATH.m
Created February 6, 2018 05:50 — forked from steipete/PSPDF_KEYPATH.m
PSPDF_KEYPATH without all the warnings
#define PSPDF_KEYPATH(object, property) (^{ \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wunreachable-code\"") \
_Pragma("clang diagnostic ignored \"-Wimplicit-retain-self\"") \
return ((void)(NO && ((void)object.property, NO)), @#property); \
_Pragma("clang diagnostic pop") \
}())
@edwardean
edwardean / PSPDFEnvironment.m
Created February 6, 2018 05:50 — forked from steipete/PSPDFEnvironment.m
Example for DISPATCH_SOURCE_TYPE_MEMORYPRESSURE (Mac only, since 10.9) ... Since we share code between iOS and mac, I'm trying to be a good system citizen and reimplement the equivalent of UIApplicationDidReceiveMemoryWarningNotification on the Mac.
NSString *const PSPDFApplicationDidReceiveMemoryWarningNotification = @"PSPDFApplicationDidReceiveMemoryWarningNotification";
// Test with sudo memory_pressure -l critical. Don't forget to re-set afterwards!
__attribute__((constructor)) static void PSPDFInstallLowMemoryNotificationWarningMac(void) {
static dispatch_source_t source;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYPRESSURE, 0, DISPATCH_MEMORYPRESSURE_WARN|DISPATCH_MEMORYPRESSURE_CRITICAL, dispatch_get_main_queue());
dispatch_source_set_event_handler(source, ^{
dispatch_source_memorypressure_flags_t pressureLevel = dispatch_source_get_data(source);
@edwardean
edwardean / LinkMapParser.swift
Created February 3, 2018 03:11
解析LinkMap文件
//
// LinkMapParser.swift
//
// Created by lihang on 02/02/2018.
//
import Foundation
public typealias SortDescriptor<Value> = (Value, Value) -> Bool
@edwardean
edwardean / linkmap.js
Created February 2, 2018 06:38 — forked from bang590/linkmap.js
XCode Linkmap Parser
var readline = require('readline'),
fs = require('fs');
var LinkMap = function(filePath) {
this.files = []
this.filePath = filePath
}
LinkMap.prototype = {
start: function(cb) {
static func formaterNumber(_ number: Double) -> String {
if number < 1e4 {
return "\(number)"
}
if number >= 1e4 && number < 1e5 {
return String(format: "%.1f", number / 1e4) + "万"
}
@edwardean
edwardean / gist:cf87d85102c2f8cc6990447373a9e73c
Created December 1, 2017 07:49
iOS get memory retain count
NSMutableDictionary *query = [[NSMutableDictionary alloc] initWithObjects: objects forKeys: keys];
long retainCount = CFGetRetainCount((__bridge CFTypeRef) query);
@edwardean
edwardean / carthage.copy-frameworks.rb
Created October 14, 2017 16:59 — forked from jongraves/carthage.copy-frameworks.rb
carthage copy-frameworks conditionally Xcode build step
built_products_dir = ENV["BUILT_PRODUCTS_DIR"]
frameworks_folder_path = ENV["FRAMEWORKS_FOLDER_PATH"]
srcroot = ENV["SRCROOT"]
dest = File.join(built_products_dir, frameworks_folder_path)
platform = ENV["PLATFORM_DISPLAY_NAME"]
carthage_frameworks_dir = File.join(srcroot, 'Carthage', 'Build', platform)
input_file_count = ENV["SCRIPT_INPUT_FILE_COUNT"].to_i
env = {"SCRIPT_INPUT_FILE_COUNT" => "0"}
@edwardean
edwardean / gist:3a0da8392d9403ff1a8002756a3257d9
Created September 22, 2017 07:45
将NSDate转换到当前时区
NSDate *date = [NSDate date];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:date];
NSDate *localDate = [date dateByAddingTimeInterval:interval];