神州令 征天庭
年少梦狂吞江海 初醒摆弓射日月;傲雪炎阳铸经纬 孤舟昆仑祭轩辕。
年少梦狂吞江海 初醒摆弓射日月;傲雪炎阳铸经纬 孤舟昆仑祭轩辕。
笑谈浮生千杯过 醉悯天下苍生怜;棋点江山书韬略 峥嵘岁月惘然间。
天罡封臣凌烟阁 中原六路聚英贤;东海陈兵八千万 踏云乘风诛群仙。
怒火燎原斩鬼神 九州归定霜寒剑;古今豪杰出我辈 百年山河一朝卷。
真正的杰出,不是妙用规则的错层,而是极致的偏执于信念. The Crankiness of Belief achieves Great , not the Trick of Regulation.
sudo su
mkdir /opt/python3.0
./configure --prefix=/opt/python3.0 && make && make install
ln -s /opt/python3.0/bin/python3.0 /usr/bin/python3.0
#!/usr/bin/python3.0
# -*- coding:utf-8 -*-
#-------------------------------------------
# Designer : Free.Wang# build the cookie container.
# E-mail : freefis@Gmail.com
# Licence : License on GPL Licence
# Archieved : Dec 27 2008
#-------------------------------------------
from urllib import request,parse
class Makesocket:
""" Build for Make a full HttpRequest via POST/GET """
def __init__(self,loginurl,param):
# login url to recieve param , Post/Get param
self.loginurl = loginurl
self.param = param
def cookie(self):
"""make a Container for Cookie"""
self.cookies = request.HTTPCookieProcessor()
# opener will be used to open Url with cookie.self.opener = request.build_opener(self.cookies) # Login to Get Cookie ,Which will be Push into self.opener.
request.install_opener(self.opener)
def run(self):
""" get Response. """
# serialize the Param
# get request with Cookie.self.encodeparam = parse.urlencode(self.param)
request.urlopen(self.loginurl,self.encodeparam)
conn = self.opener.open("http://www.hellofreefis.com/profile/")
print(conn)
if __name__ == '__main__':
oginurl = "http://www.hellofreefis.com/info_oper.php?tag=signin&pageref="
param = {
'name':"freefis",
'pwd':"freefis' passwod"
}
conn = Makesocket(loginurl,param)
conn.cookie()
conn.run()
function mail() {
var url = "http://testbyfree.appspot.com/gadget/mail/";
var action = "POST";
var param = {};
param['addr'] = $('#addr').attr("value");
param['content'] = $('#content').attr("value");
request(url,param,action);
}
function response(data) {
$("#show").empty();
if (data.text.length>=5) { document.getElementById('show').innerHTML = data.text; }
else { request("http://testbyfree.appspot.com/gadget/mail/"); }
}
function request(url,cgidata,action) {
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(cgidata);
params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
if (action == 'POST') { params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST; }
gadgets.io.makeRequest(url, response, params);
}
var initurl = "http://testbyfree.appspot.com/gadget/mail/";
request(initurl);
# running as Django App on Google App Enging
def mail_page(request):
""" the BLL handle for Http://testbyfree.appspot.com/gadget/mail/ """
if request.POST.has_key('content'):
# this Mail API supported by GAE.
from google.appengine.api import mail
content,addr = request.POST['content'], request.POST['addr']
# the sender master be the admin of GAE APP.
message = mail.EmailMessage(
sender="freefis@gmail.com",
subject="deliver from easywrite"
)
message.to , message.body = addr , content
message.send()
return render_to_response('debug.html',{'info':"ok!","mail":"mail"})
else:
return render_to_response("mail.html")
% 代码来自phofs.erl 模块. phofs is short for Parrallel Highrt-Order Function.
-module(phofs).
-export([mapreduce/4]).
-import(lists, [foreach/2]).
%% F1(Pid, X) -> sends {Key,Val} messages to Pid
%% F2(Key, [Val], AccIn) -> AccOut
mapreduce(F1, F2, Acc0, L) ->
S = self(),
Pid = spawn(fun() -> run(S, F1, F2, Acc0, L) end),
receive
{Pid, Result} ->
Result
end.
% 本段代码的主函数 mapreduce由4个参数组成.
% F1 - Map函数
% F2 - Reduce函数
% Acc0 - 累加器的初始值, 函数最后会返回Acc0的最后累加结果
% L - 运算数据,装载在一个序列中.
run(Parent, F1, F2, Acc0, L) ->
process_flag(trap_exit, true),
ReducePid = self(),
%% 启动 Map运算
%% 对 序列L 中的每一个单元e 进行F1(e)运算. 并为每个单元创建一个进程
%% 此步是ERLANG优势的最大体现.最大化计算性能
foreach(fun(X) ->
spawn_link(fun() -> do_job(ReducePid, F1, X) end)
end, L),
% 获得 序列L 的元素量N.也就是总进程数N,并等待来自N个进程的结果,存到Dict0.
N = length(L),
Dict0 = dict:new(),
Dict1 = collect_replies(N, Dict0),
%% 启动Reduce运算,F2 代表某种Reduce 法则.用户可以自己选择并归的方案.
%% 对Dict1 哈希序列的key-value元素e 运行F2(e)并返回Acc0的累加器.
%% dict:fold函数我研究了好久,后来不断的查看文档,搜结果,讨论(可能本身愚钝:P), 其相当于lists:foldr
%% 也就是相当于python的reduce函数 e.g: reduce(lambda x,y:x+y,range(5)) ===> 1+2+3+4+5.运算集合来自Dict1,运算法则来自F2.
Acc = dict:fold(F2, Acc0, Dict1),
%% 最后把结果返回主函数mapreduce. 并打印.
Parent ! {self(), Acc}.
%% collect_replies 函数 负责处理Map进程的返回结果.并存入某个容器(这里用的是进程字典,同样,Ets,Dts都是可选容器)
%% 当某个Map 任务完成,会自动结束起进程proc,并发送'EXIT',这时候collect_replies会把这个proc 从等待进程序列删除.
>%% 当N=0时,所有map任务完毕,就会把所有相同key值的元素整合到同一个序列中作为新value,并重新对应相应的key.
%% 最后形成一个完整的 key-value Hash Table, 并返回到上面的 Dict1.
collect_replies(0, Dict) ->
Dict;
collect_replies(N, Dict) ->
receive
{Key, Val} ->
case dict:is_key(Key, Dict) of
true ->
Dict1 = dict:append(Key, Val, Dict),
collect_replies(N, Dict1);
false ->
Dict1 = dict:store(Key,[Val], Dict),
collect_replies(N, Dict1)
end;
{'EXIT', _, _} ->
collect_replies(N-1, Dict)
end.
%% Call F(Pid, X)
%% F must send {Key, Value} messsages to Pid
%% and then terminate
do_job(ReducePid, F, X) ->
F(ReducePid, X).