知乎周源微信_每周源代码9-WideFinder版

2023-12-20 11:50

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

知乎周源微信

知乎周源微信

In my new ongoing quest to read source code to be a better developer, I now present the ninth 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.

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

Ya, I know this one is just 4 days after the last one, but I was having too much fun and couldn't wait until Wednesday. Plus, it's a new week so poop on you.

是的,我知道这是最后一个比赛之后的第四天,但是我玩得太开心了,等不及要等到星期三。 另外,这是新的一周,所以请大便。

Last month Tim Bray shared his experiences writing a program that does, well, here's Joe Cheng's succinct description. Tim calls the project WideFinder.

上个月,蒂姆·布雷(Tim Bray)分享了他编写程序的经验,该程序很好地完成了Joe Cheng的简洁描述。 蒂姆将项目称为WideFinder

The Wide Finder challenge is to write a program that:

Wide Finder的挑战是编写一个程序,该程序:

  1. Scans logfiles for hits on blog articles

    扫描日志文件以查找博客文章中的点击

  2. which are counted and

    计算在内

  3. sorted with the

    排序

  4. top 10 most popular being printed to stdout. It should also

    前10大最受欢迎的被打印到标准输出。 它也应该

  5. be about as elegant and concise as Tim’s Ruby version and

    Tim的Ruby版本一样优雅简洁

  6. its performance should scale with additional CPU cores.

    它的性能应随其他CPU内核而扩展

And this is done on a fairly large log file of about 250 megs. While Item #6 is the most interesting, many folks are focusing on Item #5. Either way, it's a heck of a lot more interesting problem than FizzBuzz and worth adding to your interview arsenal pocket.

这是在大约250兆的相当大的日志文件上完成的。 虽然第6项是最有趣的,但许多人都在关注第5项。 无论哪种方式,这都是比FizzBu​​zz有趣得多的问题,值得添加到您的采访 武器库中

I encourage you to go check out Tim's site as he's continued to list the sources that he finds most interesting. As a primarily C# programmer who's always trying to stretch out of my comfort zone, here's what I've found interesting, in the order I found them interesting.

