Skip to content

Instantly share code, notes, and snippets.

import UIKit
import Photos
private func imageWithImage(originImage:UIImage, targetSize:CGSize, contentMode: PHImageContentMode) -> UIImage {
let originSize = CGSize(width: originImage.size.width * originImage.scale,
height: originImage.size.height * originImage.scale)
let originRatio = originImage.size.width / originImage.size.height
let targetSizeRatio = targetSize.width / targetSize.height
var newSize: CGSize;
@tonycn
tonycn / currency_format
Last active June 23, 2016 09:59
currency NSLocale
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setLocale:[NSLocale currentLocale]];
NSLog(formatter.currencyCode);
NSLog([formatter stringFromNumber:@100]);
formatter = [[NSNumberFormatter alloc] init];
[formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
@tonycn
tonycn / git_commands_get_started
Last active August 29, 2015 14:19
Git commands
git clone git://xxx
git remote add upstream git://xxx
# create branch to develop
git checkout -b dev
git add file1
git commit ...
# fetch and rebase to upstream/master
git fetch upstream
@tonycn
tonycn / git_bugfix_branch_development
Last active August 29, 2015 14:17
git bugfix development
git tag -a v1.5.1
git push —tags origin HEAD
#新建branch继续开发
git checkout -b 1.5.1-bugfix
# 一些代码更改
git commit -a -m 'bugfix commit'
# commit : e1d3f…
git push origin 1.5.1-bugfix
@tonycn
tonycn / linux_sa_commands
Last active August 29, 2015 14:17
useful commands
#############################################
### Use watch to dump networking info
#############################################
watch -n 30 /root/script/dump_networking.sh &>/dev/null &
!/bin/sh
file_name=`date +%Y_%m_%d_%H_%M_%S`'.log'
1) 试用 file 查看arch,
$ file libxiamiMusic_arm7.a
2) 提取各个arch的lib
lipo libxiamiMusic.a -thin armv7 -output libxiamiMusic_arm7.a
lipo libxiamiMusic.a -thin armv7s -output libxiamiMusic_arm7s.a
3) 去除重复
方法- 解压处理单个arch的lib,
1. ar x libxiamiMusic_arm7.a
@tonycn
tonycn / mysql_charset
Created July 24, 2014 06:31
mysql character set
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
@tonycn
tonycn / WebViewImageCache
Created July 23, 2014 05:02
iOS webview cache
//
// WebViewImageCache.m
// DoubanShuo
//
// Created by Jianjun Wu on 7/1/11.
// Copyright 2011 Douban Inc. All rights reserved.
//
#import "WebViewImageCache.h"
#import "UserAppPreference.h"
to define : image size, position
{
id:0,
type: 'pic',
content : {
title: "",
pic: "http://img3.douban.com/view/status/median/public/40feb715b79354c.jpg",
share_url:""
}
@tonycn
tonycn / gif_to_mp4
Last active August 29, 2015 14:03
gif to mp4
[ Finnaly with ffmpeg 2.2.4 ]
ffmpeg -f gif -i animation.gif -c:v libx264 -r 30 -pix_fmt yuv420p animation2.mp4
[ install ffmpeg ]]
sudo add-apt-repository ppa:samrog131/ppa
sudo apt-get update
sudo apt-get install ffmpeg-real
- To check if ffmpeg was successfully installed
cd /opt/ffmpeg/bin