2008年7月29日星期二

2008年7月28日星期一

如何使用openflashchartV2 dot net library 中的asp.net 控件。

在工具栏上右键,选择项,添加openflashchart.dll,

工具栏上会多出控件openflashchartcontrol


然后就是按照正常的控件使用。

控件中内置了swfobject2.0和相应的open-flash-chart.swf.
所以程序中不在需要这两个文件,不过依然提供了两个属性,方便用户添加外来文件。
为以后使用新版本的swf和swfobject做预留。

2008年7月26日星期六

2008年7月19日星期六

openflashchart V2 .net 新版本

http://openflashchart.svn.sourceforge.net/viewvc/openflashchart/version-2/dot-net-library/written-by-xiao-yifang.tar.gz?view=tar


tor 软件

知道的人不用说,不知道的google search   .

2008年7月16日星期三

openflashchart2 .net实现 五

可以到
sourceforge的站点下载
http://openflashchart.svn.sourceforge.net/viewvc/openflashchart/version-2/dot-net-library/written-by-xiao-yifang/

openflashchart的原作者把它放到了svn上。

2008年7月15日星期二

有趣的问题, 称球

大学时一个老师所做的研究中的一部分。
曾经给我们出过一个题是:
13个球中有1个不知轻重的球,用天平3次称出。
抽象为一般问题是,n次最多可以称出多少球(球中有一个未知轻重的球)

重新做一下。
为了方便说明,规定图例为

第一次4,4称,如果相等的话,
可以得到8个标准的球和5个不知轻重的球。还剩两次机会,简单,不讨论。
如果不相等的话,不妨讨论大于的情况
第一次大于的话,可以得到4个可能重的球,4个可能轻的球,和5个标准球。



称第二次,如下分配:




第二次如果相等的话,在剩下的球中一个可能重的球,2个可能轻的球中,那么第三次的话,在轻重各取一个,与标准的两个球称,如果相等,则剩余的为轻球,大于的话,为参与称重的球中的重球,小于的话,为参与称重的球中的轻球。

第二次如果大于的话,说明存在于左侧的两个可能重球和右侧的一个可能轻球里面。同上。
第二次如果小于的话,说明存在与左侧的可能轻球和右侧的可能重球里面,第三次,取一个与标准球称。


2008年7月14日星期一

openflashchartV2 .net的实现四

实现了一个.net版本

上面的版本中JSON序列化所用的组件需要.net framework 3.5的支持,
对这个项目来说,本身有点太过复杂了,以后修改为支持.net framework 2.0
如果你使用上面的程序,希望可以发一个生成的图片给我,最好包括你们公司的地址:-)
我可以列在下面,谢谢。

关于openflashchart的介绍见
http://teethgrinder.co.uk/open-flash-chart-2/

2008年7月13日星期日

openflashchart2 .net实现 三

如何使用?
有很多种方式,可以在页面上使用openflashchart的图形,此处只演示一种

显示页面,比如叫 Pie.aspx

内容
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pie.aspx.cs" Inherits="Pie" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" src="swfobject.js"></script>

<script type="text/javascript">
swfobject.embedSWF("open-flash-chart.swf", "my_chart", "550", "500",
"9.0.0", "expressInstall.swf",
{"data-file":"datafile/Pie.aspx"}
);
</script>

</head>
<body>
<form id="form1" runat="server">
<div id="my_chart">
</div>
</form>
</body>
</html>

数据由datafile目录下的Pie.aspx生成,Pie.aspx.cs中Page_Load函数的内容为
OpenFlashChart.OpenFlashChart chart = new OpenFlashChart.OpenFlashChart();
chart.Title = new Title("Pie Chart");

OpenFlashChart.Pie pie = new OpenFlashChart.Pie();
Random random = new Random();

