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 <stdio.h> | |
#include <CoreFoundation/CoreFoundation.h> | |
// Barebones purple_console clone - constructed with some reverse and forward engineering. | |
// | |
// No copyright or license. Feel free to share. Comments/Feedback welcome @http://newosxbook.com/forum/ | |
// | |
// | |
// To compile: gcc jurpleConsole.c -o jc -framework CoreFoundation -framework MobileDevice |
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
//非阻塞读 | |
dispatch_source_t ProcessContentsOfFile(const char *filename) { | |
// Prepare the file for reading. | |
int fd = open(filename, O_RDONLY); | |
if (fd == -1) | |
return NULL; | |
fcntl(fd, F_SETFL, O_NONBLOCK); // Avoid blocking the read operation | |
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
dispatch_source_t readSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, fd, 0, queue); | |
if (!readSource) { |
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
#!/usr/bin/env python | |
"""Simple HTTP Server With Upload. | |
This module builds on BaseHTTPServer by implementing the standard GET | |
and HEAD requests in a fairly straightforward manner. | |
""" |
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
#pragma mark - Swizzling | |
#import <objc/runtime.h> | |
@interface NSObject (LWSwizzling) | |
+ (BOOL)swizzleMethod:(SEL)origSel withMethod:(SEL)altSel ; | |
+ (BOOL)swizzleClassMethod:(SEL)origSel withMethod:(SEL)altSel; |
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
//在主线程同步安全执行 | |
#define dispatch_main_sync_safe(block)\ | |
if ([NSThread isMainThread]) {\ | |
block();\ | |
} else {\ | |
dispatch_sync(dispatch_get_main_queue(), block);\ | |
} | |
//在主线程异步安全执行 |
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
# Auto detect text files and perform LF normalization | |
* text=auto | |
# Custom for Visual Studio | |
*.cs diff=csharp | |
# Standard to msysgit | |
*.doc diff=astextplain | |
*.DOC diff=astextplain | |
*.docx diff=astextplain |
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
@interface UIImage(Color) | |
/** | |
* 给指定的图片染色 | |
*/ | |
- (UIImage *)imageWithOverlayColor:(UIColor *)color; | |
//根据颜色与矩形区生成一张图片 | |
+ (UIImage *)imageFromColor:(UIColor *)color withRect:(CGRect)rect; |
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
@interface UIColor (CrossFade) | |
/** | |
* Fades between firstColor and secondColor at the specified ratio: | |
* | |
* @ ratio 0.0 - fully firstColor | |
* @ ratio 0.5 - halfway between firstColor and secondColor | |
* @ ratio 1.0 - fully secondColor | |
* |
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
@interface NSString (Ext) | |
- (CGFloat)widthWithFont:(UIFont *)font andAttributes:(NSDictionary *)attributes; | |
- (CGFloat)heigthWithWidth:(CGFloat)width andFont:(UIFont *)font andAttributes:(NSDictionary *)attributes; | |
- (void)enumerateCharactersUsingBlock:(void (^)(NSString *character, NSInteger idx, bool *stop))block; | |
@end |
NewerOlder