2015年3月16日 星期一

使用自訂 xib 搭配 Autolayout

先記下來,這篇很重要

http://sebastiancelis.com/2014/06/12/using-xibs-layout-custom-views/

2014年12月12日 星期五

使用 innodb_file_per_table 解決 ibdata1 單一且過大

參考這裡


使用 mysql 配合 innodb 引擎在預設的情況下所有的資料都會儲存在 ibdata1

用久了這個檔案會很大,比較好的作法是把每個資料庫的 ibdata 各別儲存。

先備份全部資料庫

mysqldump -u root -p --all-databases > /home/backup/all.sql

找到 my.cnf 或是 my.ini 並加入 innodb_file_per_table=1
以我使用 EC2 自架 mysql 來說是 /etc/my.cnf
重啟資料庫  #service mysqld restart
進入資料庫
#mysql -uroot -ppassword
檢查是否開啟分類儲存功能
mysql> show variables like '%per_table%';
若已開啟會長得像
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| innodb_file_per_table | ON    |
+-----------------------+-------+

再來把 ibdata1 以及 ib_logfile* 刪掉,此時進入資料庫應該就是空空的了
在還原之前最好先停止網路服務,我曾經還原到一半 ec2 就斷線當機給我看
#service httpd stop
還原
mysql -uroot -p < /home/backup/all.sql

啟用 innodb_file_per_table 後,當刪除資料表(DROP TABLE)、清空資料表(TRUNCATE TABLE),佔用的空見會自動縮減。刪除資料表資料(DELETE),則執行 OPTIMIZE TABLE 來縮減資料表空間。

OPTIMIZE TABLE 資料表名稱

最後補充一下使用別人整理的 innodb_file_per_table 的好處

1. 如果使用軟鏈結將大表分配到不同的分區上,易於管理資料文件
2. 易於監控解决IO資源使用的问题
3. 易於修復和恢復損壞的資料
    3.1 相互獨立,不影響其他innodb表
    3.2 導出導入針對單一table,而不是整個共享table
4. 解決單一文件大小的限制
5. 對於大量的delete操作,更易回收磁碟空間
6. 碎片較少,易於整理optimize table
7. 易於安全檢查
8. 易於備份

2014年11月24日 星期一

Apple Watch Human Interface Guidelines 隨手記


Apple Watch Human Interface Guidelines


Interface Style:

  • Hierarchical. This style matches the navigation style in iOS and is best suited for apps with hierarchical information. In a hierarchical app, users navigate by making one choice per screen until they reach their destination. To navigate to another destination, users must retrace some or all of their steps and make different choices.
    A hierarchical model is typically better than a flat, paginated navigation model for more complex app interactions.
  • Page-based. A paginated interface lets the user navigate between pages of content by swiping horizontally. A page-based interface is best suited for apps with simple data models where the data on each page is not directly tied to the data on the other pages.
    A dot indicator at the bottom of each page shows the user’s place in the set. Keep the total number of pages as small as possible to simplify navigation.

註:二擇一,避免混用


Glances are:
  • Template-based. There are separate templates for the upper and lower portions of the Glance screen. Use Xcode to pick the templates you want and then design your content to those specifications.
  • Not scrollable. All content must fit on a single screen.
  • Read-only. Tapping anywhere on the glance opens the app.
  • Optional. Not all apps need a Glance, and users can select which Glances to display.

註: Glances 非必要,可套版,不可滾動



Notification:

Be sensitive to the frequency with which you send notifications to users. Users might perceive a frequent notifications as annoying and disable notifications for your app on Apple Watch. Always make sure notifications are relevant to what the user wants.


註:有分 short look & long look,版面制式化,小心使用


Layout:


兩種SIZE





Color and Typography
Use black for your app’s background color. A black background blends seamlessly with the device bezel and maintains the illusion of there being no screen edges. Avoid bright background colors in your interface.
Use your app’s key color for branding or status. Every app defines a key color. The system uses this key color for the title string in the upper-left corner of the screen and in notification interfaces to highlight your app name or other key information. You should similarly use the key color as part of the branding of your app.
Use high contrast colors for text. High contrast colors make text more legible.