List<PieValue> values = new List<PieValue>();
List<string> labels = new List<string>();
for (int i = 0; i < 12; i++)
{
values.Add(new PieValue(random.NextDouble(),"Pie"+i));
labels.Add(i.ToString());
}
pie.Values = values;
//pie.Colour = "#fff";
pie.Colours = new string[]{"#04f","#1ff","#6ef","#f30"};
chart.AddElement(pie);
string s = chart.ToString();
Response.Clear();
Response.CacheControl = "no-cache";
Response.Write(s);
Response.End();

最后的图形为:

openflashchart2 .net实现二

一些图形具有的值具有特定的格式。
如Pie的节点值,可以同时具有 (value值,color颜色),也可以只含有值,不包括颜色,
所以对于Pie来说 ,形如 {12,{12,"#ef0"},3}之类的数组是可以接受的。
对于.net来说,数组中的值只允许一种类型,表示这种值有困难。
实现的时候,先只实现如下格式{{12,null},{12,"#ef0"},{3,null}}保证类型的统一。


为了同时利用已有的代码,抽象出一个泛型类,如图。

openflashchart2 .net 实现的类设计

到目前为止,已经有人用perl ,php实现了openflashchart2的数据层。
此处参考php的实现,来实现.net的结构。不过类的层次继承关系重新组织

以AreaHollow图形为例。
以设计来说,你尽可以做的面面俱到。此处只给出简单的实现,做不得标准:-),另外此处只是实现过程中的设计,或许在实现的过程中会更改:-).
因为此时,我还没有完全实现在.net下的版本。




openflashchart有很多图形,所以给出一个图形的基类ChartBase,方便后面添加多个图形的时候方便。
Title,Legend,都具有Text(名称),Style(样式),此处也让他们共用一个基类。

坐标轴也有一个基类。 OpenflashChart负责整体的控制。


此处的实现,关键的地方是把类转化为相应的JSON结构。采用JSON.net的实现。

最后生成AreaHollow的图像的数据层,将会是这样。
OpenFlashChart.OpenFlashChart chart = new OpenFlashChart.OpenFlashChart();
chart.Title=new Title("AreaHollow");

AreaHollow area = new AreaHollow();
Random random=new Random();
area.Colour = "#0fe";
area.DotSize = 2;
area.Fillalpha = 0.4;
area.Text = "Test";
area.Width = 2;
area.Fontsize = 10;
IList<double> values = new List<double>();
for (int i = 0; i < 12; i++)
values.Add(random.Next(i, i*2));
area.Values = values;
chart.AddElement(area);
XAxis xaxis=new XAxis();
// xaxis.Labels = new AxisLabel("text","#ef0",10,"vertical");
xaxis.Steps = 1;
xaxis.SetRange(0,12);
chart.X_Axis = xaxis;
YAxis yaxis = new YAxis();
yaxis.Steps = 4;
yaxis.SetRange(0,20);
chart.Y_Axis = yaxis;
string s = chart.ToString();
Response.Clear();
Response.CacheControl = "no-cache";
Response.Write(s);
Response.End();

openflashchart 2 在asp.net中使用

openflashchart 2 中重新设计了数据的格式,从1.0中的参数式的格式,改为了基于JSON格式的表示
现在的图形,全部采用JSON的结构式表示,如AreaHollow图形,会表示成。
{
"title": {
"text": "Area Chart"
},
"elements": [
{
"type": "area_hollow",
"fill-alpha": 0.35,
"values": [
0,
0.37747172851062,
0.73989485038644,
1.0728206994506
//省略
],
"width": 1
}
],
"y_axis": {
"min": -2,
"max": 2,
"steps": 2,
"labels": null,
"offset": 0
},
"x_axis": {
"labels": {
"steps": 4,
"rotate": "vertical"
},
"steps": 2
}
}

像以前一样,展现层依然与数据的生成分离。也就是只要最后的数据格式符合JSON的这种形式,
及openflashchart的字段定义。
就可以。所以可以用任何语言实现它的数据层。
幸运的是,目前已经在.net下有多种JSON的实现,用以把数据对象转换成JSON的格式。
下面将会有一系列的文章,来说明openflashchart的.net实现。

2008年7月12日星期六

2008年7月11日星期五

2008年7月8日星期二

