Skip to content

Instantly share code, notes, and snippets.

View 0oneo's full-sized avatar
😃
Go Li

0oneo 0oneo

😃
Go Li
  • 阿里本地生活
  • Shanghai
View GitHub Profile
NSArray *images = @[@"http://example.com/image1.png",
@"http://example.com/image2.png",
@"http://example.com/image3.png",
@"http://example.com/image4.png"];
dispatch_queue_t imageQueue = dispatch_queue_create("Image Queue",NULL);
for (NSString *urlString in images) {
dispatch_async(imageQueue, ^{
// pls check http://t.cn/z8ncg24
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[weakself.tableView reloadData];
}];
[weakself.tableView beginUpdates];
[weakself.tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
[weakself.tableView endUpdates];
[CATransaction commit];
@0oneo
0oneo / NSDateFormatter's right usage
Created October 12, 2013 08:20
NSDateFormatter is not thread safe
// test code that generate the error
for (int i = 0; i < 1000; i++) {
NSDate *date= [NSDate date];
NSString *queueName = [NSString stringWithFormat:@"queue%i", i];
dispatch_queue_t testqueue = dispatch_queue_create([queueName cStringUsingEncoding:NSUTF8StringEncoding], NULL);
dispatch_async(testqueue, ^{
NSDateFormatter *ndf = [BXAppDelegate dateFormatter];
DDLogInfo(@"%@", [ndf stringFromDate:date]);
});
}
@0oneo
0oneo / set view's background
Created November 18, 2013 16:04
set background of a view, see link
UIImage *image = [UIImage imageNamed:@"name.png"];
view.layer.contents = (id) image.CGImage;
// 如果需要背景透明加上下面这句
view.layer.backgroundColor = [UIColor clearColor].CGColor;
/*
* armv7sconvert <infile> <outfile>
* Switches CPU subsystem type to armv7s
*
* By Matt Galloway - http://www.galloway.me.uk/2012/09/hacking-up-an-armv7s-library/
*
* Based on g3spot.c from http://redbutton.sourceforge.net (c) Simon Kilvington, 2009
*/
#include <stdio.h>
@0oneo
0oneo / changeExtension
Created May 25, 2014 07:59
change file name extension in batch
#!/bin/bash
directoryName="$1"
extension="$2"
regex='.+'
if ! [[ $extension =~ $regex ]]; then
echo "Usage: changeExtension directory newExtension";
exit 1;
fi
@0oneo
0oneo / wwdc download url
Created June 7, 2014 15:27
获取wwdc session中的视频的下载链接
import re
import urllib2
s = urllib2.urlopen("https://developer.apple.com/videos/wwdc/2014/").read()
match = re.findall(r'http://devstreaming.apple.com/[\w/\d\.-]+hd[\w/\d\.]+mov\?dl=1', s)
print '\n'.join(match)
@0oneo
0oneo / UIScrollView with masonry
Last active October 12, 2017 12:38
vertical and Horizontal scrollview using masonry
@interface ViewController ()
@property (strong, nonatomic) UIScrollView* vScrollView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
@0oneo
0oneo / whatsapp-image-compression
Last active August 29, 2015 14:27 — forked from akshay1188/whatsapp-image-compression
Whatsapp like image compression
- (UIImage *)compressImage:(UIImage *)image{
float actualHeight = image.size.height;
float actualWidth = image.size.width;
float maxHeight = 600.0;
float maxWidth = 800.0;
float imgRatio = actualWidth/actualHeight;
float maxRatio = maxWidth/maxHeight;
float compressionQuality = 0.5;//50 percent compression
if (actualHeight > maxHeight || actualWidth > maxWidth) {
@0oneo
0oneo / .m
Created August 22, 2015 04:21
cancel dispatch after
//
// SpacemanBlocks.h
//
// Created by Jerry Jones on 12/11/11.
// Copyright (c) 2011 Spaceman Labs. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef void(^SMDelayedBlockHandle)(BOOL cancel);