知乎周源微信_每周源代码12-黑色版

2023-12-20 11:50

本文主要是介绍知乎周源微信_每周源代码12-黑色版,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

知乎周源微信

知乎周源微信

It's been a while since the last Weekly Source Code, but I have the holidays and the preponderance of baby poop as a fine formal excuse. I'm back from Paternity now and the Source Code will keep coming weekly as originally promised.

自上周的每周源代码以来已经有一段时间了,但是我有节假日​​和大量的婴儿便便作为正式的借口。 我现在已经从Paternity回来了,源代码将按照最初的承诺每周继续发布。

If you're new to this, each week I post some snippets of particularly interesting (read: beautiful, ugly, clever, obscene) source and the project it came from. This started from a belief that reading source is as important (or more so) as writing it. We read computer books to become better programmers, but unless you're reading books like Programming Pearls, you ought to peruse some Open Source projects for inspiration.

如果您是新手,我每周都会发布一些片段,这些片段特别有趣(阅读:美丽,丑陋,聪明,淫秽)和其来源。 这源于一种信念,即阅读源与编写源同样重要(甚至更重要) 。 我们阅读计算机书籍以成为更好的程序员,但是除非您阅读《 Programming Pearls》之类的书,否则您应该细读一些开放源代码项目以获取灵感。

And so, Dear Reader, I present to you the twelfth in a infinite number of posts of "The Weekly Source Code." Here's some source I was reading while changing diapers.