.net 3.5 大整数 big integer 支持

System.core.dll中的System.Numberic 命名空间
BigInteger 


2008年7月7日星期一

比较好的一些开源项目

1,mootools
javascript 的framework
个人认为,功能强大,使用简单,速度快。
2,subsonic
处理数据库相关的操作,可以生成代码,它的口号是,All your database belong to us.
3.wix
或许会代替windows install shield ,微软的一些产品的如Office 2007 就是用它做的安装程序。


Resharper 卸载后 Visual Studio 的快捷键和智能提示消失

Resharper的快捷键覆盖了Visual Studio的设置。如果要恢复Visual Studio的快捷键,需要在工具->导入导出配置->重置所有键     就可以了。

2008年7月6日星期日

google blog首字下沉

同样是修改模板中的
css样式,添加
div .entry-content:first-letter{font-size:3em;float:left;}

google,blog的自定义功能实在是很方便啊,与msn space比起来。

设置blog spot使用Google Analytics

google的blog中可以自定义模板,
只要在布局里面的选择修改HTML,然后把Google Analytics的跟踪代码放进去就可以了。
很简单。

piwik 请求


http://dev.piwik.org/trac/wiki/MainSequenceDiagram

2008年7月4日星期五

强大的搜索引擎

google的搜索引擎做的更出众了
自己的帖子写完之后,半小时左右就可以用google搜出来。
速度更新很快。
baidu好像死了。

google treasure hunt -----network 网络寻址

