Skip to content

Instantly share code, notes, and snippets.

@edwardean
edwardean / main.m
Created November 24, 2018 02:53 — forked from michaeleisel/main.m
#import <sys/sysctl.h>
static CFTimeInterval processStartTime() {
size_t len = 4;
int mib[len];
struct kinfo_proc kp;
sysctlnametomib("kern.proc.pid", mib, &len);
mib[3] = getpid();
len = sizeof(kp);
@edwardean
edwardean / gist:3229b320b072058002e3020aec33611a
Created November 9, 2018 16:02
字符以16进制输出
NSString *asss = @"hello";
for (NSInteger i = 0; i < asss.length; i++) {
printf("0x%x, ",[asss characterAtIndex:i]);
}
@edwardean
edwardean / gist:31b883bd75bd57fbb4d432fc25dff96b
Created September 16, 2018 12:02 — forked from 4PixelsDev/gist:7074661
IOS: Take screenshot
- (UIImage*)screenshot
{
// Create a graphics context with the target size
// On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
// On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
extension UIColor {
static var radom: UIColor {
#if swift(>=4.2)
return UIColor(red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1), alpha: 1)
#else
return UIColor(red: CGFloat(arc4random_uniform(256) / 255),
green: CGFloat(arc4random_uniform(256) / 255),
blue: CGFloat(arc4random_uniform(256) / 255), alpha: 1)
extension String {
func removingWhitespaces() -> String {
return components(separatedBy: .whitespaces).joined()
}
}
@edwardean
edwardean / xcode-dev-generate-warnings.sh
Created July 28, 2018 14:28
xcode-enhancement-scripts
# Under the projects folder -> Build Phases -> click on add new build phase on top left corner -> select New Run Script Phase
# Select the Run Script from the dropdown of Build Phase
# let the Shell be the default (/bin/sh)
# Paste below code in the place provided
# This code run every time the project is build
# To create warning (TODO, FIXME) & error msgs (ERROR) comment tags
TAGS="TODO|FIXME"
ERRORTAG="ERROR"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | \
@edwardean
edwardean / Git.md
Created June 6, 2018 05:13
统计Git修改记录
  • 统计从指定日期到现在提交的代码行数,并且排除Pods目录的更改:
git log --author="$(git config --get user.name)" --since='2018-01-01' --pretty=tformat: --numstat ":(exclude)Pods" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -
  • 统计从指定日期到现在的提交次数:
git log --author="$(git config --get user.name)" --since='2018-01-01' --no-merges --oneline | wc -l
addTarget(self, action: #selector(valueChanged(sender:)), for: [.valueChanged])
@objc private func valueChanged(sender: UISwitch) {
CATransaction.setCompletionBlock { [onChange] in
onChange?(sender.isOn)
}
}
The documentation says the block is guaranteed to be called even if there are no animations or the animation was removed. It makes it very safe to use.
@edwardean
edwardean / gist:7d7e7c44810d15eee552a19e3af5dac6
Created February 28, 2018 10:57
Swift Gaussian Blur UIImage
func blurImage(_ image: UIImage, forRect rect: CGRect, radius: Float) -> UIImage? {
let context = CIContext(options: nil)
let inputImage = CIImage(cgImage: image.cgImage!)
guard let filter = CIFilter(name: "CIGaussianBlur") else {
return nil
}
filter.setValue(inputImage, forKey: kCIInputImageKey)
@edwardean
edwardean / gist:c25f36d944d5e69d83d597109f455a88
Created February 28, 2018 07:51
Get UIImage Pixel color
http://www.markj.net/iphone-uiimage-pixel-color/
- (UIColor*) getPixelColorAtLocation:(CGPoint)point {
UIColor* color = nil;
CGImageRef inImage = self.image.CGImage;
// Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue
CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];
if (cgctx == NULL) { return nil; /* error */ }
size_t w = CGImageGetWidth(inImage);