Skip to content

Instantly share code, notes, and snippets.

View interchen's full-sized avatar

Chen Yanjun interchen

  • Xiamen Fujian China
View GitHub Profile
@interchen
interchen / tableViewHeight
Last active August 29, 2015 14:00
heightForRowAtIndexPath
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellId = [self.cells objectAtIndex:indexPath.row];
if ([cellId isEqualToString:kCellId_DevicesCell]) {
return 94.0f;
} else {
UITableViewCell *cell = [self configCellForTableView:tableView cellForRowAtIndexPath:indexPath];
return [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
}
}
@interchen
interchen / camera
Created April 29, 2014 05:35
camera
- (IBAction)handleUploadButton:(id)sender {
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear] == NO
&& [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] == NO) {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:CustomLocalizedString(@"alert_cancel", nil) destructiveButtonTitle:nil otherButtonTitles:CustomLocalizedString(@"picker_photo", nil), nil];
[sheet showFromRect:((UIButton *)sender).frame inView:self.view animated:YES];
} else {
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:CustomLocalizedString(@"alert_cancel", nil) destructiveButtonTitle:CustomLocalizedString(@"picker_camera", nil) otherButtonTitles:CustomLocalizedString(@"picker_photo", nil), nil];
[sheet showFromRect:((UIButton *)sender).frame inView:self.view animated:YES];
}
}
- (UIImage *)resizeImageToSize:(CGSize)targetSize
{
UIImage *sourceImage = captureImage;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
// 调试中文
#define Debug_Language_Chinese 0
// 调试英文
#define Debug_Language_English 0
#define AppLanguage @"appLanguage"
#define AppLanguage_ZH_CN @"zh-Hans"
#define AppLanguage_EN_US @"en"
#if Debug_Language_Chinese
// We don't need to keep making new NSData objects. We can just use one repeatedly.
__block NSMutableData *data = [NSMutableData dataWithLength:blockSize];
__block RNEncryptor *decryptor = nil;
dispatch_block_t readStreamBlock = ^{
[data setLength:blockSize];
NSInteger bytesRead = [cryptedStream read:[data mutableBytes] maxLength:blockSize];
if (bytesRead < 0) {
// Throw an error
}
@interchen
interchen / hex_string_convert
Created May 30, 2014 00:57
Hex String convert
/**将二进制转换成16进制
* @param buf
* @return
*/
public static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
@interchen
interchen / java_aes_ecb_nopadding
Created May 30, 2014 07:10
Java AES ECB NoPadding
// 加密
public static byte[] ecbEncrypt(byte sSrc[], String sKey) throws Exception {
if (sKey == null) {
System.out.print("Key为空null");
return null;
}
// 判断Key是否为16倍数
if (sKey.length() % 16 != 0) {
System.out.print("Key长度不是16倍数");
@interchen
interchen / bundle
Created June 26, 2014 02:46
bundle
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *buildVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
@interchen
interchen / convertNullObject
Created June 26, 2014 14:52
Delete NSNull object in Json object
/**
* 把response中的NSNull对象删除掉
*
* @param response 要处理的对象
*
* @return 删除掉NSNull后的新对象
*/
- (id)convertNullObject:(id)response
{
if (response == nil || [response isKindOfClass:[NSNull class]]) {
UIStoryboard *storyBoard;
if ([language isEqualToString:@"ar"]) {
lan = [[NSLocale preferredLanguages] objectAtIndex:0];
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5Arabic" bundle:bnd];
}
else if([language isEqualToString:@"en"]) {
NSLog(@"DDD ");
lan = [[NSLocale preferredLanguages] objectAtIndex:20];
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5English" bundle:bnd];
}