因此,尊敬的读者,我在“每周源代码”的无数帖子中向您介绍第十二个。 这是我在换尿布时正在阅读的一些资料。

  • Looking for applications that use WPF? They are out there and they don't always have "juicy buttons" and scream "I was written in WPF." Sometimes they are just clean, simple and functional. Witty is a Twitter (chat-esque) client written in WPF, a technology I have yet to fully grok.

    寻找使用WPF的应用程序吗? 他们在那里,他们并不总是有“多汁的按钮”和尖叫声“我是用WPF编写的”。 有时它们只是干净,简单和实用的。 Witty是用WPF编写的Twitter (聊天)客户端,我尚未完全了解过该技术。

    This little app has a simple Twitter Client Library that includes inside it a

    这个小应用程序有一个简单的Twitter客户端库,其中包含一个

    TinyUrl maker. (Google better buy TinyUrl or the whole web might get link rot) Sometimes it's fun to read source for the comments, but it's also cathartic to read code that you didn't write and say to yourself, "hey, this could use some refactoring." Perhaps a good time for you to offer to help an Open Source Project.

    TinyUrl制造商。 (Google最好购买TinyUrl,否则整个网络可能会丢失链接)有时,阅读注释源很有趣,但阅读未编写的代码并对自己说:“嘿,这可能需要一些重构。” 也许是您提供帮助开源项目的好时机。

    This example is the most trivial chunk of code in Witty, but somehow it made me smile. Regardless, the MainWindow of Witty also had some interesting stuff, particularly the background fetching of data. It's definitely easier than WinForms.

    这个例子是Witty中最琐碎的代码块,但是以某种方式让我笑了。 无论如何,Witty的MainWindow也有一些有趣的东西,特别是数据的后台获取。 绝对比WinForms容易。

    public void UpdateRelativeTime()
    {DateTime StatusCreatedDate = (DateTime)dateCreated;TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - StatusCreatedDate.Ticks);double delta = ts.TotalSeconds;string relativeTime = string.Empty;if (delta == 1){relativeTime = "a second ago";}else if (delta < 60){relativeTime = ts.Seconds + " seconds ago";}else if (delta < 120){relativeTime = "about a minute ago";}else if (delta < (45 * 60)){relativeTime = ts.Minutes + " minutes ago";}else if (delta < (90 * 60)){relativeTime = "about an hour ago";}else if (delta < (24 * 60 * 60)){relativeTime = "about " + ts.Hours + " hours ago";}else if (delta < (48 * 60 * 60)){relativeTime = "1 day ago";}else{relativeTime = ts.Days + " days ago";}RelativeTime = relativeTime;
    }
  • Folks are poking at C# 3.0 trying to get lambdas and anonymous type declarations to feel and act like Ruby hash table declarations. It'll be interesting to see if Anders is already on top of this. I wonder if he and Matz hang out? If I invented a language, I'd make a really exclusive clubhouse. ;)

    人们嘲笑C#3.0,试图让lambda和匿名类型声明像Ruby哈希表声明一样发挥作用。 看看Anders是否已处于此之上将会很有趣。 我想知道他和Matz是否出去玩吗? 如果发明一种语言,我会成为一个真正的俱乐部。 ;)

    Folks are poking at C# 3.0 trying to get lambdas and anonymous type declarations to feel and act like Ruby hash table declarations. It'll be interesting to see if Anders is already on top of this. I wonder if he and Matz hang out? If I invented a language, I'd make a really exclusive clubhouse. ;) Eilon shows the difference between Dictionaries and anonymous types in his proposal:

    人们嘲笑C#3.0,试图让lambda和匿名类型声明像Ruby哈希表声明一样发挥作用。 看看Anders是否已处于此之上将会很有趣。 我想知道他和Matz是否一起玩吗? 如果发明一种语言,我会成为一个真正的俱乐部。 ;) Eilon在他的提案中展示了Dictionary和匿名类型之间的区别:

    Folks are poking at C# 3.0 trying to get lambdas and anonymous type declarations to feel and act like Ruby hash table declarations. It'll be interesting to see if Anders is already on top of this. I wonder if he and Matz hang out? If I invented a language, I'd make a really exclusive clubhouse. ;) Eilon shows the difference between Dictionaries and anonymous types in his proposal:

    人们嘲笑C#3.0,试图让lambda和匿名类型声明像Ruby哈希表声明一样发挥作用。 看看Anders是否已处于此之上将会很有趣。 我想知道他和Matz是否出去玩吗? 如果发明一种语言,我会成为一个真正的俱乐部。 ;) Eilon在他的提案中展示了Dictionary和匿名类型之间的区别:

    • This is some ugly code:

      这是一些难看的代码:

    Folks are poking at C# 3.0 trying to get lambdas and anonymous type declarations to feel and act like Ruby hash table declarations. It'll be interesting to see if Anders is already on top of this. I wonder if he and Matz hang out? If I invented a language, I'd make a really exclusive clubhouse. ;) Eilon shows the difference between Dictionaries and anonymous types in his proposal:

    人们嘲笑C#3.0,试图让lambda和匿名类型声明像Ruby哈希表声明一样发挥作用。 看看Anders是否已处于此之上将会很有趣。 我想知道他和Matz是否出去玩吗? 如果发明一种语言,我会成为一个真正的俱乐部。 ;) Eilon在他的提案中展示了Dictionary和匿名类型之间的区别:

    Dictionary<string, string> values = new Dictionary<string, string>();
    values.Add("key1", "value1");
    values.Add("key2", "value2");
    values.Add("key3", "value3");
    GetHtmlLink("Click me", values);
     Dictionary<string, string> values = new Dictionary<string, string>();
    values.Add("key1", "value1");
    values.Add("key2", "value2");
    values.Add("key3", "value3");
    GetHtmlLink("Click me", values);

    My proposal: Have the method accept a parameter of type object. Callers could pass in a type that has properties with the appropriate names and values. They can use C#'s object initializer syntax to save some space:

    我的建议:让该方法接受类型为object的参数。 调用者可以传入具有适当名称和值的属性的类型。 他们可以使用C#的对象初始值设定项语法节省一些空间:

    MyParams myParams = new MyParams { Key1 = "value1", Key2 = "value2", Key3 = "value3" };
    GetHtmlLink("Click me", myParams);

    However, there was the added work of defining the MyParams type. Admittedly, it wasn't that hard with C# 3.0's automatic properties, but I hate defining types that are used in only one place. If the user can pass in an arbitrary object with properties, why not let that object be of an anonymous type? Here's the final code:

    但是,还有其他工作来定义MyParams类型。 诚然,C#3.0的自动属性并不难,但是我讨厌定义只在一个地方使用的类型。 如果用户可以传递带有属性的任意对象,为什么不让该对象成为匿名类型呢? 这是最终代码:

    GetHtmlLink("Click me", new { Key1 = "value1", Key2 = "value2", Key3 = "value3" });
     GetHtmlLink("Click me", new { Key1 = "value1", Key2 = "value2", Key3 = "value3" });
    

    Woah! We went from five lines of code with dictionaries to two lines of code with object initializers (minus the type definition), to just one line of code with anonymous types!

    哇! 我们从带有字典的五行代码到带有对象初始化程序的两行代码(减去类型定义),到只有带有匿名类型的一行代码!

  • Bill asks for better Dictionary Initializers, and Alex does it with lambdas in his post, giving him this clean syntax, and PhilHa weighs in with his thoughts. Bill says "Your inner Rubyist is nodding with approval."

    Bill要求使用更好的Dictionary Initializer ,而Alex在其帖子中使用lambda做到了这一点,为他提供了这种简洁的语法, PhilHa则考虑了自己的想法。 比尔说:“您内心的Rubyist正在点头同意。

    Dictionary<string, object> items = Hash<object>(Name => "alex", TargetType => typeof(Uri), Id => 10);
    Assert.AreEqual(10, items["Id"]);

    字典<string,object> items = Hash <object>(Name =>“ alex”,TargetType => typeof(Uri),Id => 10); Assert.AreEqual(10,items [“ Id”]);

  • If you're looking to do small GUI applications, you might take a moment to look at "Shoes" the tiny Ruby UI Tookit. Why? Well, if you're an old WinForms or new WPF guy like myself, (or an old Java guy, also like myself) it's helpful to other perspectives on what a Domain Specific Language for UI might look like. The sample source is here.

    如果您要制作小型GUI应用程序,则可能需要花一点时间来看看“ Shoes”小型Ruby UI Tookit 。 为什么? 好吧,如果您是像我这样的旧WinForms或新WPF家伙(或者也像我一样的旧Java家伙),则对于其他方面的UI界面视图很有帮助。 示例源在这里。

    Here are

    这是

    four different snippets in four different language that show a single button with a click event handler that shows a message.

    四种不同语言的四种摘要,显示一个按钮,并带有一个显示消息的click事件处理程序。

    Here's the same thing in Shoes. Note that the

    这在鞋中也是一样。 请注意

    documentation for Shoes is available as a Ransom Note. The creator never uses the acronym "GUI" in the docs or materials, but prefers to think of Shoes as a "toy." It's a pretty near toy, take a look at the 2D animation examples.

    鞋子的文档可作为赎金票据获得。 创建者从不在文档或材料中使用首字母缩写“ GUI”,而是更喜欢将Shoes视为“玩具”。 这是一个非常接近的玩具,请看一下2D动画示例。

    Shoes.app {button("Press Me") { alert("You pressed me") }
    }
  • Rob (and lots of other folks) are exploring what UserControls look like in an ASP.NET MVC world. He says " Your UserControl can be one of two things: A granular bit of UI that renders information passed from a Controller [or] a granular bit of UI that renders information from an application-wide data source." He calls them a "Viewlet" and offers these helper methods: Rendering a ViewUserControl
    The
    MVC Toolkit has a nice method called “RenderUserControl()” that allows you to process your ViewUserControl and output it’s result inline:
    Rob(和其他许多人)正在探索UserControl在ASP.NET MVC世界中的外观。 他说:“ 您的UserControl可以是以下两件事之一:呈现从控制器传递的信息的UI粒度[或]从应用程序范围的数据源呈现信息的UI粒度。 ”他称其为“ Viewlet ”,并提供以下辅助方法: 渲染一个ViewUserControl MVC工具包 有一个名为“RenderUserControl()”好方法,可以让你处理你ViewUserControl和输出它的结果联:
    <%=Html.RenderUserControl(“~/UserControls/UserList.ascx”)%>

    If the ViewUserControl is typed (say ViewUserControl<MyControllerData>), then it’s ViewData object will be filled for you, and your ViewPage and rendered control will share the same data.

    如果键入了ViewUserControl(例如ViewUserControl <MyControllerData>),则将为您填充它的ViewData对象,并且您的ViewPage和呈现的控件将共享相同的数据。

    If you want to be explicit about it, you can do that as well, specifying the data to pass:

    如果您想对此进行明确说明,也可以通过指定要传递的数据来做到这一点:

    <%=Html.RenderUserControl(“~/UserControls/UserList.ascx”,ViewData.Users)%>

    Finally, if you need to set properties on the ViewUserControl, you can do that as well by passing in an anonymous type:

    最后,如果需要在ViewUserControl上设置属性,则也可以通过传入匿名类型来做到这一点:

    <%=Html.RenderUserControl(“~/UserControls/UserList.ascx”,ViewData.Users, new {GroupID=2})%>

