This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CoreFoundation/CoreFoundation.h> | |
std::string CIdHelper::getCId(int env) { | |
CFStringRef bundle_id = CFSTR("bundle_id"); | |
CFStringRef key = CFSTR("key"); | |
CFPropertyListRef cid = CFPreferencesCopyAppValue(key, bundle_id); | |
if (!cid) { | |
return {}; | |
} | |
char buffer[1024]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat { | |
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude) | |
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil) | |
return ceil(boundingBox.height) | |
} | |
func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat { | |
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIView { | |
func roundCorners(corners: UIRectCorner, radius: CGFloat) { | |
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
let mask = CAShapeLayer() | |
mask.path = path.cgPath | |
layer.mask = mask | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension NSView { | |
var image: NSImage? { | |
guard let bitmapImageRep = bitmapImageRepForCachingDisplay(in: bounds) else { return nil } | |
cacheDisplay(in: bounds, to: bitmapImageRep) | |
guard let cgImage = bitmapImageRep.cgImage else { return nil } | |
return NSImage(cgImage: cgImage, size: bounds.size) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func radixSort(nums []int) []int{ | |
maxValue := maxValueOfList(nums...) | |
a := 1 | |
for k:=0;a<=maxValue;k++{ | |
buckets := map[int][]int{} | |
for i:=0;i<10;i++{ | |
buckets[i] = []int{} | |
} | |
for _,num := range nums{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@discardableResult | |
public func synchronized<T>(_ lock: AnyObject, closure:() -> T) -> T { | |
objc_sync_enter(lock) | |
defer { objc_sync_exit(lock) } | |
return closure() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def progress(percent,width=50): | |
if percent >= 100: | |
percent=100 | |
show_str=('[%%-%ds]' %width) %(int(width * percent/100)*"#") | |
print('\r%s %d%%' %(show_str,percent),end='') |