Skip to content

Instantly share code, notes, and snippets.

View luowei's full-sized avatar

luowei luowei

View GitHub Profile
@luowei
luowei / jurpleConsole.c
Created January 24, 2021 01:19
jurpleConsole - a clone of Apple's purple_console tool, used to connect from your Mac to services on the i-Device (jailbroken or not) via lockdownd using the private MobileDevice.framework.
#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
@luowei
luowei / handle_dispatch_source.m
Last active December 11, 2020 14:28
dispatch source 非阻塞读写文件、监听文件、子进程
//非阻塞读
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) {
@luowei
luowei / SimpleHTTPServerWithUpload.py
Created June 14, 2018 10:17 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/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.
"""
@luowei
luowei / OCExt-NSObject.m
Created August 28, 2017 03:45
NSObject Swizzing
#pragma mark - Swizzling
#import <objc/runtime.h>
@interface NSObject (LWSwizzling)
+ (BOOL)swizzleMethod:(SEL)origSel withMethod:(SEL)altSel ;
+ (BOOL)swizzleClassMethod:(SEL)origSel withMethod:(SEL)altSel;
@luowei
luowei / Useful-Defines.m
Last active November 29, 2017 02:28
更新强弱引用
//在主线程同步安全执行
#define dispatch_main_sync_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}
//在主线程异步安全执行
@luowei
luowei / .gitattributes
Created January 8, 2017 12:16
.gitattributes
# 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
@luowei
luowei / OCExt-UIImage.m
Created November 21, 2016 03:54
UIImage OC扩展
@interface UIImage(Color)
/**
* 给指定的图片染色
*/
- (UIImage *)imageWithOverlayColor:(UIColor *)color;
//根据颜色与矩形区生成一张图片
+ (UIImage *)imageFromColor:(UIColor *)color withRect:(CGRect)rect;
@luowei
luowei / OCExt-UIColor.m
Created November 21, 2016 03:54
UIColor OC扩展
@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
*
@luowei
luowei / OCExt-UIButton.m
Created November 21, 2016 03:53
UIButton OC扩展
@interface UIButton (Ext)
@property(nonatomic, assign) UIEdgeInsets hitTestEdgeInsets;
@end
// -------- Implementation --------
@luowei
luowei / OCExt-NSString.m
Created November 21, 2016 03:53
NSString OC扩展
@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