Enjoy, and keep reading code!

享受,并继续阅读代码!

翻译自: https://www.hanselman.com/blog/the-weekly-source-code-12-back-in-black-edition

知乎周源微信

这篇关于知乎周源微信_每周源代码12-黑色版的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/515950

相关文章

java向微信服务号发送消息的完整步骤实例

《java向微信服务号发送消息的完整步骤实例》:本文主要介绍java向微信服务号发送消息的相关资料,包括申请测试号获取appID/appsecret、关注公众号获取openID、配置消息模板及代码... 目录步骤1. 申请测试系统2. 公众号账号信息3. 关注测试号二维码4. 消息模板接口5. Java测试

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

如何基于Python开发一个微信自动化工具

《如何基于Python开发一个微信自动化工具》在当今数字化办公场景中,自动化工具已成为提升工作效率的利器,本文将深入剖析一个基于Python的微信自动化工具开发全过程,有需要的小伙伴可以了解下... 目录概述功能全景1. 核心功能模块2. 特色功能效果展示1. 主界面概览2. 定时任务配置3. 操作日志演示

Redis迷你版微信抢红包实战

《Redis迷你版微信抢红包实战》本文主要介绍了Redis迷你版微信抢红包实战... 目录1 思路分析1.1hCckRX 流程1.2 注意点①拆红包:二倍均值算法②发红包:list③抢红包&记录:hset2 代码实现2.1 拆红包splitRedPacket2.2 发红包sendRedPacket2.3 抢