我鼓励您访问Tim的网站,因为他继续列出了他最感兴趣的来源。 作为一个主要的C#程序员,他总是试图超出我的舒适范围,这就是发现有趣的地方的顺序按照我发现它们有趣的顺序

  • Don Box's Naive Implementation in C# 3.0 - Apparently this is the kind of code Don can write after two beers. Notice the use of yield to make this "LINQ over a text file of CR/LF strings." That's one of those write-it-constantly-over-and-over-again helper methods that makes me wonder why it wasn't just included.

    Don Box在C#3.0中的朴素实现-显然,这是Don在喝完两杯啤酒后可以编写的代码。 请注意使用yield来制作“在CR / LF字符串的文本文件上的LINQ”。 那就是那些不断重复地写它的辅助方法之一,这让我想知道为什么不仅仅包含它。

    static void Main(string[] args){var regex = new Regex(@"GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)");var grouped = from line in ReadLinesFromFile(@"C:\temp\bray.txt")let match = regex.Match(line)where match.Successlet url = match.Valuegroup url by url;var ordered = from g in groupedlet count = g.Count()orderby count descendingselect new { Count = count, Key = g.Key };foreach (var item in ordered.Take(10))Console.WriteLine("{0}: {1}", item.Count, item.Key);}// LINQ-compatible streaming I/O helperpublic static IEnumerable<string> ReadLinesFromFile(string filename){using (StreamReader reader = new StreamReader(filename)) {while (true){string s = reader.ReadLine();if (s == null)break;yield return s;}}
  • Joe Cheng tightens it up with his LINQ skillz and does the group and sort all in one swell foop. As an aside, I'd like to see his QuickTimer class for next week. Nice use of my favorite C# idiom - IDisposable/using. Joe also alludes to some parallelism that could be easily added with PLINQ. Maybe we'll see that code soon.

    Joe Cheng用LINQ的技巧加强了工作,并一口气地进行小组整理。 顺便说一句,我想在下周看他的QuickTimer课程。 很好地使用了我最喜欢的C#习惯用法-IDisposable / using。 Joe还提到可以通过PLINQ轻松添加的一些并行性 也许我们会很快看到该代码。

  • using (new QuickTimer(“Total time”))
    {IEnumerable<string> data = new LineReader(args[0]);Regex regex = new Regex(@”GET /ongoing/When/\d\d\dx/\d\d\d\d/\d\d/\d\d/([^ ]+) “,RegexOptions.Compiled | RegexOptions.CultureInvariant);var result = from line in datalet match = regex.Match(line)where match.Successgroup match by match.Groups[1].Value into grporderby grp.Count() descendingselect new { Article = grp.Key, Count = grp.Count() };foreach (var v in result.Take(10))Console.WriteLine(“{0}: {1}”, v.Article, v.Count);
    }
  • My programmer's man-crushes continue as Jomo Fisher posts the WideFinder Naive F# Implementation. Notice how everyone uses "naive" to basically say "I'm sure it could be better, so don't be mean." I can't tell you with a straight face that I totally understand this. It's kind of magical.

    当Jomo Fisher发布WideFinder Naive F#实现时,我的程序员的心血继续。 请注意,每个人都是如何使用“天真”来基本说“我敢肯定这会更好,所以不要刻薄”。 我不能直率地告诉你我完全理解这一点。 有点神奇。

  • #light
    open System.Text.RegularExpressions
    open System.IO
    open System.Textlet regex = new Regex(@"GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)", RegexOptions.Compiled)let seqRead fileName =seq { use reader = new StreamReader(File.OpenRead(fileName))while not reader.EndOfStream doyield reader.ReadLine() }let query fileName = seqRead fileName|> Seq.map (fun line -> regex.Match(line)) |> Seq.filter (fun regMatch -> regMatch.Success)|> Seq.map (fun regMatch -> regMatch.Value)|> Seq.countBy (fun url -> url)*And here's the code to call it:    for result in query @"file.txt" do let url, count = result
  • Busting out of the Microsoft Languages for a minute, here's Tim's Ruby example:

    暂时退出Microsoft Languages,这是Tim的Ruby示例:
  • counts = {}
    counts.default = 0ARGF.each_line do |line|if line =~ %r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }counts[$1] += 1end
    endkeys_by_count = counts.keys.sort { |a, b| counts[b] <=> counts[a] }
    keys_by_count[0 .. 9].each do |key|puts "#{counts[key]}: #{key}"
    end
  • Here's the Java version from UnintentionalObjectRetention. I haven't done Java since I worked at Nike in 1997 as a contractor:

    这是UnintentionalObjectRetention的Java版本。 自从我1997年在耐克公司担任承包商以来,我还没有做过Java:

  • public class WideFinder {     public static void main(String[] args) throws IOException {      Map<String, Integer> counts = new HashMap<String, Integer>();      Pattern p = Pattern.compile("GET /ongoing/When/\\d\\d\\dx/(\\d\\d\\d\\d/\\d\\d/\\d\\d/[^ .]+) ");  BufferedReader in = new BufferedReader(new InputStreamReader(           new FileInputStream(args[0]), "US-ASCII"));         String line = null;     while ((line = in.readLine()) != null) {       Matcher m = p.matcher(line);       if (m.find()) {            String key = m.group();     Integer currentCount = counts.get(key);   counts.put(key, (currentCount == null ? 1 : (currentCount + 1)));     }}    in.close();      List<Entry<String, Integer>> results = new ArrayList<Map.Entry<String, Integer>>(counts.entrySet());      Collections.sort(results, new Comparator<Entry<String, Integer>>() {   public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2)        {            return o2.getValue().compareTo(o1.getValue());     }     });   for(int i = 0; i < 10; i++) {    System.out.println(results.get(i));    }}
    }
  • And last, but kind of first, here it is in LISP from Nate.

    最后,但首先,这里是Nate的LISP中。

  • (defun run (&rest logs)(let ((counts (make-hash-table :test #'equal)))(dolist (filename logs)(with-open-file (stream filename :direction :input:external-format :latin-1)(loop for line = (read-line stream nil stream)until (eq line stream)do (cl-ppcre:register-groups-bind (match)("GET /ongoing/When/\\d{3}x/(\\d{4}/\\d{2}/\\d{2}/[^ .]+) " line)(incf (gethash match counts 0))))))(loop for key being the hash-keys of countscollect key into keysfinally (map nil #'(lambda (x)(format t "~D: ~A~%" (gethash x counts) x))(subseq (sort keys #'>:key #'(lambda (x) (gethash x counts))) 0 10)))))

    A good way to understand other languages (programming or human) is to read the same story in each of these languages and compare them. Tim's problem serves that purpose well!

    理解其他语言(编程语言或人类语言)的一种好方法是用每种语言阅读相同的故事并进行比较。 蒂姆的问题很好地达到了这个目的!

    Oh, and if you want to see why we program in Managed Code, check out the C version.

    哦,如果您想了解我们为什么使用托管代码编程,请查看C版本。

    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-9-widefinder-edition

    知乎周源微信

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



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

相关文章

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项目 