Use the built-in text styles whenever possible. The built-in styles automatically support Dynamic Type and were designed to look good on Apple Watch.

Prefer the use of a single font throughout your app. Apps can use an additional font for branding purposes, but use that extra font sparingly. Mixing many different fonts can make your app seem fragmented and sloppy. Use the UIFont text styles API to define different areas of text according to semantic usage, such as body or headline.


註:顏色採用高對比,建議使用黑色背景,字型盡量單一且使用內建字型。


Table:


Use row types consistently. You might create different row types to implement your content, headers, and footers. Be consistent in your use of those rows.

Avoid mixing rows with dramatically different types of content. When displaying content, be consistent with the row type you use to display that content. Use other row types only as section breaks or to organize the content rows. Using the same row type for content ensures that rows are sized consistently and are easier to navigate.

Limit the number of table rows displayed at one time. Tables with more than twenty rows of content become cumbersome to scroll through. Display only the subset of rows that are immediately relevant and give the user the option to load more rows.


註:單一cell,避免太多列,超迥10列給user "讀取更多" 的 button.

Button:



Create buttons that span the width of the screen. The creation of full-width buttons is strongly encouraged. If you must put more than one button in the same horizontal space, limit the total number of buttons to two.
Try to match button heights whenever possible. If you have multiple buttons onscreen together, use the same height for each. Buttons


註:寬盡量滿版,最多塞二個button

Image:
Create all image assets as @2x resources. There is no need to create non Retina images.


Dates and Timers:

Use a date object whenever you want to display the current day or time.
Always use a timer label to implement a precise countdown or count-up timer.

註:使用內建的 Dates Label 和 Timer Label


ICON:



























2014年10月19日 星期日

iOS : Audio Trimming

最近在研究 iOS 音樂剪輯/播放這一塊,紀錄一下

Trim :

http://stackoverflow.com/questions/13097331/unable-to-trim-a-video-using-avassetexportsession

http://stackoverflow.com/questions/9698787/ios-audio-trimming

http://stackoverflow.com/questions/21463250/cocoa-avasset-loaded-from-file-has-0-tracks

Export Mediaitem to local file:

http://stackoverflow.com/questions/13925148/exporting-video-from-users-itunes-library

http://stackoverflow.com/questions/4238219/trim-audio-with-ios


2014年9月25日 星期四

xcode plugins


分享咱家技術長推的兩個好用的 XCode Plugins


1. FuzzyAutocompletePlugin

https://github.com/FuzzyAutocomplete/FuzzyAutocompletePlugin/releases

這是一個非常懶惰的Plugins, 原本在寫程式時要依序打 NSStringFromCGRect, Xcdoe 才會跳出選擇讓你選,裝了 Fuzzy 後你可以跳著輸入 NSS RE 就會讓你選擇 NSStringFromCGRect 了。

2. BBUncrustifyPlugin

https://github.com/benoitsan/BBUncrustifyPlugin-Xcode

這個可以簡單的幫你把大家寫的 Code 的格式全部轉成一様,在多人工作的環境下,看起來會像是同一個人寫的。

2014年9月23日 星期二

Linux 找出誰佔據了你硬碟容量&清理mysql 記錄檔

搜尋資料夾檔案大小 du --exclude="proc" | sort -g -r | head



登入mysql


mysql -u root -p


清理 mysql-bin 方法為:

PURGE MASTER LOGS TO 'mysql-bin.010';
PURGE MASTER LOGS BEFORE '2008-12-19 21:00:00';

============================
位於 /var/spool/mail/root 信箱如果滿了,要如何一次清空呢
方法很簡單,只要下達一行指令即可

cp /dev/null  /var/spool/mail/root


2014年9月2日 星期二

App 不在背景執行也可以接收 iBeacon

有點強~

https://community.estimote.com/hc/en-us/articles/203253193-Launching-notifications-in-iOS-when-the-app-is-killed