Lasted Stream

增加Google Storage 上传支持 eg. http://www.ohbug.com/dl/19002
Posted at 4 days, 2 hours ago via Web

Xcode 4建立多语言文档New Updated

1.在Resources分类下选择新建文档

2.模板对话框中选择Resource,再选择Strings File

enter image description here

3.将文件命名为“Localizable.strings”并保存

4.选中新创建的“Localizable.strings”文件,打开属性查看器Inspector(View > Utilities > File Inspector)

5.在Localization设置中添语言

enter image description here

6.编辑生成的语言文件

enter image description here

-EOF-

iOS获取用户所安装的(输入法)键盘 Updated

NSUserDefaults里面包含了很多与用户偏好相关的信息,键盘信息也不例外。例如,我们可以获得用户的设置信息:

NSDictionary* defaults = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
NSLog(@"Defaults: %@", defaults);

以上语句会获得一个包含用户设置信息的字典对象。要单独获得键盘信息,直接获取键为“ AppleKeyboards”的数据即可:

NSArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleKeyboards"];
NSLog(@"Keyboards: %@", array);

此时我们便获得用户实际安装的键盘数组对象。

Project源码下载

参考自iOS developer:tips

-EOF-

使用App Engine (GAE) 内置API读写 Google Storage 数据 Updated

App Engine SDK 1.5.5 预览版已经释出。这个版本的各项改进都很给力,其中有一项是已经可以直接从GAE写数据到Google Storage而无需借助boto,由于只有SDK没有文档,使用方法需要自己看源码。经过一个早上的研究,它的使用类似blobstore,示例如下:

from __future__ import with_statement
from google.appengine.api import files

# Create the file
file_name = files.gs.create('/gs/hello-storage/object/demo.txt',acl='public-read-write')

# Open the file and write to it
with files.open(file_name, 'a') as f:
  f.write('data')

# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)
# Read it
with files.open('/gs/hello-storage/object/demo.txt') as f:
    logging.info(f.read(4))

写文件的时候我们使用files.gs.create创建一个Google Storage名称,它的函数原型如下:

def create(filename,
           mime_type='application/octet-stream',
           acl='private',
           cache_control=None,
           content_encoding=None,
           content_disposition=None,
           user_metadata=None):
  """Create a writable blobstore file.

  Args:
    filename: Google Storage object name (/gs/bucket/object)
    mime_type: Blob content MIME type as string.
    acl: Canned acl to apply to the object as per:
      http://code.google.com/apis/storage/docs/reference-headers.html#xgoogacl
    cache_control: Cache control header to set when serving through Google
      storage. If not specified, default of 3600 seconds is used.
    content_encoding: If object is compressed, specify the compression method
      here to set the header correctly when served through Google Storage.
    content_disposition: Header to use when serving through Google Storage.
    user_metadata: Dictionary specifying key value pairs to apply to the
      object. Each key is prefixed with x-goog-meta- when served through
      Google Storage.

  Returns:
    A writable file name for Google Storage file. This file can be opened for
    write by File API open function. To read the file call file::open with the
    plain Google Storage filename (/gs/bucket/object).
  """

读取文件直接使用 files.open访问GS文件的URI,再使用 files.read指定需要读取的字节就行了。

需要注意的是在本地开发的时候,操作的文件数据是不会上传到Google Storage中的;要向GS中写入数据需要携带content_disposition信息用户权限认证,我为了偷懒直接将bucket设成了公共可读写。另外我在测试设置acl的时候也发现上传的文件我自己通过gsutil是没法查看内容的,这部分还没有试验成功,等成功后再将该部分内容补充到这里。

这个API目前只能进行简单的数据读写,还没有其它接口。如果需要保存文件到Google Storage供后期程序调用,需要自己在数据库中记录下相应文件的URI,文件大小等信息以供后期读取。

另外,使用该内置接口能够读写的单文件最大字节数还不得而知。初步估计在5~32M之间。目前1.5.5在GAE服务端已经部署,可以直接进行线上测试。相信距离正式发布已经不远,届时有相应得文档出来以后这些未知事项就会变得明了。

-EOF-

iCloud Storage APIs 使用 Updated

// 传nil获取iCloud容器(iCloud Container)列表中的第一个容器
NSURL *iCloudURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
NSLog(@"%@", [iCloudURL absoluteString]);

NSUbiquitousKeyValueStore *cloudStore = [NSUbiquitousKeyValueStore defaultStore];
[cloudStore setString:[iCloudURL absoluteString] forKey:@"iCloudURL"];//保存一个键值,不同的数据类型有不同的set方法
[cloudStore synchronize]; // 保存,相当于数据库的commit
NSLog(@"%@",[cloudStore stringForKey:@"iCloudURL"]);

[cloudStore removeObjectForKey:@"iCloudURL"];//删除一个键值,remove方法就只有这一个,不用区分数据类型
NSLog(@"%@",[cloudStore stringForKey:@"iCloudURL"]);//获取一个键的值,需要区分数据类型

一起学习C语言(0)--开篇 Updated

子曰:’温故而知新,可以为师矣。‘

这不能算作是完整的教程,只是我的温习笔记,我将之记录下来与大家分享学习的乐趣。

设置C语言编程环境

工欲善其事,必先利其器。学习C语言,除了基本的理论知识外,就是不断的实践,所以首要的问题是设置好C的编译环境。本笔记是在使用Mac OS X 系统上使用“终端”来学习完成,编辑器选用vim。

1.获得C的编译环境

使用Mac OS X的同学可以直接安装随机光碟中的XCode即可直接安装好C编译。

使用Linux的同学可以使用命令 apt-get install build-essential 安装C编译环境。

使用Windows的同学可以下载GCC for Windows或者Visual Studio Express以获得C编译环境。

2.源代码编辑器的选择

IDE固然是不错的东西,但作为刚开始学习编程同学来说,未免太重了,虽然自动创建项目,拥有代码高亮及智能提示等高级功能,但一开始就使用它会降低你学习的灵活性,在刚开始学习一门新语言的过程中,建议使用纯文本编辑器。

可提选择的有很多,如Vim,Emacs,gedit,Notepad等,更多选择可参考 http://zh.wikipedia.org/wiki/文本编辑器列表

Hello world.

按照惯例,每门语言都有 Hello world. 这次也不会少。环境配置好了,打开编辑器,新建文件 learn_c0.c ,输入如下代码:

#include <stdio.h>

int main(){
   puts("Hello world."); 
   return 0;
}

保存并退出。

回到终端(Shell),输入:

make learn_c0

cc learn_c0.c -o learn_c0

这里是使用make命令编译 learn_c0.c 文件,并生成 learn_c0 可执行文件。

然后我们在终端执行生成的文件:

./learn_c0

Hello world.

Hello world.便是我们刚才编译的程序输出的内容。第一个Hello world.能够编译并运行,这也证明我们的编译环境搞好了,接下来可以进行更深入的学习和练习。

你可以尝试将 puts("Hello world."); 语句中的 "Hello world." 改成其它内容,编译并运行,查看程序的输出结果。

AD

Photo Stream

运行状态

运行时间 353D
文章数 20