这个自己看吧,本人对网络外行:-(

Question

Below is a diagram of a computer network. The nodes are hosts on the network, and the lines between them are links. A packet is sent out from host F with a destination of 74.1.70.230. Which nodes does the packet pass through on its way to the destination? (include start and final node in your answer)

Network

Here is a network routing table you'll need to determine the path taken:
Node Ip address Routing table entry Routing table entry Routing table entry Default route
A 11.207.188.140 174.179.20.151 => 118.51.156.14 107.254.82.100 => 115.32.2.165 74.1.70.0/24 => 102.41.84.235 104.173.164.71
B 118.51.156.14 74.1.70.230 => 104.173.164.71 115.32.2.165 => 11.207.188.140 102.208.9.0/24 => 115.32.2.165 107.254.82.100
C 107.254.82.100 54.91.191.110 => 102.41.84.235 118.51.156.14 => 26.153.160.156 74.1.70.0/24 => 118.51.156.14 74.1.70.230
D 174.179.20.151 253.172.13.172 => 107.254.82.100 22.245.173.210 => 22.245.173.210 38.202.188.0/24 => 54.91.191.110 74.1.70.230
E 102.208.9.150 174.179.20.151 => 47.198.81.165 108.85.16.8 => 253.172.13.172 26.153.160.0/24 => 108.85.16.8 174.179.20.151
F 253.172.13.172 253.172.13.172 => 38.202.188.8 26.153.160.156 => 47.198.81.165 102.208.9.0/24 => 102.208.9.150 108.85.16.8
G 38.202.188.8 74.1.70.230 => 54.91.191.110 38.202.188.8 => 22.245.173.210 11.207.188.0/24 => 174.179.20.151 253.172.13.172
H 22.245.173.210 11.207.188.140 => 108.85.16.8 38.202.188.8 => 174.179.20.151 107.254.82.0/24 => 54.91.191.110 38.202.188.8
I 108.85.16.8 22.245.173.210 => 102.208.9.150 118.51.156.14 => 253.172.13.172 74.1.70.0/24 => 22.245.173.210 47.198.81.165
J 47.198.81.165 38.202.188.8 => 102.208.9.150 102.208.9.150 => 108.85.16.8 11.207.188.0/24 => 54.91.191.110 253.172.13.172
K 54.91.191.110 115.32.2.165 => 38.202.188.8 118.51.156.14 => 174.179.20.151 38.202.188.0/24 => 22.245.173.210 107.254.82.100
L 74.1.70.230 115.32.2.165 => 102.41.84.235 107.254.82.100 => 104.173.164.71 11.207.188.0/24 => 54.91.191.110 107.254.82.100
M 104.173.164.71 54.91.191.110 => 115.32.2.165 118.51.156.14 => 74.1.70.230 102.41.84.0/24 => 118.51.156.14 11.207.188.140
N 115.32.2.165 22.245.173.210 => 118.51.156.14 47.198.81.165 => 26.153.160.156 38.202.188.0/24 => 11.207.188.140 104.173.164.71
O 26.153.160.156 174.179.20.151 => 74.1.70.230 74.1.70.230 => 102.41.84.235 102.208.9.0/24 => 115.32.2.165 107.254.82.100
P 102.41.84.235 107.254.82.100 => 26.153.160.156 22.245.173.210 => 107.254.82.100 74.1.70.0/24 => 74.1.70.230 11.207.188.140

Enter the nodes the packet passes through below
(Note: Answer must start with F, end with the destination node name, and contain only node names.)

google treasure hunt ----zip

问题:

统计下面zip文件夹中满足下面条件的数据,并把它们的乘积返回。
所有文件名或文件路径中包含foo,且以.txt结尾的文件中的第4行的总数
所有文件名或文件路径中包含EFG ,且以.js结尾的文件中的第5行的总数
提示:如果相应的行不存在,不统计



Question

Here is a random zip archive for you to download:
GoogleTreasureHunt08_18057390569245304937.zip

Unzip the archive, then process the resulting files to obtain a numeric result. You'll be taking the sum of lines from files matching a certain description, and multiplying those sums together to obtain a final result. Note that files have many different extensions, like '.pdf' and '.js', but all are plain text files containing a small number of lines of text.

Sum of line 4 for all files with path or name containing foo and ending in .txt
Sum of line 5 for all files with path or name containing EFG and ending in .js
Hint: If the requested line does not exist, do not increment the sum.

Multiply all the above sums together and enter the product below.
(Note: Answer must be an exact, decimal representation of the number.)


程序:



static Int64 sum(string folder, string ext, string foundstring, Int64 linenum)
{
Int64 result=0;
string[] files = Directory.GetFiles(folder, ext, SearchOption.AllDirectories);
foreach (string file in files)
{
if (file.ToLower().Contains(foundstring))
using (StreamReader reader = new StreamReader(file))
{
Int64 count = 0;
string line;
while ((line=reader.ReadLine())!=null)
{
count++;
if (count == linenum)
{
Int64 temp = Convert.ToInt64(line);
result+=temp;
break;
}
}
}

}
return result;


}

google tresure hunt 机器人

有一个机器人在36x36的格子上的左上角,移动到右下角,每次只能向下,或向右移动一步。

共有多少条路径?

这个问题很简单,组合数学中的问题。


Question

A robot is located at the top-left corner of a 36 x 36 grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

Note: The grid below is 7x3, and is used to illustrate the problem. It is not drawn to scale.

Robot

*Image not to scale.

How many possible unique paths are there?
(Note: Answer must be an exact, decimal representation of the number.)



解法:对于n x m的格子,路径数为组合中 n+m-2个数中n-1的组合数,

分析,机器人共需要走n+m-2步到达目的地。这些步中有n-1步是需要向右的。正好是组合数学中的组合定义。

数目可能比较大,会超出整形的最大值。编程的话,需要大数的支持。

有开源的一些项目可以使用。.net的话,可以用IntX codeplex上的项目。

2008年7月3日星期四

google寻宝 google treasure hunt prime 素数问题

偶然看见的题目,很有意思,一时技痒,试着解决一下:-)
题目翻译如下:
找一个最小的素数,使其满足一下条件:
分别可以表示成连续11,37,347,1157个素数之和。

如41是满足下面条件的最小素数:
同时满足连续3个,和6个的素数之和。
11 + 13 + 17 = 41,
2 + 3 + 5 + 7 + 11 + 13 = 41

题目中的数字是动态生成的。这是给我生成的题目。解法都一样。

Question:

