草羹
Every day is a new beginning!
随笔- 8  文章- 0  评论- 0 
博客园  首页  新随笔  联系  管理  订阅 订阅
2010年8月11日
F#对斐波那契数列求和

如题,1+1+2+3+5+8+13+…?

let sumfib n =
    let rec fib x =
        match x with
        | 1 -> 1
        | 2 -> 1
        | x -> fib(x-2)+fib(x-1)   
    let rec addfib x =
        match x with
        | 1 -> 1
        | x -> fib (x)+ addfib (x-1)   
    addfib n

cool!

posted @ 2010-08-11 14:01 草羹 阅读(38) 评论(0) 编辑
2010年7月19日
Isolated Storage in SL4

在Silverlight4中,默认应用程序存储配额是1MB=1024KB=1048576Bytes,可以在SL程序的右键菜单点击查看,如下图1:

如果要申请配额,可以在构造里检查存储配额然后执行一下代码,但要考虑到用户可能阻止该请求:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    Int64 IsoQuota = store.Quota; //单位为bytes
    Int64 requestIsoQuota = 1000;
    if (store.IncreaseQuotaTo(IsoQuota +requestIsoQuota )) //增加到指定大小
    {
       //……
    }
}

执行上述代码将自动提示用户"是否要增加可用存储",结果如下图2:

为了保持默认的1MB默认存储,我们选择“否”以便于后面的测试,如果选择了“是”也没关系,我们可以在应用程序存储选项页中选择该程序删除网站对应的存储使其重新初始化到1MB。在上述代码中,我们请求增加的配额为1000bytes,但是提示请求的大小依然是默认的配额1MB,这里Silverlight是如何显示申请存储配额时请求的大小的呢?

经测试发现,Silverlight对请求的大小采用了小数点保留一位四舍五入的策略,上图的请求的大小实际上就是上述代码中(IsoQuota +requestIsoQuota)除以(1MB*1024*1024)四舍五入保留一位小数的结果。在默认配额情况下,如果请求的配额requestIsoQuota 小于0.05MB=52428.8bytes=52429时,提示请求到的存储大小的小数位将被忽略,但这并不影响实际的存储配额,提示请求的大小依然是1.0MB,如果requestIsoQuota大于或等于0.05MB=52428.8bytes(requestIsoQuota类型为Int64,即requestIsoQuota最小为52429时提示请求大小为1.1MB)将提示请求大小为1.1MB。这里我们可以来验证一下,将requestIsoQuota的值更改为52428,提示请求的大小为1.0M,选择“是”对其进行增加可用存储,然后将requestIsoQuota的值更改为1,这时候的提示是请求的大小为1.1M,这也就从侧面反映了显示出来的请求的大小并不影响实际的存储配额,虽然他们可能是不一致的。

posted @ 2010-07-19 12:17 草羹 阅读(23) 评论(0) 编辑
2009年12月8日
“Out of the box”的解释

1)“Out of box”用于描述某种不确定的事件。常常作为副词来形容某种观点的不确定性。据说这个词同20世纪早期的英国数学家亨利?恩斯特?杜德耐解答一个著名数学谜语的思路相关。题目要求用四条直线连接平面上三乘三分布的九个点,要求一笔连成,也就是在画线的时候笔不能离开纸面。解决这个数学问题的关键在于要克服传统的在三乘三边界内画点的思想,如果将线连接到边界之外,那么问题可以迎刃而解,这样就产生了“Out of box”这个词。相应的,将思维受限这种情况称为“boxed-in”。在IT领域,节奏变化很快,因此每个人都在寻找“Out of box”的思维方式,尝试创新。
用“In the box”表示某种确定的事情。比如,最近有一篇文章讨论了MP3以及盗版音乐的关系,其中引用了一位业内人士的话表示:“主流唱片公司很少关心互联网上的发展,他们的思维就是‘Inside the box’”。
2)"Out of the box"(开箱即用)也用作"off the shelf"(现货供应)的同义词,其含义是指能够满足一定需求的、已经作好了的软件、硬件或两者的结合形式。如不采用,就需要投入专门的人力物力来开发。

out-of-the-box具有“创造性的,独特性,思维不合常规”的意思,但在计算机术语里又可以指“从盒子里拿出来直接可以使用的,也就是即开即用”的意思。"out-of-the-box" is similar to "off-the-shelf",
usually referinng to software/hardware which can be used as is, not requiring extra customisation or add-on components.”

转自:bokee

