热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

知乎周源微信_每周源代码7

知乎周源微信Inmynewongoingquesttoreadsourcecodetobeabetterdeveloper,Inowpresenttheseventhinaninf
知乎周源微信

知乎周源微信

In my new ongoing quest to read source code to be a better developer, I now present the seventh in an infinite number of a weekly series called "The Weekly Source Code." Here's some source I'm reading this week that I enjoyed.

在我不断追求读取源代码以成为更好的开发人员的新追求中,我现在以每周系列的无数个“每周源代码”的形式展示第七个。 这是我本周喜欢的一些资料。

I got a little sidetracked the recent trip to the ALT.NET conference, so forgive me for missing last week.

最近的ALT.NET会议之旅让我有些困惑,所以请原谅我上周的失踪。

  • Joe Cheng's Schwartzian Transform in C# 3.0 - Whenever someone knows the official name for technique, be it in chess or in code, they're usually smarter than I. "You are using Bonetti's Defense against me, ah?" Joe is one of those guys. ;)

    郑元畅的使用Schwartzian变换在C#3.0 -每当有人知道对于技术的正式名称,无论是在国际象棋或代码,他们通常更聪明的是比我你正在使用博内蒂的防御我啊? 乔是其中之一伙计们;)

    "What’s a

    “什么是

    Schwartzian Transform? It’s a way of efficiently sorting a list of objects according to some potentially expensive-to-calculate property of those objects. For example, let’s say you have an array of filenames, and you want to sort them by their last modified dates"

    Schwartzian转换? 这是一种根据对象潜在的昂贵计算属性对对象列表进行有效排序的方法。 例如,假设您有一个文件名数组,并且想按文件的最后修改日期对其进行排序”

    This is a very useful technique to know and nice and clean in C# 3.0.

    在C#3.0中,这是一种非常有用的知识,非常好用。

