Working with RESTful Services in CodeIgniter
CodeIgniter is becoming well known for its power as a PHP based web application framework, but it's not often that we see examples of it being used for anything else. Today we'll learn how we can use CodeIgniter to create a RESTful API for your existing web applications, and demonstrate how to interact with your own API or other RESTful web-services, such as Facebook and Twitter.
目前很多网站都使用了 Google Analytics 来跟踪各个页面的访问情况,但经常会出现页面过慢,JS 执行错误等问题,导致统计的结果不准确。现在 Google 提供了一个新的功能─异步跟踪:
- Faster tracking code load times for your web pages due to improved browser execution
- Enhanced data collection and accuracy
- Elimination of tracking errors from dependencies when the JavaScript hasn't fully loaded
JS 代码片段:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
更多信息…
New language features in Java 7
I’m just back from the Devoxx conference in Antwerp. An update was given on the new language changes that will be in Java 7. The JDK currently has a release date of September 2010.
Here are 7 of the new features that have been completed:
* Language support for collections
* Automatic Resource Management
* Improved Type Inference for Generic Instance Creation (diamond)
* Underscores in numeric literals
* Strings in switch
* Binary literals
* Simplified Varargs Method Invocation
很多特性都非常有意思,比如:
List<String> list = new ArrayList<String>();
list.add("item");
String item = list.get(0);
Set<String> set = new HashSet<String>();
set.add("item");
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("key", 1);
int value = map.get("key");
可以变为:
List<String> list = ["item"];
String item = list[0];
Set<String> set = {"item"};
Map<String, Integer> map = {"key" : 1};
int value = map["key"];
最有意思的是数字:
int one_million = 1_000_000;

使用 PHP curl 抓取页面时,可以设置 cookie 保存的文件,示例代码:
<?php
$cookie_path = 'cookie.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
//....
?>
特别需要注意的是,在完成抓取之后,需要把 cookie 文件删除,否则下次抓取时会自动使用原有的 cookie 数据,从而导致一些预想不到的错误(我们今天就被这个问题折腾了很久
)。
Chunking Large Queries with Iterators in PHP
When executing large queries it's usually best not to load the whole result set in one go. Memory isn't infinite and PHP isn't renowned for handling it very well. So the obvious answer is to chunk the large query in to lots of smaller queries. This is a simple method I use for hiding the fact the query is being chunked behind an iterator.