來源:AWS Computing Checksums
最近在用 AWS Glacier 備份資料時,發現 AWS 回傳的 SHA Checksum 的數值跟系統內建的 sha25sum 不一致,而 AWS Computing Checksums 有提供 Java 跟 C# 版本,因為邏輯很簡單,就順手刻一個 Python 版本:changyy/aws-glacier-sha256-tree-hash
2014年7月1日 星期二
iOS 開發筆記 - 使用自定字型
用法:
- 將字形(MyCustomFontName.ttf)拖進Supporting Files,記得要勾選 "Add to tagets"
- 更新 *.plist 資訊,新增 Fonts provided by application,新增剛剛添加的字型檔名(含副檔名)
- 簡易使用 NSLog(@"MyCustomFont: %@", [UIFont fontWithName:@"MyCustomFontName" size:12]); ,不需副檔名,若 NSLog 輸出不是 null 即可。
2014年6月30日 星期一
iOS 開發筆記 - 初探 Core Text 架構:paragraphs, lines, glyph runs and glyph
Core Text is an advanced, low-level technology for laying out text and handling fonts. The Core Text API, introduced in Mac OS X v10.5 and iOS 3.2, is accessible from all OS X and iOS environments.
先搞懂 String 在 iOS 系統內是如何被畫到 UIView 上頭:
CTFramesetter -> CTFrame (paragraphs) -> CTLine (lines) -> CTRun (glyph runs)簡易的範例:
NSString *utf8String = @"0你1我2他";
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:utf8String];
CTLineRef line = CTLineCreateWithAttributedString((CFMutableAttributedStringRef) attrString);
CFIndex glyphLength = CTLineGetGlyphCount(line);
CFArrayRef runArray = CTLineGetGlyphRuns(line);
CFIndex runArrayLength = CFArrayGetCount(runArray);
for (CFIndex runIndex = 0; runIndex < runArrayLength; runIndex++) {
CTRunRef run = (CTRunRef) CFArrayGetValueAtIndex(runArray, runIndex);
CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName);
for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++) {
CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1);
CGGlyph glyph;
CGPoint position;
CTRunGetGlyphs(run, thisGlyphRange, &glyph);
CTRunGetPositions(run, thisGlyphRange, &position);
//CGContextShowGlyphsAtPositions(context, &glyph, &position, 1);
}
}
NSLog(@"intput: %lu, runArrayLength: %@, glyphLength:%@", [utf8String length], @(runArrayLength), @(glyphLength));
結果:
intput: 6, runArrayLength: 6, glyphLength:6
其中每一個 run 代表同一個 attributed string ,此例數字、中文交替,所以共有 6 個 run。另一個例子:
NSString *utf8String = @"0你1我我2他";
intput: 7, runArrayLength: 6, glyphLength:7
由於有兩個"我"在同一個 run 中,所以只有 6 個 run。
標籤:
core,
core text,
glyph,
glyph runs,
iOS,
lines,
paragraphs,
text
[Linux] 簡易備份加密 MySQL / MySQLDump 資料 @ Ubuntu 14.04
採用 mysqldump 備份 MySQL 資料,可搭配 --where " timestamp < '2014-06-01' AND timestamp >= '2014-05-01' " 等月份備份方式;使用 md5sum 驗證;使用 tar 和 openssl des3 加密:
- $ mysqldump -u root -p myDatabase myTable --where " timestamp < '2014-06-01' AND timestamp >= '2014-05-01' " > mydatabase_mytable.2014-06.sql
- $ find * -name "*.sql" -exec sh -c 'test -e {}.md5sum || md5sum {} > {}.md5sum' \;
- $ find * -name "*.sql" -exec sh -c 'tar -zcf - {} {}.md5sum | openssl des3 -salt -k MyPassword | dd of={}.tgz.des3' \;
$ find * -name "*.sql" -exec sh -c 'test -e {}.md5sum || md5sum {} > {}.md5sum' \; && md5sum -c *.md5sum > /dev/null && find * -name "*.sql" -exec sh -c 'test -e {}.tgz.des3 || tar -zcf - {} {}.md5sum | openssl des3 -salt -k MyPassword | dd of={}.tgz.des3' \;
2014年6月27日 星期五
[PHP] 使用 CURL 測試 Remote Resource Availability @ Ubuntu 14.04
有些程式跑在對岸,就該測測網路是否可取得啦
<?php
function checkRemoteResourceAvailability($target_url) {
$ch = curl_init($target_url);
curl_setopt($ch, CURLOPT_NOBODY, true);
$status = curl_exec($ch) !== false && curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200;
curl_close($ch);
return $status;
}
echo checkRemoteResourceAvailability('http://tw.yahoo.com/favicon.ico') ? "ok" : "not available";
訂閱:
文章 (Atom)