posted @ 2009-12-08 10:31 草羹 阅读(19) 评论(0) 编辑
2009年12月4日
WCF之消息队列问题

1.Q:此计算机上尚未安装消息队列。

A:控制面板 --> 添加或删除程序 --> 添加/删除Windows组件 --> 勾选消息队列 --> 点击详细信息,将包括MSMQ HTTP支持在内的子组件都勾选上 -->确定完成。

上述方法主要是针对XP操作系统,更多安装步骤参见:官方的安装“消息队列 (MSMQ)”

2.Q:消息队列服务不可用。

A:运行输入services.msc打开服务,找到Message Queuing服务,该服务主要用来为分布式异步消息应用程序提供通信基础结构,启动该服务即可解决消息队列服务不可用的问题。

posted @ 2009-12-04 11:21 草羹 阅读(71) 评论(0) 编辑
2009年9月29日
Applications = Code + Markup读书笔记(2)

1.由RGB三原色组成的颜色空间也叫sRGB颜色空间,sRGB空间将显示点阵图像的做法正式化
The RGB color space implied by byte values of red, green, and blue primaries is sometimes

known as the sRGB color space, where s stands for standard. The sRGB space formalizes

common practices in displaying bitmapped images from scanners and digital cameras on

computer monitors. When used to display colors on the video display, the values of the sRGB

primaries are generally directly proportional to the voltages of the electrical signals

sent from the video display board to the monitor.

2.引入了scRGB的概念,也被称为sRGB64
关于scRGB的Wikipedia: http://en.wikipedia.org/wiki/ScRGB

3.sRGB三原色存储类型为byte,scRGB三原色存储类型为float,由于scRGB可以大于1或小于0,所以scRGB颜

色空间更大

4.Brush体系结构
Object
└─DispatcherObject (abstract)
   └─DependencyObject
      └─Freezable (abstract)
         └─Animatable (abstract)
            └─Brush (abstract)
               ├─GradientBrush (abstract)
               │ ├─LinearGradientBrush
               │ └─RadialGradientBrush
               │
               ├─SolidColorBrush
               │
               └─TileBrush (abstract)
                  ├─DrawingBrush
                  ├─ImageBrush
                  └─VisualBrush

5.关于Brush的动态事件机制,如上结构图,Brush继承自Freezable,而Freezable实现了changed事件,所以

只要Brush改变,都会通知事件的订阅者,该示例中就是通知Window来重绘窗体了,这一点需要和Winform进

行区分,Winform中除非人为处理,否则更改颜色不会触发窗体绘制
Obviously somebody is redrawing the client area every time the brush changes, but it's all

happening behind the scenes. This dynamic response is possible because Brush derives from

the Freezable class, which implements an event named Changed. This event is fired whenever

any changes are made to the Brush object, and this is how the background can be redrawn

whenever a change occurs in the brush.

This Changed event and similar mechanisms are used extensively behind the scenes in the

implementation of animation and other features in the Windows Presentation Foundation.

6.Brushes.PaleGoldenrod和new SolidColorBrush(Colors.PaleGoldenrod)虽然得到的是相同的brush,

但是在使用的时候要考虑到前者不允许被修改,因为前者是一个静态只读属性,还需要注意到Frozen的相关概念
The SolidColorBrush objects returned from the Brushes class are in a frozen state, which

means they can no longer be altered

7.LinearGradientBrush及RadialGradientBrush的一些属性和示例应用

活学活用,切勿读死书 @_@

posted @ 2009-09-29 00:06 草羹 阅读(44) 评论(0) 编辑
2009年9月24日
LINQ学习笔记及总结(1)
摘要: [代码][代码]阅读全文
posted @ 2009-09-24 22:58 草羹 阅读(102) 评论(0) 编辑
2009年9月20日
44个Silverlight 视频讲座
摘要: 01. Silverlight - Hello World 02. Silverlight - Anatomy of an Application 03. Silverlight - The VS Environment 04. Silverlight - Content Controls 05. Silverlight - Built-In Controls 06. Silverlight - ...阅读全文
posted @ 2009-09-20 20:11 草羹 阅读(120) 评论(0) 编辑
Applications = Code + Markup读书笔记(1)
摘要: 1. 关于Application和Window的层次结构Object └─DispatcherObject (abstract) ├─Application └─DependencyObject └─Visual (abstract) └─UIElement └ ...阅读全文
posted @ 2009-09-20 15:48 草羹 阅读(11) 评论(0) 编辑
仅列出标题  
Copyright ©2012 草羹