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

2023-12-20 11:50

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

知乎周源微信

知乎周源微信

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

在我的新不断追求阅读源代码,是一个更好的开发者,我现在提出的第八每周一系列名为无限数量的“每周源代码”。 这是我本周喜欢的一些资料。

  • The Vista Battery Saver is a fun and simple little application that shuts off Aero and the Sidebar when you're running on batteries. The source is up at CodePlex. He registered his application with Windows for Power Notifications. Windows will send his application a Window Message when the system's power state changes.

    Vista Battery Saver是一个有趣且简单的小应用程序,当您使用电池运行时,它会关闭Aero和侧边栏。 源代码来自CodePlex。 他在Windows上为Power Notifications注册了他的应用程序。 当系统电源状态更改时,Windows将向其应用程序发送“窗口消息”。

    //In the main WinForm, he overrides the WndProcprotected override void WndProc(ref Message m){base.WndProc(ref m);if (m.Msg == PowerMngr.WM_POWERBROADCAST){PowerMngr.GetManager().PowerSettingChange(m);}}//Earlier he selects the messages he's interested in.internal void RegisterForPowerNotifications(IntPtr hwnd){hPowerSrc = RegisterPowerSettingNotification(hwnd,ref GUID_ACDC_POWER_SOURCE,DEVICE_NOTIFY_WINDOW_HANDLE);hBattCapacity = RegisterPowerSettingNotification(hwnd,ref GUID_BATTERY_PERCENTAGE_REMAINING,DEVICE_NOTIFY_WINDOW_HANDLE);hMonitorOn = RegisterPowerSettingNotification(hwnd,ref GUID_MONITOR_POWER_ON,DEVICE_NOTIFY_WINDOW_HANDLE);hPowerScheme = RegisterPowerSettingNotification(hwnd,ref GUID_POWERSCHEME_PERSONALITY,DEVICE_NOTIFY_WINDOW_HANDLE);}[DllImport(@"User32", SetLastError = true, EntryPoint = "RegisterPowerSettingNotification", CallingConvention = CallingConvention.StdCall)]private static extern IntPtr RegisterPowerSettingNotification(IntPtr hRecipient,ref Guid PowerSettingGuid,Int32 Flags);
  • Patrick Smacchia released a Strongly Typed Path Library today. You know Patrick, he's NDepend-guy and he rocks. He includes a Class Diagram as well:

    Patrick Smacchia今天发布了“强类型路径库”。 你知道帕特里克,他是NDepend-guy,而且他很摇滚。 他还包括一个类图:

    PathClassDiagram

    Patrick Smacchia released a Strongly Typed Path Library today. You know Patrick, he's NDepend-guy and he rocks. He includes a Class Diagram as well:

    Patrick Smacchia今天发布了“强类型路径库”。 你知道帕特里克,他是NDepend-guy,而且他很摇滚。 他还包括一个类图:

    I'll let you go check it out, because you should. I think a class this smart would be a nice addition to the BCL. Here's some of his tests showing the usage of the library. Make careful note of the !'s inside the Asserts. They weren't totally obvious to me. I usually use == false. I find it easier to read.

    我会让你去检查,因为你应该。 我认为这门课很聪明,将是对BCL的不错补充。 这是他的一些测试,显示了库的用法。 仔细记下断言中的!。 他们对我来说不是很明显。 我通常使用== false。 我发现它更容易阅读。

  •       //// Path string validation//string reason;Debug.Assert(PathHelper.IsValidAbsolutePath(@"C:\Dir2\Dir1", out reason));Debug.Assert(!PathHelper.IsValidAbsolutePath(@"C:\..\Dir1", out reason));Debug.Assert(!PathHelper.IsValidAbsolutePath(@".\Dir1", out reason));Debug.Assert(!PathHelper.IsValidAbsolutePath(@"1:\Dir1", out reason));Debug.Assert(PathHelper.IsValidRelativePath(@".\Dir1\Dir2", out reason));Debug.Assert(PathHelper.IsValidRelativePath(@"..\Dir1\Dir2", out reason));Debug.Assert(PathHelper.IsValidRelativePath(@".\Dir1\..\Dir2", out reason));Debug.Assert(!PathHelper.IsValidRelativePath(@".\Dir1\..\..\Dir2", out reason));Debug.Assert(!PathHelper.IsValidRelativePath(@"C:\Dir1\Dir2", out reason));
  • I was talking to John Lam this week and he said: "BTW I’m having a ton of fun with C# 3.0 – it really is a beautiful language. Here’s an app that I wrote today that dumps all of our implemented Ruby methods to a YAML file." It'll be up on RubyForge later this week, but here's a snippet. It's about 100 lines and it takes a while to sink in. It's simple and it's a nice way to use LINQ against Reflection and the extension methods that use generics is nice and clean. Start at the Main() at the bottom and work your way around. Sure it could be shorter and hackier, but he appears to be balancing functionality with his own sense of aesthetic.

    我这周与约翰·林( John Lam )交谈时,他说:“顺便一句,我对C#3.0充满了乐趣–这确实是一种优美的语言。这是我今天编写的一个应用程序,它将我们所有已实现的Ruby方法转储到YAML文件。 “它将在本周晚些时候在RubyForge上发布,但这是一个代码段。 它大约有100行,需要花一些时间。它很简单,并且是对Reflect使用LINQ的好方法,而使用泛型的扩展方法又好又干净。 从底部的Main()开始,然后逐步解决。 当然,它可能会更短,更骇人,但他似乎在功能性和自己的审美意识之间取得了平衡。

  • 
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using Ruby;
    using Ruby.Extensions;
    using Microsoft.Scripting.Utils;
    using Ruby.Runtime;namespace IronRuby.Library.Scanner {static class ExtensionMethods {public static IEnumerable<T> SelectCustomAttributes<T>(this Type type) where T : Attribute {return type.GetCustomAttributes(typeof(T), false).Cast<T>();}public static IEnumerable<T> SelectCustomAttributes<T>(this MethodInfo method) where T : Attribute {return method.GetCustomAttributes(typeof(T), false).Cast<T>();}}class RubyClassInfo {public Type ClrType { get; set; }public delegate void Block(IEnumerable<RubyMethodAttribute> methods);public string Name {get { return ClrType.SelectCustomAttributes<RubyClassAttribute>().First().Name ?? ClrType.Name; }}private Type LookupExtensionModuleType(IncludesAttribute attr) {Type includedType;Program.ExtensionModules.TryGetValue(attr.Type, out includedType);return includedType ?? attr.Type;}private void GetMethodNames(Type t, Block accumulate) {var methods = (from m in t.GetMethods()where m.IsDefined(typeof(RubyMethodAttribute), false)select m.SelectCustomAttributes<RubyMethodAttribute>().First());accumulate(methods);foreach (IncludesAttribute attr in t.SelectCustomAttributes<IncludesAttribute>()) GetMethodNames(LookupExtensionModuleType(attr), accumulate);}private IEnumerable<string> GetMethodNames(RubyMethodAttributes methodType) {var result = new List<string>();GetMethodNames(ClrType, methods => result.AddRange((from m in methodswhere m.MethodAttributes == methodType select m.Name).Distinct()));result.Sort();return result;}public IEnumerable<string> InstanceMethods {get { return GetMethodNames(RubyMethodAttributes.PublicInstance); }}public IEnumerable<string> SingletonMethods {get { return GetMethodNames(RubyMethodAttributes.PublicSingleton); }}}class Program {static IEnumerable<RubyClassInfo> GetRubyTypes(Assembly a) {return from rci in(from t in a.GetTypes()where t.IsDefined(typeof(RubyClassAttribute), false) && !t.IsDefined(typeof(RubyExtensionModuleAttribute), false) select new RubyClassInfo { ClrType = t })orderby rci.Nameselect rci;}static Dictionary<Type, Type> GetExtensionModules(Assembly a) {var modules = from t in a.GetTypes()where t.IsDefined(typeof(RubyExtensionModuleAttribute), false)select new { Type = t, Attribute = t.SelectCustomAttributes<RubyExtensionModuleAttribute>().First() };var result = new Dictionary<Type, Type>();foreach(var m in modules)result[m.Attribute.Extends] = m.Type;return result;}const string RubyAssembly = @"Ruby, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";internal static Dictionary<Type, Type> ExtensionModules;static void DumpMethods(IEnumerable<RubyClassInfo> types, Func<RubyClassInfo, IEnumerable<string>> getMethods) {foreach (RubyClassInfo rci in types) {Console.WriteLine("{0}:", rci.Name);foreach (string methodName in getMethods(rci))Console.WriteLine("  - {0}", methodName);}}static void Main(string[] args) {var name = new AssemblyName(RubyAssembly);var a = Assembly.Load(name);ExtensionModules = GetExtensionModules(a);var types = GetRubyTypes(a);DumpMethods(types, t => t.InstanceMethods);DumpMethods(types, t => t.SingletonMethods);}}
    }

    Feel free to send me any links to cool source you find.

    随时给我发送任何链接到您找到的超酷资源的链接。

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

    知乎周源微信

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



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

相关文章

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外链微信推广短连接怎么做?

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