public static List SortBy2(this List coll,Converter converter,Comparison comparison){return coll.ConvertAll(el => new { Key = converter(el), Value = el }).Sort((a, b) => comparison(a.Key, b.Key)).ConvertAll(x => x.Value);}

  • LINQ to Amazon - This is a little old, but it's still darn interesting to read. If you've been thinking about implementing LINQ over an object or web service that your company has, this is a good place to start. I'll let you go digging around, but here's some bits I found interesting. Note also that the code is very old and I haven't been able to find the latest stuff.

    LINQ to Amazon-这有点老了,但阅读起来仍然很有趣。 如果您一直在考虑对公司拥有的对象或Web服务实施LINQ,那么这是一个不错的起点。 我会让您继续研究,但是这里有些有趣的地方。 还要注意,代码很旧,我找不到最新的东西。

    This is what I call Left-Hand/Right-Hand code where we're pulling with one hand, in this case XML and handing off with the other hand, in this case, making a LINQ List.  It tends to be very tedious but LINQ sure makes it easy.

    这就是我所说的“左手/右手”代码,我们用一只手(在这种情况下为XML)拉动代码,而用另一只手在这种情况下进行交接,从而生成LINQ列表。 它通常很繁琐,但是LINQ确实使它变得容易。

  • XNamespace ns = NAMESPACE_AWSECommerceService;
    var books = from book in booksDoc.Descendants(ns+"Item") select new Book { Title = book.Element(ns+"ItemAttributes").Element(ns+"Title").Value, Publisher = book.Element(ns+"ItemAttributes").Element(ns+"Publisher").Value, Year = uint.Parse(((String)book.Element(ns+"ItemAttributes").Element(ns+"PublicationDate").Value).Substring(0, 4)), Authors = ( from author in book.Descendants(ns+"Author") select (String) author.Value ).ToList()
    };

  • Argotic Syndication Framework - Woof, a full implementation of Atom 1.0, OPML 2.0, RSD 1.0, and RSS 2.0 syndication formats. If you're looking for syndication source look no further. This is not only very clean code that's also well organized with a very interesting extension mechanism for including other namespaces within your syndication format.  It's also excessively well documented. I hate them. ;) Although, I'm not sure where the tests are, it's pretty clear that this reflects a huge amount of work.  Or a lot of code generation.

    Argotic Syndication Framework -Woof,是Atom 1.0 , OPML 2.0 , RSD 1.0和RSS 2.0联合格式的完整实现。 如果您正在寻找联合来源,那就别无所求。 这不仅是非常干净的代码,而且还通过非常有趣的扩展机制进行了良好的组织,以在您的联合格式中包括其他名称空间。 它也有充分的记录。 我恨他们。 ;)尽管我不确定测试在哪里,但是很明显这反映了大量的工作。 还是很多代码生成。

    There is far too much to paste much here, but what are the things I click away was a new attribute but I hadn't heard of yet. You can tell FxCop to relax as they do here with a naming rule.

    这里要粘贴的内容太多了,但是我单击的内容是一个新属性,但是我还没有听说过。 您可以通过命名规则告诉FxCop放松,就像他们在这里一样。

  • [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Rss")]
    public class RssFeedCreatedEventArgs : EventArgs, IComparable {...

  • LukeH and a fully LINQified RayTracer - Seriously, someone give this guy some money or a warm handshake or something. This is unreal...it's single line of LINQ. That means it's one expression. Luke is a glutton for punishment because I'm still trying to get my brain around the statement. This guy is a beast. I'm thinking of starting a cult around him. Here's his code, but go read his post for the explanation. Go! Right now! I'll wait here.

    LukeH和完全LINQified RayTracer-认真的说,有人给这个人一些钱或热烈的握手之类的东西。 这是不真实的...这是LINQ的单行。 这意味着它是一种表达。 卢克(Luke)是惩罚的嘴,因为我仍在努力使自己的头脑与声明无关。 这个家伙是野兽。 我正在考虑开始对他进行崇拜。 这是他的代码,但是请阅读他的文章以获取解释。 走! 马上! 我在这里等

    LukeH and a fully LINQified RayTracer - Seriously, someone give this guy some money or a warm handshake or something. This is unreal...it's single line of LINQ. That means it's one expression. Luke is a glutton for punishment because I'm still trying to get my brain around the statement. This guy is a beast. I'm thinking of starting a cult around him. Here's his code, but go read his post for the explanation. Go! Right now! I'll wait here.

    LukeH和完全LINQified RayTracer-认真的说,有人给这个人一些钱或热烈的握手之类的东西。 这是不真实的...这是LINQ的单行。 这意味着它是一种表达。 卢克(Luke)是惩罚的嘴,因为我仍在努力使自己的头脑与声明无关。 这个家伙是野兽。 我正在考虑开始对他进行崇拜。 这是他的代码,但是请阅读他的文章以获取解释。 走! 马上! 我在这里等

  • var pixelsQuery =from y in Enumerable.Range(0, screenHeight)let recenterY = -(y - (screenHeight / 2.0)) / (2.0 * screenHeight)select from x in Enumerable.Range(0, screenWidth)let recenterX = (x - (screenWidth / 2.0)) / (2.0 * screenWidth)let point = Vector.Norm(Vector.Plus(scene.Camera.Forward, Vector.Plus(Vector.Times(recenterX, scene.Camera.Right),Vector.Times(recenterY, scene.Camera.Up))))let ray = new Ray { Start = scene.Camera.Pos, Dir = point }let computeTraceRay = (Func, Func>)(f => traceRayArgs =>(from isect infrom thing in traceRayArgs.Scene.Thingsselect thing.Intersect(traceRayArgs.Ray)where isect != nullorderby isect.Distlet d = isect.Ray.Dirlet pos = Vector.Plus(Vector.Times(isect.Dist, isect.Ray.Dir), isect.Ray.Start)let normal = isect.Thing.Normal(pos)let reflectDir = Vector.Minus(d, Vector.Times(2 * Vector.Dot(normal, d), normal))let naturalColors = from light in traceRayArgs.Scene.Lightslet ldis = Vector.Minus(light.Pos, pos)let livec = Vector.Norm(ldis)let testRay = new Ray { Start = pos, Dir = livec }let testIsects = from inter infrom thing in traceRayArgs.Scene.Thingsselect thing.Intersect(testRay)where inter != nullorderby inter.Distselect interlet testIsect = testIsects.FirstOrDefault()let neatIsect = testIsect == null ? 0 : testIsect.Distlet isInShadow = !((neatIsect > Vector.Mag(ldis)) || (neatIsect == 0))where !isInShadowlet illum = Vector.Dot(livec, normal)let lcolor = illum > 0 ? Color.Times(illum, light.Color) : Color.Make(0, 0, 0)let specular = Vector.Dot(livec, Vector.Norm(reflectDir))let scolor = specular > 0 ? Color.Times(Math.Pow(specular, isect.Thing.Surface.Roughness), light.Color) : Color.Make(0, 0, 0)select Color.Plus(Color.Times(isect.Thing.Surface.Diffuse(pos), lcolor),Color.Times(isect.Thing.Surface.Specular(pos), scolor))let reflectPos = Vector.Plus(pos, Vector.Times(.001, reflectDir))let reflectColor = traceRayArgs.Depth >= MaxDepth? Color.Make(.5, .5, .5): Color.Times(isect.Thing.Surface.Reflect(reflectPos), f(new TraceRayArgs(new Ray { Start = reflectPos, Dir = reflectDir }, traceRayArgs.Scene, traceRayArgs.Depth + 1)))select naturalColors.Aggregate(reflectColor, (color, natColor) => Color.Plus(color, natColor))) .DefaultIfEmpty(Color.Background).First())let traceRay = Y(computeTraceRay)select new { X = x, Y = y, Color = traceRay(new TraceRayArgs(ray, scene, 0)) };foreach (var row in pixelsQuery)foreach (var pixel in row)setPixel(pixel.X, pixel.Y, pixel.Color.ToDrawingColor());

    Feel free to send me links to cool source that you find hasn't been given a good read.

    随时向我发送指向很酷的资源的链接,您发现这些链接没有得到很好的阅读。

    翻译自: https://www.hanselman.com/blog/the-weekly-source-code-7

    知乎周源微信



推荐阅读
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了游标的使用方法,并以一个水果供应商数据库为例进行了说明。首先创建了一个名为fruits的表,包含了水果的id、供应商id、名称和价格等字段。然后使用游标查询了水果的名称和价格,并将结果输出。最后对游标进行了关闭操作。通过本文可以了解到游标在数据库操作中的应用。 ... [详细]
  • flowable工作流 流程变量_信也科技工作流平台的技术实践
    1背景随着公司业务发展及内部业务流程诉求的增长,目前信息化系统不能够很好满足期望,主要体现如下:目前OA流程引擎无法满足企业特定业务流程需求,且移动端体 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • IB 物理真题解析:比潜热、理想气体的应用
    本文是对2017年IB物理试卷paper 2中一道涉及比潜热、理想气体和功率的大题进行解析。题目涉及液氧蒸发成氧气的过程,讲解了液氧和氧气分子的结构以及蒸发后分子之间的作用力变化。同时,文章也给出了解题技巧,建议根据得分点的数量来合理分配答题时间。最后,文章提供了答案解析,标注了每个得分点的位置。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 如何用UE4制作2D游戏文档——计算篇
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了如何用UE4制作2D游戏文档——计算篇相关的知识,希望对你有一定的参考价值。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • eclipse学习(第三章:ssh中的Hibernate)——11.Hibernate的缓存(2级缓存,get和load)
    本文介绍了eclipse学习中的第三章内容,主要讲解了ssh中的Hibernate的缓存,包括2级缓存和get方法、load方法的区别。文章还涉及了项目实践和相关知识点的讲解。 ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
author-avatar
陈春红_2009932
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有