摘要:
为了测试一下js和Canvas的计算能力,做了一个Mandelbrot的分形图,支持鼠标Zoom In。Mandelbrot的定义很简单,虚数平面的每个点(x,y),通过反复计算zn+1 = zn2 + c,z0 = 0。只有结果收敛才属于Mandelbrot,否则根据n的设定一个颜色,越大越深,代表接近属于集合的点,可以把集合中的点理解为n=无穷大。推荐在chrome中打开本页,还支持firefox和ie9。 拖动鼠标可以明显发现chrome是最流畅的。更为专业的Mandelbrot请check这里 http://www.atopon.org/mandel/Your browser does 阅读全文
摘要:
class Student{ public string Name { get; set; }}static double Test(int loop, Student stu, Func<Student, string> action){ var watch = Stopwatch.StartNew(); string s = null; for (var i = 0; i < loop; i++) s = action(stu); return watch.ElapsedTicks;}static Func<Student, string> NativeGet 阅读全文
摘要:
当跨assemblies的时候要特别注意两者的区别, 请看这篇文章if the scope of your constant is limited to just one assembly, class, or smaller (you can define a const inside a method), this is not a big deal. However, if the const is visible outside the assembly it is defined in, we must be wary! Because the const’s value is su 阅读全文
摘要:
在sqlserver中可以这样显示分组前N个成员, 关键在row_number, partitionselect * from (select schoolmember_id, row_number() over(partition by school_id order by schoolmember_id ) as number from schoolmember) as awhere a.number < 3 阅读全文
摘要:
private static int BinarySearch(T[] array, int index, int length, T value){ int lo = index; int hi = index + length - 1; while (lo <= hi) { int i = lo + ((hi - lo) >> 1); int order; if (array[i] == null) { order = (value == null) ? 0 : -1; } else { order = array[i].CompareTo(value); } if (o 阅读全文
摘要:
declare @text nvarchar(500) ,@delimiter nchar(1)set @text = '1,2,3'set @delimiter = ',' set @text = @text + @delimiter;WITH CSV([index], [comma_index])as(select [index] = 1, [comma_index] = CHARINDEX(@delimiter, @text) union allselect [index] = [comma_index] + 1, [comma_index] = CHAR 阅读全文
摘要:
通过SqlServer的Common Table Expressions (CTE)可以进行递归计算。参见Using Common Table Expressions 和 Recursive Queries Using Common Table Expressions通过CTE计算FibonacciWITH Fib(a, b)AS(SELECT 0,1 UNION allSELECT b, a+b FROM Fib WHERE b < 10)SELECT * FROM Fib 阅读全文
摘要:
由于最近较忙,上一篇的坑估计要慢慢填了。感觉写文章介绍要比写程序还累啊。先看看测试程序,能够了解api支持哪些功能:static void Main(string[] args){ //wrapper对象 dynamic data = DJson.Wrap(new { name = "Jane", male = false, age = 24, dob = DateTime.Now, friend = new { name = "Jesse", male = true, age = 32, dob = DateTime.Now }, mobile = n 阅读全文
摘要:
参考 http://www.yoda.arachsys.com/csharp/singleton.html双lock的singleton性能非常差,这里推荐inner class的方式,并且加上泛型。public class Singleton<T> where T : new(){ public static T Instance { get { return Nested.instance; } } private class Nested { //suppress optimization in .net v1.1 static Nested() { } internal s 阅读全文
摘要:
通过jQuery.get是不能异步访问跨域资源的。主要是因为安全考虑,否则其他域有可能获得当前页的cookie造成隐私泄漏。但js确可以跨域访问,因为所有浏览器都支持refer外部的js文件。访问外部域的js时会发送外部域的cookie,这样在返回的js中就能获取值了。创建两个website,分别叫local.domain1.com和local.domain2.comdomain1中负责set和get本域的cookie,分别为setcookie.aspx和getcookie.aspx//setcookie.aspxpublic partial class SetCookie : System. 阅读全文