Find the smallest number that can be expressed as
the sum of 11 consecutive prime numbers,
the sum of 37 consecutive prime numbers,
the sum of 347 consecutive prime numbers,
the sum of 1157 consecutive prime numbers,
and is itself a prime number.

For example, 41 is the smallest prime number that can be expressed as
the sum of 3 consecutive primes (11 + 13 + 17 = 41) and
the sum of 6 consecutive primes (2 + 3 + 5 + 7 + 11 + 13 = 41).



此题的答案是:9778121

程序:

        static bool isPrime(Int64 num)
{
if ((num == 2) || (num == 3))
return true;
Int64 sqrti = (Int64)Math.Sqrt(num) + 1;
for (Int64 i = 2; i < sqrti; i++)
{
if (num % i == 0)
return false;
}

return true;
}
static void Main(string[] args)
{
Int64 result = 0;
bool found = false;
Int64 endprime;
Int64 startprime = 2;
Int64 sumtotal = sum(startprime, 1157, out endprime);
Console.WriteLine(sumtotal);
Console.WriteLine(endprime);
while (!found)
{
while (!isPrime(sumtotal))
{
sumtotal = sumtotal + endprime - startprime;
startprime = findPrimeAfter(startprime);
endprime = findPrimeAfter(endprime);

}
Console.WriteLine("find temp prime sum:" + sumtotal);
if (splitprime(sumtotal, 11) && splitprime(sumtotal, 37) && splitprime(sumtotal, 347))
{
result = sumtotal;
found = true;
}
else
{
sumtotal = sumtotal + endprime - startprime;
startprime = findPrimeAfter(startprime);
endprime = findPrimeAfter(endprime);
}

}

Console.WriteLine("result:" + result);


}
static bool splitprime(Int64 prime, Int64 slicenum)
{
Int64 average = prime / slicenum;
Int64 lowprime = findPrimeBefore(average, slicenum);
// Int64 highprime = findPrimeAfter(average, slicenum);
Int64 startprime = lowprime;
Int64 endprime;
Int64 slicetotalnum = sum(startprime, slicenum, out endprime);
while ((startprime < average) && (slicetotalnum <= prime))
{
if (slicetotalnum == prime)
{
Int64 temp = startprime;
Console.Write(prime+"=");
while (slicenum-- > 0)
{
Console.Write(temp + "+");
temp = findPrimeAfter(temp);
}
Console.WriteLine();
return true;
}
slicetotalnum = slicetotalnum + endprime - startprime;
startprime = findPrimeAfter(startprime);
endprime = findPrimeAfter(endprime);

}
return false;
}
static Int64 sum(Int64 startprimenum, Int64 primenum, out Int64 endprimenum)
{
Int64 total = 0;
Int64 prime = startprimenum;
for (int i = 0; i < primenum; i++)
{
total += prime;
prime = findPrimeAfter(prime);
}
endprimenum = prime;
return total;
}
static Int64 findPrimeBefore(Int64 prime)
{
if (prime == 2)
return 2;
if (prime == 3)
return 2;
if (prime % 2 == 0)
prime = prime - 1;
else
{
prime = prime - 2;
}
while (!isPrime(prime) && prime > 0)
{
prime = prime - 2;
}
return prime;
}
static Int64 findPrimeBefore(Int64 prime, Int64 before)
{
while (before-- > 0 && prime > 0)
prime = findPrimeBefore(prime);
return prime;
}
static Int64 findPrimeAfter(Int64 prime, Int64 after)
{
while (after-- > 0)
prime = findPrimeAfter(prime);
return prime;
}
static Int64 findPrimeAfter(Int64 prime)
{
if (prime == 2)
return 3;
if ((prime & 1) == 1)
prime = prime + 2;
else
{
prime = prime + 1;
}
while (!isPrime(prime) && prime > 0)
{
prime = prime + 2;
}
return prime;
}

2008年7月1日星期二

VS2005/2008 字体设置

新发现了一个VS 2005的Theme,
http://www.codinghorror.com/blog/archives/000682.html

效果不错: