知乎周源微信_每周源代码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

相关文章

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

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

SWAP作物生长模型安装教程、数据制备、敏感性分析、气候变化影响、R模型敏感性分析与贝叶斯优化、Fortran源代码分析、气候数据降尺度与变化影响分析

查看原文>>>全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用 SWAP模型是由荷兰瓦赫宁根大学开发的先进农作物模型,它综合考虑了土壤-水分-大气以及植被间的相互作用;是一种描述作物生长过程的一种机理性作物生长模型。它不但运用Richard方程,使其能够精确的模拟土壤中水分的运动,而且耦合了WOFOST作物模型使作物的生长描述更为科学。 本文让更多的科研人员和农业工作者

uniapp设置微信小程序的交互反馈

链接:uni.showToast(OBJECT) | uni-app官网 (dcloud.net.cn) 设置操作成功的弹窗: title是我们弹窗提示的文字 showToast是我们在加载的时候进入就会弹出的提示。 2.设置失败的提示窗口和标签 icon:'error'是设置我们失败的logo 设置的文字上限是7个文字,如果需要设置的提示文字过长就需要设置icon并给

GitHub每周最火火火项目(9.2-9.8)

项目名称:polarsource / polar 项目介绍:polar 是一个开源项目,它是 Lemon Squeezy 的替代方案,并且具有更具优势的价格。该项目的目标是为开发者提供一种更好的选择,让他们能够在追求自己的热情和兴趣的同时,通过编码获得相应的报酬。通过使用 polar,开发者可以享受到更实惠的价格,同时也能够更自由地发挥自己的创造力和技能。 项目地址:https://github.

运营版开源代码 多语言跨境商城 跨境电商平台

默认中英双语 后台带翻译接口 支持133种语言自动翻译 支持多商户联盟 一键部署版本 伪静态+后台登陆后缀 源码下载:https://download.csdn.net/download/m0_66047725/89722389 更多资源下载:关注我。

基于微信小程序与嵌入式系统的智能小车开发(详细流程)

一、项目概述 本项目旨在开发一款智能小车,结合微信小程序与嵌入式系统,提供实时图像处理与控制功能。用户可以通过微信小程序远程操控小车,并实时接收摄像头采集的图像。该项目解决了传统遥控小车在图像反馈和控制延迟方面的问题,提升了小车的智能化水平,适用于教育、科研和娱乐等多个领域。 二、系统架构 1. 系统架构设计 本项目的系统架构主要分为以下几个部分: 微信小程序:负责用户界面、控制指令的

微信小程序uniappvue3版本-控制tabbar某一个的显示与隐藏

1. 首先在pages.json中配置tabbar信息 2. 在代码根目录下添加 tabBar 代码文件 直接把微信小程序文档里面的四个文件复制到自己项目中就可以了   3. 根据自己的需求更改index.js文件 首先我这里需要判断什么时候隐藏某一个元素,需要引入接口 然后在切换tabbar时,改变tabbar当前点击的元素 import getList from '../

微信小程序(一)数据流与数据绑定

一、单向数据流和双向数据流 1、单项数据流:指的是我们先把模板写好,然后把模板和数据(数据可能来自后台)整合到一起形成HTML代码,然后把这段HTML代码插入到文档流里面 优点:数据跟踪方便,流向单一,追寻问题比较方便【主要体现:微信小程序】。 缺点:就是写起来不太方便,如果修改UI界面数据需要维护对应的model对象 2、双向数据流:值和UI是双向绑定的,大家都知道,只要UI里面的值发生

微信小程序学习网站

小程序--柯神博客 http://www.cnblogs.com/nosqlcoco 案例地址: https://github.com/cocoli/weixin_smallexe/tree/master/weixin_demo/pages/component/uploadfile

分享一个基于uniapp科技馆服务微信小程序 博物馆管理小程序(源码、调试、LW、开题、PPT)

💕💕作者:计算机源码社 💕💕个人简介:本人 八年开发经验,擅长Java、Python、PHP、.NET、Node.js、Android、微信小程序、爬虫、大数据、机器学习等,大家有这一块的问题可以一起交流! 💕💕学习资料、程序开发、技术解答、文档报告 💕💕如需要源码,可以扫取文章下方二维码联系咨询 💕💕Java项目 💕💕微信小程序项目 💕💕Android项目 