Just launch Wireshark from terminal:
sudo /Applications/Wireshark.app/Contents/MacOS/Wireshark
+ (void)animateWithDuration:(NSTimeInterval)duration | |
timingFunction:(CAMediaTimingFunction*)timingFunction | |
animations:(void (^)(void))animations | |
completion:(void (^)(BOOL finished))completion | |
{ | |
[CATransaction begin]; | |
[CATransaction setAnimationDuration:duration]; | |
[CATransaction setAnimationTimingFunction:timingFunction]; | |
[UIView animateWithDuration:duration animations:animations completion:completion]; |
class ClosureSleeve { | |
let closure: () -> () | |
init(attachTo: AnyObject, closure: @escaping () -> ()) { | |
self.closure = closure | |
objc_setAssociatedObject(attachTo, "[\(arc4random())]", self, .OBJC_ASSOCIATION_RETAIN) | |
} | |
@objc func invoke() { | |
closure() |
extension Int { | |
func times(_ closure: (Int) throws -> Void) rethrows { | |
try (0...self).forEach { | |
try closure($0) | |
} | |
} | |
@discardableResult | |
func times<T>(_ closure: (Int) throws -> T) rethrows -> [T] { | |
var result: [T] = [] |
Just launch Wireshark from terminal:
sudo /Applications/Wireshark.app/Contents/MacOS/Wireshark
extension UIColor { | |
class var random: UIColor { | |
get { | |
let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0 | |
let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white | |
let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black | |
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1) | |
} |
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
auto opMaker = ^NSOperation*(int idx) { | |
return [NSBlockOperation blockOperationWithBlock:^{ | |
sleep(1); | |
NSLog(@"opration %zd finished", idx); | |
}]; | |
}; |
Downloads
did not exist, create a new Downloads
directory.Downloads
exists, remove all *.dvtdownloadableindex
files under it.+ (void)memoryCacheBenchmark | |
{ | |
NSMutableDictionary* dict = [NSMutableDictionary new]; | |
NSCache* cache = [NSCache new]; | |
int count = 10000, repeat = 100; | |
NSMutableArray* keys = [NSMutableArray new]; | |
NSMutableArray* values = [NSMutableArray new]; | |
for (int i = 0; i < count; i++) | |
{ |
- (void)showCamera | |
{ | |
auto showCamera = ^{ | |
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) | |
{ | |
// TODO: alert | |
return; | |
} | |
auto availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; |
#pragma once | |
#import <CoreGraphics/CoreGraphics.h> | |
#pragma mark - CGSize | |
CG_INLINE | |
CGSize operator*(const CGSize& lhs, CGFloat f) | |
{ | |
return (CGSize){lhs.width * f, lhs.height * f}; |