SpringBoot后端实现小程序微信登录功能实现

《SpringBoot后端实现小程序微信登录功能实现》微信小程序登录是开发者通过微信提供的身份验证机制,获取用户唯一标识(openid)和会话密钥(session_key)的过程,这篇文章给大家介绍S... 目录SpringBoot实现微信小程序登录简介SpringBoot后端实现微信登录SpringBoo

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

SpringBoot实现微信小程序支付功能

《SpringBoot实现微信小程序支付功能》小程序支付功能已成为众多应用的核心需求之一,本文主要介绍了SpringBoot实现微信小程序支付功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录一、引言二、准备工作(一)微信支付商户平台配置(二)Spring Boot项目搭建(三)配置文件

微信公众号脚本-获取热搜自动新建草稿并发布文章

《微信公众号脚本-获取热搜自动新建草稿并发布文章》本来想写一个自动化发布微信公众号的小绿书的脚本,但是微信公众号官网没有小绿书的接口,那就写一个获取热搜微信普通文章的脚本吧,:本文主要介绍微信公众... 目录介绍思路前期准备环境要求获取接口token获取热搜获取热搜数据下载热搜图片给图片加上标题文字上传图片

如何用java对接微信小程序下单后的发货接口

《如何用java对接微信小程序下单后的发货接口》:本文主要介绍在微信小程序后台实现发货通知的步骤,包括获取Access_token、使用RestTemplate调用发货接口、处理AccessTok... 目录配置参数 调用代码获取Access_token调用发货的接口类注意点总结配置参数 首先需要获取Ac

W外链微信推广短连接怎么做?

制作微信推广链接的难点分析 一、内容创作难度 制作微信推广链接时,首先需要创作有吸引力的内容。这不仅要求内容本身有趣、有价值,还要能够激起人们的分享欲望。对于许多企业和个人来说,尤其是那些缺乏创意和写作能力的人来说,这是制作微信推广链接的一大难点。 二、精准定位难度 微信用户群体庞大,不同用户的需求和兴趣各异。因此,制作推广链接时需要精准定位目标受众,以便更有效地吸引他们点击并分享链接