Haibin님의 프로필.。 *゚’゚♪。.:*(¯`•._.•°Wel...사진블로그리스트기타 도구 도움말

.。 *゚’゚♪。.:*(¯`•._.•°Welcome to Barry's Blog°•._.•´¯)*:.。♪*゚’゚・。.

☆*~Let your feelings and comments B logged~*☆

Ding Haibin

사진(1/3)
리스트

Eastwood中文支持

Eastwood是一个模仿Google Chart的制图工具
Eastwood使用JFreeChart作为图标工具,使用Java servlet的方式进行封装,
其URL的编码方式完全按照Google Chart API进行。
这两个工具居然不约而同的对中文不支持,如果标签使用中文表示时,就会出现乱码
 
好在Eastwood是开源的,打开源代码ChartServlet.java加上一行
 
request.setCharacterEncoding("UTF-8");
 
$ant
...
BUILD SUCCESSFUL
Total time: 10 seconds
 
 Tomcat的server.xml修改为使用UTF-8对URI进行编码。
 
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               URIEncoding="UTF-8" />
 
重新发布到Tomcat,搞定,Java的开发速度就是惊人。
 
Google Chart Demo:
 
Where's Google?

Where's Google?

Where's Google?

Where's Google?

Where's Google?

Where's Google?

Where's Google? 

Where's Google? 

Where's Google?

Where's Google? 

Poor support of Live Space for Firefox

When I write and post on my Live Space, duplicated posts were always made,
more evilly, it also tell me wrongly that I had failed to post the article.

err...

Evil of IE non-standard extensions!!

API for "MSN Messenger Now Playing"

It's fun to display what's you're listening to in your MSN Live Messenger
The API is quite simple, just by sending a predefined format of message
to the window "MsnMsgrUIManager", which can be easily achieved by calling
Windows API "FindWindowEx"
Then send a "WM_COPYDATA" within pointer to "COPYDATASTRUCT" data structure
to the found window via "SendMessage"

The format of "COPYDATASTRUCT" is defined below:

dwData = 0x547;
lpData = pointer  to preformatted msg string buffer;
cbData = length in byte of the msg buffer, including null termination

msg string buffer is defined as below:
1. Clear "Now playing"
"\\0Music\\00\\0{0} - {1}\\0\\0\\0\\0\\0"
2. Show "Now playing"
"\\0Music\\01\\0{artist} - {title}\\0{album}\\0{WMID}\\0\\0"
p.s. WMID == 0 (what's WMID?)


Closure

Closure is a special callback/delegate
Let's see the how closure is written within the following languages:
Ruby, C#, Java(JDK7), C++(C++0x)

1.Ruby
def managers(emps)
return emps.select {|e| e.isManager}
end
2. C#
public List<Employee> Managers(List<Employee> emps) {
return emps.FindAll(delegate(Employee e) {
return e.IsManager;
}
}
3. Java
void sayHello(java.util.concurrent.Executor ex) {
ex.execute((){ System.out.println("hello"); });
}
4. C++

void printVec(std::vector<int> const&) {
std::for_each(v.begin(), v.end(),
[](int i){ std::cout << i << ' '; });
}

reference:
1. http://joe.truemesh.com/blog/000390.html
2. http://gafter.blogspot.com/2006/08/closures-for-java.html
3. http://herbsutter.spaces.live.com/Blog/cns!2D4327CC297151BB!785.entry
4. http://martinfowler.com/bliki/Closure.html




C++0x variadic template parameter

See how simple tr1::function can be implemented with this Core improvement

template<typename R, typename... Args>
class invoker_base {
public:
virtual ~invoker_base() { }
virtual R invoke(Args...) = 0;
virtual invoker_base* clone() = 0;
};

template<typename F, typename R, typename... Args>
class functor_invoker : public invoker_base<R, Args...> {
public:
explicit functor_invoker(const F& f) : f(f) { }
R invoke(Args... args) { return f(args...); }
functor_invoker* clone() { return new functor_invoker(f); }
private:
F f;
};

template<typename Signature>
class function;

template<typename R, typename... Args>
class function<R (Args...)> {
public:
typedef R result_type;

function() : invoker (0) { }

function(const function& other) : invoker(0) {
if (other.invoker)
invoker = other.invoker->clone();
}

template<typename F>
function(const F& f) : invoker(0) {
invoker = new functor_invoker<F, R, Args...>(f);
}

~function() {
if (invoker)
delete invoker;
}

function& operator= (const function& other) {
function(other).swap(*this);
return *this;
}

template<typename F>
function& operator= (const F& f) {
function(f).swap(*this);
return *this;
}

void swap(function& other) {
invoker_base<R, Args...>* tmp = invoker;
invoker = other.invoker;
other.invoker = tmp;
}

result_type operator()(Args... args) const {
return invoker->invoke(args...);
}
private:
invoker_base<R, Args...>* invoker;
};

int get(int i) {
return i+1;
}

#include <iostream>

int main()
{
function<int(int)> f1(&get);
std::cout << f1(10) << std::endl;
}
Hooray, what a clean implementation.

Three major things:
1. Declaring a variadic template argument
typename... Args
or
class... Args
2. Referring to a variadic template argument
Args..., args...
3. Calculating the length of the template parameter package
sizeof...(Args)