TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: What piece of code/codebase blew your mind when you saw it?

293 点作者 Decabytes超过 2 年前
Mine was when I learned a subset of recursion called mutual recursion. It was for a pair of function to determine if a number was odd or even.<p>(define (odd? x)<p><pre><code> (cond [(zero? x) #f] [else (even? (sub1 x))])) </code></pre> (define (even? x)<p><pre><code> (cond [(zero? x) #t] [else (odd? (sub1 x))]))</code></pre>

114 条评论

_whiteCaps_超过 2 年前
<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Duff%27s_device" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Duff%27s_device</a><p><pre><code> send(to, from, count) register short *to, *from; register count; { register n = (count + 7) &#x2F; 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n &gt; 0); } }</code></pre>
评论 #33416531 未加载
评论 #33414125 未加载
评论 #33415037 未加载
评论 #33414064 未加载
评论 #33416819 未加载
jph超过 2 年前
The Legendary Fast Inverse Square Root with &quot;Voodoo Black Magic&quot;<p><a href="https:&#x2F;&#x2F;medium.com&#x2F;hard-mode&#x2F;the-legendary-fast-inverse-square-root-e51fee3b49d9" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;hard-mode&#x2F;the-legendary-fast-inverse-squa...</a>
评论 #33414119 未加载
评论 #33416741 未加载
评论 #33423140 未加载
评论 #33416073 未加载
评论 #33414070 未加载
tfehring超过 2 年前
Quine Relay, &quot;a Ruby program that generates Rust program that generates Scala program that generates ...(through 128 languages in total)... REXX program that generates the original Ruby code again.&quot;<p><a href="https:&#x2F;&#x2F;github.com&#x2F;mame&#x2F;quine-relay" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mame&#x2F;quine-relay</a><p>(HN thread: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6048761" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6048761</a>)
评论 #33415081 未加载
评论 #33414827 未加载
评论 #33419033 未加载
评论 #33414920 未加载
pierrec超过 2 年前
I&#x27;ve read and re-implemented a lot of stuff by Inigo Quilez. Much of it is ingenious but eventually straightforward once you get the hang of it. I still find this particular snippet magical:<p><a href="https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;MdB3Dw" rel="nofollow">https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;MdB3Dw</a><p>Well, the code itself is simple GLSL. The math is (and I have not verified this) not that complex either, as I believe it&#x27;s all about integrating the raytracing equation for a moving sphere over the time variable. I guess what I find most impressive is just the fact that it works and that someone even thought of doing that. I also think this is currently the only example of this method being used anywhere, and it might mostly stay that way because the method might not be super generalisable.
评论 #33414364 未加载
评论 #33417365 未加载
评论 #33414350 未加载
评论 #33414566 未加载
评论 #33426138 未加载
SeanAnderson超过 2 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;chrislgarry&#x2F;Apollo-11&#x2F;blob&#x2F;a13539c7c5c482ffbbebf099ad3aada7d0f54fdf&#x2F;Luminary099&#x2F;LUNAR_LANDING_GUIDANCE_EQUATIONS.agc#L179" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;chrislgarry&#x2F;Apollo-11&#x2F;blob&#x2F;a13539c7c5c482...</a><p>My mind was blown that I could read Apollo 11 source code. It was additionally blown that it included comments like, &quot;# TEMPORARY, I HOPE HOPE HOPE&quot;
评论 #33416528 未加载
评论 #33417331 未加载
评论 #33417582 未加载
krylon超过 2 年前
Years ago, fresh out of training, I got a job that involved image recognition, and I spent a couple of weeks reading the code dealing with image processing. I was confused, until I realized that all the operations were basically the same, the only difference was the matrix of weights applied to the pixels.<p>That same week, I had a chat with a friend who at the time was dabbling in audio processing, and we tried to understand how lowpass and hipass filters worked. When we did understand it, I realized they worked basically the same as the image processing operations, just with a temporal aspect to it.
评论 #33414750 未加载
评论 #33414725 未加载
评论 #33415302 未加载
apeace超过 2 年前
I really don’t like that example. I get that it’s just demonstrating mutual recursion and not intended to be practical, but I feel like there could be other ways to demonstrate that concept that aren’t so inefficient.<p>My answer would be the jQuery code base, back in the day when that was popular. At the time I didn’t know a whole lot about Javascript or the DOM. I remember it feeling like the kind of code you could just read top to bottom and it was almost like reading a novel. Really well-organized, well-commented, and effective. I don’t know if it’s still like that, but at the time it was transformative for me.
评论 #33414614 未加载
评论 #33415897 未加载
tcgv超过 2 年前
I was mind blown in college when learning recursive programming and being introduced to the recursive solution to the Tower of Hanoi problem:<p>- <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tower_of_Hanoi#Recursive_implementation" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tower_of_Hanoi#Recursive_imple...</a><p>I remeber thinking &quot;where&#x27;s the rest of the code? It surely can&#x27;t be just those lines!&quot;
评论 #33416190 未加载
评论 #33415788 未加载
评论 #33414958 未加载
评论 #33414588 未加载
评论 #33421717 未加载
whalesalad超过 2 年前
Not code or a codebase - but reading <i>Eloquent Ruby</i> every morning on the DC Metro made the commute to work fly by in an instant and kinda blew my mind. I will try to illustrate the stuff that blew my mind below:<p>Quick backstory: a feature of Ruby (that you tend to either love or hate) is that you do not need to use parentheses to call a function.<p>if you have a function like so<p><pre><code> def prefix_hello(name) &quot;hello, #{name}!&quot; end </code></pre> you can call it like this<p><pre><code> prefix_hello &quot;fred&quot; =&gt; &quot;hello, fred!&quot; </code></pre> After learning about some of the spiritual ancestors of Ruby (like Smalltalk), message passing, learning everything is just an object and function calls are just messages being sent to objects, a lot of things clicked immediately for me. It was kind of a mind blown moment.<p>Take the `+` (add) symbol in `5 + 3` - in essence, it&#x27;s just a regular method that is literally caled `def +(number)`, which belongs to the int&#x2F;number object.<p>In laymans terms this code is saying, hey object (number) &#x27;5&#x27;, call your + method with &#x27;3&#x27; as the argument.<p>You can simulate this in an `irb` shell:<p><pre><code> irb(main):001:0&gt; x = 10 =&gt; 10 irb(main):002:0&gt; x.send(:+, 10) =&gt; 20 </code></pre> It&#x27;s all right there! `objectA.send(methodName, arg, arg, arg)`<p>Then you realize that this is true of many languages, Python included (__add__)... but I do think Ruby does this in a particularly, ahem, eloquent way that really impressed me.<p>This moment in my career&#x2F;learning was almost like a springboard&#x2F;catalyst and unlocked a lot of additional learning down the road, like getting involved with Erlang and Lisp&#x2F;Clojure.
jesse__超过 2 年前
Handmade Hero.<p>Before warching Casey program, it had not occurred to me you could sit down with a compiler and write an entire video game from scratch.<p>Then, I found out Jonathan Blow sat down and wrote his own compiler, followed by an engine, and now has a game in flight.<p>It&#x27;s a truly incredible what these guys (and their teams) get done.
评论 #33415589 未加载
评论 #33414863 未加载
评论 #33414387 未加载
评论 #33414383 未加载
评论 #33414618 未加载
评论 #33414733 未加载
评论 #33414857 未加载
smcameron超过 2 年前
Actually Portable Executables &#x2F; Cosmopolitan<p><a href="https:&#x2F;&#x2F;justine.lol&#x2F;ape.html" rel="nofollow">https:&#x2F;&#x2F;justine.lol&#x2F;ape.html</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;jart&#x2F;cosmopolitan" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jart&#x2F;cosmopolitan</a>
mattbee超过 2 年前
qmail was the first codebase I read that blew a lot of assumptions I had about &quot;good code&quot; and &quot;clean design&quot; out of the water.<p>It went its own way on a <i>lot</i> of things compared to GNU projects and achieved an enormous level of success for 10-15 years despite some really weird decisions. And even the &quot;wrong&quot; decisions, with hindsight, stemmed from a clear desire to keep creative control and a small codebase. I&#x27;d rather read well-documented &quot;bad&quot; code any day of the week.<p>Since then I&#x27;ve felt a bit of rebellion against standard practice is often a valuable if it&#x27;s 100% aligned with the goal of your project - reinventing a wheel, ignoring portability, picking a weird language, a new storage format, that kind of thing.<p>For an engineer it&#x27;s so easy to get sucked into assuming you should make standard, well-supported, well-understood choices that you suppress your more creative &amp; judgmental instincts.
gregfjohnson超过 2 年前
Ken Thompson&#x27;s self-perpetuating hack on the c compiler and login.c to create a back door that is invisible in the compiler source code and the source code of login.c. Described in his Turing Award acceptance speech, &quot;Reflections on Trusting Trust&quot;.
评论 #33417374 未加载
fouronnes3超过 2 年前
In python the inverse of the zip function is zip. You call it with with * to make list elements into function arguments. So a, b = zip(*c) is the inverse of c = zip(a, b).
评论 #33415256 未加载
评论 #33415265 未加载
评论 #33414717 未加载
jsrcout超过 2 年前
A binary rate-monotonic scheduler. It was in the Ada realtime executive for an avionics box (there was no OS). It executed tasks at 5 rates, each half as fast as the previous one. It was dead simple, something like (pseudocode)<p><pre><code> counter = 1 do highest priority stuff case counter when 1, 3, 5, 7, 9, 11, 13, 15 do high priority stuff when 2, 6, 10, 14 do medium priority stuff when 4, 12 do low priority stuff when 8 do lowest priority stuff (1st half) when 16 do lowest priority stuff (2nd half) end counter++ if counter &gt; 16 counter = 1 end </code></pre> This was called on a timer interrupt.<p>I was like &quot;what the heck does this do?&quot; followed by &quot;that sure reminds me of binary trees&quot; and finally &quot;whoa! cool!&quot;
评论 #33421997 未加载
lioeters超过 2 年前
For me it was the &quot;Make a Lisp&quot; project. Reading the architectural diagram of a Lisp interpreter, and browsing its implementation in many (~87) programming languages.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;kanaka&#x2F;mal" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kanaka&#x2F;mal</a><p>Especially where the guide explains how tail-call optimization works, my mind was blown.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;kanaka&#x2F;mal&#x2F;blob&#x2F;master&#x2F;process&#x2F;guide.md#step-5-tail-call-optimization" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kanaka&#x2F;mal&#x2F;blob&#x2F;master&#x2F;process&#x2F;guide.md#s...</a><p>Studying the project changed the way I understand code. Since then I&#x27;ve created my own little Lisps in about three or four versions&#x2F;languages. Next I&#x27;d like to write one in WebAssembly Text format, which is already in a Lisp-shaped syntax.
评论 #33416559 未加载
gnat超过 2 年前
I went through and commented the Perl tokeniser (toke.c) back in the late 90s&#x2F;early 2000s, and my mind was blown by the &quot;is this regular expression syntax involving $ or is it a variable interpolation involving $&quot;? logic which was basically &quot;here are some things we might have seen, make a weighted sum of which were actually seen and then if it&#x27;s greater than x, let&#x27;s assume it is variable interpolation&quot;.<p>You&#x27;ll note that we were busting that clean separation between tokeniser and parser. Yup, sometimes it&#x27;s hard to DWIM and still stay in your lane.<p>Just checked and, thanks to the hard work of far smarter people than myself, the whole thing has been refactored and now the better code has better comments. Progress is wonderful! (I couldn&#x27;t find the weighted guess, so maybe they found a way to work around it)
drittich超过 2 年前
Here&#x27;s the first that blew my mind, from the early 1980s: It was a BASIC &quot;AI&quot; program that would guess what animal you were thinking of just by asking a few questions. &quot;That&#x27;s crazy,&quot; I thought.<p>And, it learned more each time you ran it - even more crazy! It was only when I looked at the source code and realized that it was using self-modifying code that I went, &quot;Wait a minute - THAT&#x27;S A THING?&quot;<p>I had so many of those moments. The very first was realizing you could use an iterator variable to do other things within the loop. That&#x27;s the exact moment when programming clicked for me. My perception of it changed from being a glorified way to write out steps (like a hair-washing algorithm on a shampoo bottle) to realizing it could be very expressive and flexible.
frankjr超过 2 年前
Well, .NET&#x27;s garbage collector certainly springs to mind. Not exactly in a good way. You know you have something special on your hands when GitHub refuses to show you a highlighted version of a hand written C++ file (<a href="https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;runtime&#x2F;blob&#x2F;98984ccad55362a66b7fd7a8f198bab13c2496bc&#x2F;src&#x2F;coreclr&#x2F;gc&#x2F;gc.cpp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;runtime&#x2F;blob&#x2F;98984ccad55362a66b7fd...</a>).<p>Other than that, I remember my mind was blown a few times while watching Jim Weirich&#x27;s presentation on functional programming all those years ago (<a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=FITJMJjASUs" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=FITJMJjASUs</a>).
评论 #33414644 未加载
评论 #33414561 未加载
评论 #33414883 未加载
vinaypai超过 2 年前
The OPs example blows my mind but not in the way originally intended. Wow, it managed to make a trivial constant-time operation into an exponential-time operation. This is a mind-blowingly bad example of recursion.<p>It&#x27;s like trying to enter a house by demolishing it and rebuilding it around you instead of opening the door and walking in.
评论 #33416336 未加载
nequo超过 2 年前
Thanks to Haskell&#x27;s laziness, the following implementation of `minimum` is O(n):<p><pre><code> import Data.List (sortBy) minimum :: Ord a =&gt; [a] -&gt; a minimum = head . sortBy compare </code></pre> `sortBy` is O(n log n). But `head` only needs the first element which can be found in linear time. So `sortBy` does not compute the rest and `minimum` is O(n).
jeffreyrogers超过 2 年前
Arthur Whitney&#x27;s compiler for a language &quot;isomorphic to c&quot;: <a href="https:&#x2F;&#x2F;kparc.com&#x2F;b&#x2F;" rel="nofollow">https:&#x2F;&#x2F;kparc.com&#x2F;b&#x2F;</a>.<p>Amazing that someone can write correct, fast code like that.
评论 #33416189 未加载
nl超过 2 年前
The Peter Norvig spellchecker: <a href="https:&#x2F;&#x2F;norvig.com&#x2F;spell-correct.html" rel="nofollow">https:&#x2F;&#x2F;norvig.com&#x2F;spell-correct.html</a><p>I like it because it&#x27;s <i>so</i> clearly coded - there are no crazy syntax tricks or hacks - it&#x27;s just obviously the right way to write it. And yet it is compact, elegant and non-obvious if you are writing it yourself.
WalterBright超过 2 年前
The original ADVENT game in FORTRAN. It was way, way beyond my pedestrian programming. It even had OOP in it: &quot;a troll is a modified dwarf&quot;. And it did the marvelous thing of once it had gone through the world-building initialization, which took some time, it would <i>patch its own executable</i> with the results!<p>I used that trick for years until the virus scanners shut down that sort of activity. Sigh. This is why we can&#x27;t have nice things.
jacknews超过 2 年前
LFSR&#x27;s are mind blowing; the fact that you can generate a randomish sequence that covers an entire ^2 range visiting each number once, and only once, seems like a lucky piece of magic.<p>And in just a couple of lines, excuse my quickie untested code:<p><pre><code> #include &lt;stdio.h&gt; #include &lt;stdint.h&gt; &#x2F;&#x2F; 5-bit maximal LSFR taps to get pseudo-random sequence of 31 unique numbers in range 1-31 &#x2F;&#x2F; 0x12, 0x14, 0x17, 0x1B, 0x1D, 0x1E, 0x18, 0x17 int main(int c, char **v) { uint8_t taps = 0x17; &#x2F;&#x2F; could be any of the taps above uint8_t seed = 0x7; &#x2F;&#x2F; start, could be 1-31 uint8_t lfsr = seed; do { printf(&quot;%d\n&quot;, lfsr); lfsr = (lfsr &amp; 1) ? (lfsr &gt;&gt; 1) ^ taps : (lfsr &gt;&gt; 1); } while ( lfsr != seed ); return 0; }</code></pre>
评论 #33418856 未加载
andreygrehov超过 2 年前
Swap two variables using XOR:<p><pre><code> x ^= y; y ^= x; x ^= y; </code></pre> Check if the number is even:<p><pre><code> x &amp; 1 == 0</code></pre>
评论 #33419553 未加载
Trufa超过 2 年前
For me it was as simple as when I could start doing functional programming with javascript.<p>I was so surprised, since I had learned the other way first that it is actually easier to teach functional approaches with teenagers.<p>arr.map(x =&gt; x<i>2) was abundantly clearer than<p>const newArr = [] for(let i, i &lt; arr.length, i++) { newArr.push(arr[i]</i>2) }<p>And to be perfectly honest, I might have goofed the for loop.
评论 #33413955 未加载
评论 #33414597 未加载
评论 #33415793 未加载
评论 #33414501 未加载
评论 #33413967 未加载
brasetvik超过 2 年前
It has long since been cleaned up, but the history of Lucene&#x27;s Levenshtein automatons are a fascinating mix of pragmatism, hackery, grit, and engineering. Using a Python library to generate crazy-looking Java code, which you can&#x27;t (yet) understand, but whose tests pass and benchmarks look amazing.<p>- <a href="https:&#x2F;&#x2F;blog.mikemccandless.com&#x2F;2011&#x2F;03&#x2F;lucenes-fuzzyquery-is-100-times-faster.html" rel="nofollow">https:&#x2F;&#x2F;blog.mikemccandless.com&#x2F;2011&#x2F;03&#x2F;lucenes-fuzzyquery-i...</a> - <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=4AbcvHKX8Ow" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=4AbcvHKX8Ow</a><p>(Levenshtein distances are used as a measure between fuzzy&#x2F;misspelled matches, and was ironically misspelled initially - <a href="https:&#x2F;&#x2F;lucene.apache.org&#x2F;core&#x2F;7_4_0&#x2F;suggest&#x2F;org&#x2F;apache&#x2F;lucene&#x2F;search&#x2F;spell&#x2F;LevensteinDistance.html" rel="nofollow">https:&#x2F;&#x2F;lucene.apache.org&#x2F;core&#x2F;7_4_0&#x2F;suggest&#x2F;org&#x2F;apache&#x2F;luce...</a>)
Isamu超过 2 年前
Lots of good responses here, so I’ll give an example that blew my mind in a negative way:<p>Fortran IV code, thousands of lines, no functions, only GOTOs jumping everywhere randomly. Mostly one or two letter variables, lots of GOTOs that turned out to be loops, with lots more jumping into the middle of them and jumping out of them into other loops. No documentation, I was supposed to modularize it. Failed.<p>But it successfully calculated thermodynamic properties for engineering designs, so go figure.
mjw1007超过 2 年前
Hashlife.<p>I&#x27;m pretty sure that if something of the sort had occurred to me before I came across it, I would have thought &quot;that&#x27;ll never work&quot; and moved on without taking it seriously.
amake超过 2 年前
I&#x27;m partial to this snippet from SICP (4.2.3 Streams as Lazy Lists):<p><pre><code> (define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p))) (define (cdr z) (z (lambda (p q) q))) </code></pre> This implements cons-style linked lists in terms of only functions. In other words lists need not be the fundamental construct of a Lisp&#x2F;Scheme—you can use functions instead.
steveAllen0112超过 2 年前
I love learning programming, and also math, because I feel like my mind is blown every time I come across a new concept.<p>However, it&#x27;s rare for that feeling to obtain just by programming in a language. One language that (so far) has consistently had that feeling even when simply programming in it is Dyalog APL.<p>To think that it&#x27;s so expressive that naming things is often unnecessary, the name being the function itself.... It feels like I&#x27;m playing with raw essence.<p>+&#x2F;÷≢ is the classic example, of course. That&#x27;s four characters -- the &quot;tally&quot; character at the end tends to render wrong in browsers, but I assure you it really is only one character. Four characters! What is the name of the function? Either &quot;Mean&quot;, or &quot;Average&quot;, one of which is four characters itself, and the other longer. Of course, you could just say, &quot;Avg&quot;, but why bother?<p>And this contains in itself another example. +&#x2F; being &quot;Sum&quot;, which is longer. And &quot;Product&quot; is an even higher contrast: ×&#x2F;<p>This language also has the added mind-blowing feature where the glyphs are often visually related when they are functionally related.<p>So &quot;Scan&quot; is \. Therefore, &quot;Running Sum&quot; aka &quot;Plus Scan&quot; is +\. Likewise &quot;Running Product&quot; aka &quot;Multiply Scan&quot; is -- you guessed it! -- ×\.<p>And there is so much more. I&#x27;ve been doing APL for a while now (IDR if it&#x27;s a full year yet or not, but it&#x27;s getting close I think), and it keeps blowing my mind over and over again. It&#x27;s gotten to the point where when writing APL I feel like I&#x27;m just spelling out my thoughts for the most part. I&#x27;ve never gotten that feeling in any other language, and it&#x27;s a mind-blowing feeling.
MaxBorsch228超过 2 年前
A snippet of pandas code in a notebook I saw when learning pandas, it looked like this:<p><pre><code> def to_minutes(df, col): df[col] = df[col].dt.minutes return df ( pd .read_csv(&#x27;data.csv&#x27;) .assign(dur=df.finish-df.start) .pipe(to_minutes, col=&#x27;dur&#x27;) .query(&#x27;dur &lt; 30&#x27;) .sort_values(by=&#x27;dur&#x27;) .pipe( seaborn.relplot, x=&#x27;dur&#x27;, y=&#x27;distance&#x27;, hue=&#x27;city&#x27; ) ) </code></pre> It&#x27;s a simple snippet but the code structure is clever in many ways. The enclosure of the whole expression, starting with pd, into () makes it possible to split method chaining into multiple lines without backslashes and start each line with &quot;.&quot;. Now we can treat DataFrame methods similarly to verbs from dplyr data grammar and &quot;.&quot; similarly to %&gt;% operator. Its now easy to rearrange, add and delete whole lines without thinking if we forgot to add &quot;.&quot; to the line above or below. Everything is immutable, no side effects, it&#x27;s safe to copy the code in a new notebook cell and tweak it a little without worrying about tens of temporary df2_copy1 variables. The .pipe method allows to avoid &quot;df = df[...]&quot; junk, to reuse code fragments and even to use plotting libraries in ggplot fashion. If the chain becomes huge, just put it in a function and apply in to df using pipe method, etc... I wonder if it&#x27;s possible to add memorization to pipe method to avoid recalculating the whole construction every time when rerunning the cell during debugging.
评论 #33416832 未加载
kazinator超过 2 年前
How about, that C program which produces random dot (well, character) stereograms, whose source code is such a stereogram?<p>Winner of 2001 IOCCC:<p><a href="https:&#x2F;&#x2F;www.ioccc.org&#x2F;2001&#x2F;herrmann2.c" rel="nofollow">https:&#x2F;&#x2F;www.ioccc.org&#x2F;2001&#x2F;herrmann2.c</a>
billyhoffman超过 2 年前
Function pointers<p>I was a self-taught programmer as a teenager so there was a lot of theory and mental models I was missing. I viewed code as something static I wrote into an editor and later interpreted (QBasic) or compiled and ran (C).<p>Learning about function pointers in C was transformational. I started thinking about code as data that can be called and passed around and even changed at runtime and suddenly things like cooperative multi tasking made sense to me.
评论 #33419571 未加载
xeeeeeeeeeeenu超过 2 年前
PPR - Pattern-based Perl Recognizer. It&#x27;s basically a <i>giant</i> regex that matches Perl code.<p>The regex itself: <a href="https:&#x2F;&#x2F;metacpan.org&#x2F;dist&#x2F;PPR&#x2F;source&#x2F;lib&#x2F;PPR.pm#L65" rel="nofollow">https:&#x2F;&#x2F;metacpan.org&#x2F;dist&#x2F;PPR&#x2F;source&#x2F;lib&#x2F;PPR.pm#L65</a><p>Documentation: <a href="https:&#x2F;&#x2F;metacpan.org&#x2F;pod&#x2F;PPR" rel="nofollow">https:&#x2F;&#x2F;metacpan.org&#x2F;pod&#x2F;PPR</a>
评论 #33420010 未加载
gorgoiler超过 2 年前
Rob Pike’s lexer was very nicely done and struck a chord with me. It’s not nearly as magical as some of the other things here. It’s just great engineering:<p><a href="https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=HxaD_trXwRE" rel="nofollow">https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=HxaD_trXwRE</a>
ponsfrilus超过 2 年前
&gt; The IOCCC Flight Simulator was the winning entry in the 1998 International Obfuscated C Code Contest. It is a flight simulator in under 2 kilobytes of code, complete with relatively accurate 6-degree-of-freedom dynamics, loadable wireframe scenery, and a small instrument panel.<p>&gt; IOCCC Flight Simulator runs on Unix-like systems with X Windows. As per contest rules, it is in the public domain.<p><a href="https:&#x2F;&#x2F;blog.aerojockey.com&#x2F;post&#x2F;iocccsim" rel="nofollow">https:&#x2F;&#x2F;blog.aerojockey.com&#x2F;post&#x2F;iocccsim</a><p>Oh, and the code is shaped as a plane. Pretty awesome.
Kuinox超过 2 年前
This .NET Dictionary&lt;Type,T&gt; that allow very cheap lookup when your key is a type. <a href="https:&#x2F;&#x2F;github.com&#x2F;asynkron&#x2F;protoactor-dotnet&#x2F;blob&#x2F;dev&#x2F;src&#x2F;Proto.Actor&#x2F;Utils&#x2F;TypedDictionary.cs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;asynkron&#x2F;protoactor-dotnet&#x2F;blob&#x2F;dev&#x2F;src&#x2F;P...</a>
btown超过 2 年前
ICantBelieveItCanSort: <a href="https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;2110.01111.pdf" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;2110.01111.pdf</a>
treffer超过 2 年前
For codenbases... Objectweb ASM blew my mind.<p>It&#x27;s a library to read&#x2F;write java class files. The core at that time would fit into 2 java files.<p>It was a reader and a writer built around a visitor pattern. At that time apache bcel was also big, a library to build in-memory class file representations which you would then manipulate. ASM allowed you to do many transformation without ever holding the whole file in memory.<p>ASM also had an in-memory representation as an add-on. It was all nicely layered and the core was just a marvelous small piece of code, with incredible low memory consumption.
skruger超过 2 年前
Arthur Whitney’s J Incunabulum: <a href="https:&#x2F;&#x2F;code.jsoftware.com&#x2F;wiki&#x2F;Essays&#x2F;Incunabulum" rel="nofollow">https:&#x2F;&#x2F;code.jsoftware.com&#x2F;wiki&#x2F;Essays&#x2F;Incunabulum</a>
srik超过 2 年前
CPS comes to mind (Continuation passing style). Apparently continuations really do it for me. One of the many gains from picking up functional programming is stumbling upon little &quot;pearls&quot; like these that I wouldn&#x27;t have otherwise.<p><a href="https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Haskell&#x2F;Continuation_passing_style" rel="nofollow">https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Haskell&#x2F;Continuation_passing_s...</a>
AnthonBerg超过 2 年前
The Idris codebase is quite beautiful. Given some understanding of how it works underneath, I find that there’s a succinct clarity in everything.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;idris-lang&#x2F;Idris2" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;idris-lang&#x2F;Idris2</a>
davchana超过 2 年前
Mine was super basic, one of many, that a 0 DAY can push an excel date a day behind, so DATE(2022, 10, 0) means Last Day of October. No need to keep an array of which month has 30, 31 or 28&#x2F;29 days. Simple DATE(2022,3,0) gives the last day of February.
endgame超过 2 年前
Lenses, and going from lenses to optics more generally. You start with what looks like a bad reinvention of &quot;dot notation&quot; to deal with updates on nested records, but then as you generalise, it turns into a deep well to draw from. You get an incredibly powerful toolkit to query&#x2F;summarise&#x2F;transform&#x2F;rewrite data structures, and it&#x27;s the only library I know where compositionality is _enhanced_ by _exposing_ its inner workings:<p>Here is SPJ giving a talk on them: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=k-QwBL9Dia0" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=k-QwBL9Dia0</a>
评论 #33417235 未加载
altitudinous超过 2 年前
A book called &quot;Astronomical Algorithms&quot; was written back in the 80&#x27;s or 90&#x27;s. It was very exciting and inspirational for me that the sun and moon and the position of planets - nature itself - could be predicted by code. It still is an inspiration for me today.
评论 #33419751 未加载
nanumbat超过 2 年前
My first job in 1987 was porting all of Oracle&#x27;s source code (entirely in C for 32 bit architectures) to a 64 bit Control Data mainframe.<p>So, that.
评论 #33414049 未加载
pawelduda超过 2 年前
More of a shell snippet, but removing duplicate lines with awk is one that comes to my mind:<p>awk &#x27;!seen[$0]++&#x27;
w1nst0nsm1th超过 2 年前
The python code for a NN to learn addition.<p>I know it seems trivial, but back then, it seemed everybody talked about it, there was that coursera course about driving car, the self promotion of towarddatascience.com, video on youtube... but not a single line of code which made sense.<p>I mean : &quot;Shut the fuck up and show me the actual code !&quot;.<p>I finally found it on github.<p>I was like : <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=xYHJRhRym1U" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=xYHJRhRym1U</a>
omoikane超过 2 年前
IOCCC taught me that form is just as important as function, and often a lot more fun:<p><a href="https:&#x2F;&#x2F;www.ioccc.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.ioccc.org&#x2F;</a>
thunderbird120超过 2 年前
Stolen from 4chan. Not malicious, just prints out a string, but in terms of code density is simultaneously some of the smartest and dumbest code I&#x27;ve ever seen. Bonus points if you can actually figure out exactly how it works.<p><pre><code> #include &lt;stdint.h&gt; #include &lt;stdio.h&gt; int main() { &#x2F;&#x2F;the following code should be self-explanatory int format = 684837; uint64_t freqs[16] = {4557704611105873944,6293041952211349568,7232032755832676440,9836271091686599272,11342418091143829394,7666925796986299039,8289648}; uint64_t phases[16] = {2745812699376323861,4477710776532278558,4107622644641439798,4062343665106426382,4257685111635071841,2598073413584315427,1713226}; uint64_t composite[32] = {0}; int i = 0; unsigned char frequency = i[(char*)(freqs)]; unsigned char phase = i[(char*)(phases)]; while (frequency &gt; 0){ for (int j=phase;j&lt;2048;j+=frequency){ (j&#x2F;64)[composite] |= ((uint64_t)1 &lt;&lt; j%64); } frequency = (i%64)[(char*)(freqs+i&#x2F;64)]; phase = (i%64)[(char*)(phases+i&#x2F;64)]; i++; } printf((char*)&amp;format, composite); return 0; }</code></pre>
评论 #33417301 未加载
nicklaf超过 2 年前
Not programming per se, but: mathematical induction. It feels like cheating to get an infinite number of true statements by cleverly setting up a deductive argument.
Phrodo_00超过 2 年前
The actual y combinator (for recursive anonymous functions) took me a while to understand, and I&#x27;m pretty sure that by now I&#x27;ve forgot how it works and would need to take a second look at it.<p>On the less functional side, Linux linked lists are super smart.
eb0la超过 2 年前
A flight simulator called fly8 had an interesting C structure made of pointers to functions. It was a way to declare a device driver in C.<p>Years later I could tell my colleagues how a device driver&#x2F;plugin actually worked (before COM&#x2F;etc) just with this.
评论 #33414833 未加载
评论 #33414359 未加载
fegu超过 2 年前
The doom square root trick. Reducing an expensive function to almost nothing with low error. Many writeups on the web far better than I could give.
评论 #33414093 未加载
评论 #33416868 未加载
评论 #33414356 未加载
fny超过 2 年前
In Ruby, all of the following statements are true:<p><pre><code> Class.ancestors.include?(Object) Object.ancestors.include?(Class) Class.is_a?(Object) Object.is_a?(Class) </code></pre> It&#x27;s beautiful.
评论 #33420189 未加载
pklausler超过 2 年前
Haskell:<p><pre><code> primes = filterPrime [2..] where filterPrime (p:xs) = p : filterPrime [x | x &lt;- xs, x `mod` p &#x2F;= 0]</code></pre>
评论 #33414721 未加载
评论 #33414063 未加载
评论 #33418355 未加载
评论 #33414077 未加载
throwitaway111超过 2 年前
The codebase that has most blown my mind is the one I currently work on. It is the biggest steaming pile of garbage I&#x27;ve ever seen. It&#x27;s a Rails app developed by two guys who had never worked as developers before. They built an MVP that found immediate traction in their market and so they hired some slightly more experienced contractors to add features. It is shockingly poorly designed. We&#x27;ve hired an army of talented people to try to fix things so we can actually get to the point where we can add new features but I&#x27;m not sure we&#x27;ll ever get there.<p>Until this job I hadn&#x27;t realized how blessed I had been in my career to work at companies that took software development seriously. I can safely say that every instance of &quot;bad code&quot; I had run into previous to this one was really nothing.<p>I&#x27;m not sure how much longer I&#x27;ll stay here tbh. The place is toxic for a variety of reasons not just the software.
fferen超过 2 年前
Data from functions:<p>(define (cons x y) (lambda (m) (m x y)))<p>(define (car z) (z (lambda (p q) p)))<p>(define (cdr z) (z (lambda (p q) q)))
评论 #33414605 未加载
评论 #33416141 未加载
fegu超过 2 年前
Swapping two variables without a temporary using xor.
评论 #33417389 未加载
评论 #33414083 未加载
评论 #33414607 未加载
评论 #33414331 未加载
tabtab超过 2 年前
APL. I didn&#x27;t care for the particular symbols, but the concept blew my mind, and got me interested in &quot;table oriented programming&quot; (TOP) and later the SMEQL query language (what SQL should have been). I&#x27;d often make table-driven logic using dBASE&#x2F;xBASE back in its day because it was so nimble to edit meta-attributes AND put code in tables with it.<p>I still believe in data-dictionaries to drive CRUD instead of crap like C#&#x2F;Java &quot;annotations&quot; on model classes, but our current tools and languages are not TOP-friendly. I&#x27;m convinced TOP is the future, I just don&#x27;t know when. Some say &quot;you lose type checking&quot;, but relational integrity can do much the same thing if set up right. I do personal TOP R&amp;D, but the job is too big for 1 hobbyist.
cpeterso超过 2 年前
The O(1) sleep sort algorithm: <a href="https:&#x2F;&#x2F;www.cs.princeton.edu&#x2F;courses&#x2F;archive&#x2F;fall13&#x2F;cos226&#x2F;lectures&#x2F;52Tries.pdf" rel="nofollow">https:&#x2F;&#x2F;www.cs.princeton.edu&#x2F;courses&#x2F;archive&#x2F;fall13&#x2F;cos226&#x2F;l...</a>
评论 #33416097 未加载
评论 #33415896 未加载
cruegge超过 2 年前
A more advanced example of mutual recursion: it&#x27;s possible to perform an exhaustive search over the &quot;Cantor space&quot; of all infinite sequences of bits that either finds a sequence satisfying a (total, computable) predicate or determines that such a sequence doesn&#x27;t exist. That is to say, there&#x27;s a function `search`,<p><pre><code> type Cantor = Natural -&gt; Bit search :: (Cantor -&gt; Bool) -&gt; Maybe Cantor </code></pre> that returns in finite time if its argument does.<p>Source: <a href="https:&#x2F;&#x2F;math.andrej.com&#x2F;2007&#x2F;09&#x2F;28&#x2F;seemingly-impossible-functional-programs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;math.andrej.com&#x2F;2007&#x2F;09&#x2F;28&#x2F;seemingly-impossible-func...</a>
jansan超过 2 年前
Euclidean algorithm as a one-line function:<p><pre><code> function gcd(a,b){ return b ? gcd(b, a%b) : a; }</code></pre>
评论 #33414643 未加载
评论 #33426189 未加载
评论 #33416956 未加载
评论 #33413868 未加载
bovermyer超过 2 年前
...none. Not because I&#x27;ve never seen mindblowing code, but because I&#x27;ve never understood it for what it was when first seeing it.<p>I&#x27;m a slow learner.
just_for_you超过 2 年前
The Unreal Engine 4 code, when it first went open-ish source. I was blown away by how huge it was, but yet, how clean and modular everything was.
insaider超过 2 年前
Ray Casting Algorithm is neat because it&#x27;s immediately understandable efficiency <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Point_in_polygon" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Point_in_polygon</a>
评论 #33417379 未加载
tonnydourado超过 2 年前
The `@inlineCallbacks` decorator from Twisted. Not the implementation, even, just what it does. Understanding it was what finally made async click in my head.
EdwardCoffin超过 2 年前
Richard Bird&#x27;s Haskell program to solve Sudoku, both the final product and the process of deriving it from a series of less efficient versions, as described in his functional pearl paper [1]<p>[1] <a href="https:&#x2F;&#x2F;www.cs.tufts.edu&#x2F;~nr&#x2F;cs257&#x2F;archive&#x2F;richard-bird&#x2F;sudoku.pdf" rel="nofollow">https:&#x2F;&#x2F;www.cs.tufts.edu&#x2F;~nr&#x2F;cs257&#x2F;archive&#x2F;richard-bird&#x2F;sudo...</a>
onos超过 2 年前
I learned programming informally via scientific project work. When I learned about hashing and O(1) lookup the power of it truly blew my mind.
评论 #33416919 未加载
pyjarrett超过 2 年前
C++&#x27;s &quot;Curiously Recurring Template Pattern&quot;<p><pre><code> template &lt;typename T&gt; class Foo {}; class Bar : public Foo&lt;Bar&gt; { ... }; </code></pre> <a href="https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;language&#x2F;crtp" rel="nofollow">https:&#x2F;&#x2F;en.cppreference.com&#x2F;w&#x2F;cpp&#x2F;language&#x2F;crtp</a>
评论 #33414019 未加载
dunham超过 2 年前
A year or so ago I stumbled across the A-normalization code discussed here:<p><a href="https:&#x2F;&#x2F;matt.might.net&#x2F;articles&#x2F;a-normalization&#x2F;" rel="nofollow">https:&#x2F;&#x2F;matt.might.net&#x2F;articles&#x2F;a-normalization&#x2F;</a><p>I&#x27;ve got a fairly good grasp on recursion, but it took some effort to get a mental model of what was going on (k is what to do with the inside thing), because it&#x27;s doing both recursion and continuation passing at the same time. It feels like a technique that could come in handy someday.<p>Not code&#x2F;codebase, but I also want to mention the transform behind bzip:<p><a href="https:&#x2F;&#x2F;www.hpl.hp.com&#x2F;techreports&#x2F;Compaq-DEC&#x2F;SRC-RR-124.pdf" rel="nofollow">https:&#x2F;&#x2F;www.hpl.hp.com&#x2F;techreports&#x2F;Compaq-DEC&#x2F;SRC-RR-124.pdf</a><p>I understand how it works, but it seems magical that you can sort all of the rotations, take the last column, and still be able to recover the original text.
LarsDu88超过 2 年前
Fast inverse square root. Commonly attributed to john carmack, it actually predates his application of it by several years
评论 #33419833 未加载
iLoveOncall超过 2 年前
I interned at a web agency a long time ago and none of their technical people were more than integrators for WordPress and Drupal but sometimes they had to dable in custom modules and stuff like that, which was clearly not their strong suit.<p>Anyway, one of the modules had a piece of code that was checking what was in a mailbox, and the name of that function was literally &quot;butWhatIsItThatThereIsInThatMailbox()&quot;.<p>For another project I used Laravel to make a website, and they needed to add a feature after it went to production but I was not working there anymore. I later learned that they just did a &quot;mysql_connect&quot; and ran their query directly in the view&#x27;s template because they didn&#x27;t know how to use the framework to make a DB query and pass the data to the view.<p>And they had HUGE clients that everyone has heard of.<p>So yeah, mind blowing.
niepiekm超过 2 年前
Although I have not seen the source code, I was mind blown when first heard of and saw the demo of the Sketchpad, a program created by Ivan Sutherland in 1963.<p><a href="http:&#x2F;&#x2F;scihi.org&#x2F;ivan-sutherland-computer-graphics&#x2F;" rel="nofollow">http:&#x2F;&#x2F;scihi.org&#x2F;ivan-sutherland-computer-graphics&#x2F;</a><p>Ph.D. thesis: - <a href="https:&#x2F;&#x2F;dspace.mit.edu&#x2F;handle&#x2F;1721.1&#x2F;14979" rel="nofollow">https:&#x2F;&#x2F;dspace.mit.edu&#x2F;handle&#x2F;1721.1&#x2F;14979</a> (1963 original), - <a href="https:&#x2F;&#x2F;www.cl.cam.ac.uk&#x2F;techreports&#x2F;UCAM-CL-TR-574.{html,pdf}" rel="nofollow">https:&#x2F;&#x2F;www.cl.cam.ac.uk&#x2F;techreports&#x2F;UCAM-CL-TR-574.{html,pd...</a> (2003 electronic edition)
ChrisMarshallNY超过 2 年前
My first real software engineering job.<p>I was put in charge of the company&#x27;s email program. This was in 1987-8.<p>It was a single file, with over 100 KLoC of 1970s-vintage FORTRAN IV code.<p>Not one single comment.<p>Variables written like INTEGER A1, for a buffer index.<p>No subroutines.<p>GOTOs galore.<p>That was some trauma that convinced me to write good, structured, well-documented code, from then on.
jsrcout超过 2 年前
Almost forgot - Lisp In Life. Pretty sure I first saw it here at HN. IMO the most amazing part is the Life-based processor - once you have that, the rest is &quot;merely&quot; a matter of adding layers. But it&#x27;s one thing to know someone <i>could</i> do it, quite another to see it in action.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;woodrush&#x2F;lisp-in-life" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;woodrush&#x2F;lisp-in-life</a><p>Run it in your browser here. Definitely worth zooming all the way in to get a sense of scale.<p><a href="https:&#x2F;&#x2F;woodrush.github.io&#x2F;lisp-in-life&#x2F;" rel="nofollow">https:&#x2F;&#x2F;woodrush.github.io&#x2F;lisp-in-life&#x2F;</a>
nraynaud超过 2 年前
When I was a student, I went to a programming lab one very hangover morning, new teacher. He was a bit ambitious and he had us program a visitor pattern in smalltalk, it really openend my mind on using the vtable as a flow control system.
gaudat超过 2 年前
The Elixir |&gt; (pipeline &#x2F; nose) operator. Makes functional programming much cleaner without brackets or intermediate variables. I wish more programming language has this. JavaScript comes close with chained calls of map.
评论 #33417265 未加载
评论 #33415197 未加载
评论 #33416793 未加载
评论 #33414709 未加载
aliqot超过 2 年前
the rotating donut written in C shaped like a donut, also a lot of early demoscene written by hand in assembly
mbrodersen超过 2 年前
The Lambda Calculus. So simple. So powerful. Still studied today.
评论 #33418374 未加载
scarecrowbob超过 2 年前
Learning that I could pass a -function- as a value blew my mind for sure.<p>I&#x27;d been programming for quite a while at that point, though mostly it was self-taught or procedural&#x2F;OOP things I had learned in school.<p>That made a lot of impacts on how I thought about programming; basically until tha point I had never encountered functional programming, and boop it pushed me off a big ol&#x27; cliff.
SamReidHughes超过 2 年前
Reverse Polish Lisp (on the HP 49G) for starters.<p>The basic Haskell function definition,<p><pre><code> factorial 0 = 1 factorial n = n * factorial (n - 1)</code></pre>
icelancer超过 2 年前
A lot of VGA&#x2F;SVGA paging blew my mind 20-25 years ago when I saw it.<p>Frankly, it still does. Low-mid level graphics code is incredible wizardry.
评论 #33414446 未加载
rrwo超过 2 年前
A lot of code from The Art of Prolog that used some form of accumulator data structure as a third argument to predicates.
评论 #33415877 未加载
jimcsharp超过 2 年前
Not code but I always marvel at the relational databases of creaky Enterprise behemoths - SharePoint, SAP, etc...
alexeiz超过 2 年前
Clojure transducers (<a href="https:&#x2F;&#x2F;clojure.org&#x2F;reference&#x2F;transducers" rel="nofollow">https:&#x2F;&#x2F;clojure.org&#x2F;reference&#x2F;transducers</a>). It&#x27;s clearly a functional construct, but somehow I haven&#x27;t seen it being used in other functional languages.
评论 #33417723 未加载
brailsafe超过 2 年前
It would have to be an HID interface for some controller I ran into. It was essentially a large switch that used bitwise operations against some magic byte as the cases to determine which button was pressed. Avoided using variables or an enum which I thought was interesting
_448超过 2 年前
I do not have access to a C compiler at the moment so cannot verify this with latest compiler but one thing I remember seeing long time ago was that you can interchange an array name and it&#x27;s index, something like this: a[i] can also be written as i[a]
derekpankaew超过 2 年前
YOLO v3&#x27;s paper is hilarious. The model was state of the art at the time, yet it&#x27;s written in a tongue-in-cheek way:<p><a href="https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1804.02767.pdf" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;pdf&#x2F;1804.02767.pdf</a>
yencabulator超过 2 年前
I think groupcache and singleflight are surprisingly simple for what they do: <a href="https:&#x2F;&#x2F;go.dev&#x2F;talks&#x2F;2013&#x2F;oscon-dl.slide" rel="nofollow">https:&#x2F;&#x2F;go.dev&#x2F;talks&#x2F;2013&#x2F;oscon-dl.slide</a>
ranger_danger超过 2 年前
notcurses: <a href="https:&#x2F;&#x2F;github.com&#x2F;dankamongmen&#x2F;notcurses" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dankamongmen&#x2F;notcurses</a><p>The guy is a literal genius, I hope to forget half the stuff he knows.<p>Also Fabrice Bellard (ffmpeg&#x2F;qemu) and Inigo Quilez.
joshxyz超过 2 年前
messagepack implementations.<p>made me realize how much knobs are there in writing a data to bytes encoding function.. you get to pick a trade off between readability, ease of implementation (in other language), encoding speed, encoding output size, and more.
potta_coffee超过 2 年前
I saw the title, came to post the exact code that OP posted. It&#x27;s from Dybvig&#x27;s Scheme programming language book. I remember going through that book and just being blown away by the elegance of Scheme.
mattmiller超过 2 年前
Its been a while since I worked with this lib but I always thought Pygments was pretty.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;pygments&#x2F;pygments" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pygments&#x2F;pygments</a>
orsenthil超过 2 年前
A recursive version of depth first search that I coded in python while practicing for interviews with leetcode. Recusion and DFS is so elegant.
bombcar超过 2 年前
I feel the SCP foundation has something about a Cthulhu codebase that literally explodes the brains of all who read it.<p>And I feel I’ve worked on that codebase …
评论 #33415308 未加载
评论 #33426242 未加载
swyx超过 2 年前
it isn&#x27;t rocket science, but <a href="https:&#x2F;&#x2F;github.com&#x2F;fkling&#x2F;astexplorer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fkling&#x2F;astexplorer</a> significantly raised my standard of what a readable, modifiable, nontrivial react&#x2F;redux codebase could look like. bonus that astexplorer is basically used by everyone in the js tooling ecosystem
pkrumins超过 2 年前
SQLite’s codebase - the test to code ratio is something like 1 to 20000. It’s the most tested codebase in existence.
looopTools超过 2 年前
Sadly I cannot share the code. But some COBOL code used for validation of financial transactions. It was crazy!
ihaveabeardnow超过 2 年前
I once saw a 20k line Java source file, being used in production... no it wasn&#x27;t generated. that blew my mind.
评论 #33414012 未加载
评论 #33415343 未加载
thenipper超过 2 年前
Most legacy ML models I’ve had to move to production aka not on a laptop. Oh you meant in a good way…
DanielHB超过 2 年前
Hash tables are something I learned in college and was just mind-blown, so simple and so useful
bane超过 2 年前
There was a youtube video a few years back that showed a guy livecoding...I think an ECMA interpreter, or maybe a WASM interpreter from scratch using some very easy to follow code. I can&#x27;t remember what it was or the video, but it was gobsmacking. So instead here&#x27;s another story.<p>I once worked with an old Perl greybeard, he had written some kind of code that could parse an almost impossible large set of string formats that a large collection of automated systems produced except they all had some sort of non-standard&#x2F;non-guaranteed formatting or semantics. Little bits and pieces (some semi-atomic bits) of them were semi-reliable, but the aggregate strings were just a huge mess, things came in all kinds of orders, had unreliable separators (if any) some things came in backwards, some forwards, and so on.<p>You might imagine them to be things like IP addresses that sometimes had system names attached, sometimes locations, sometimes, no address, sometimes the address was separated by dots or commas, sometimes, pieces of equipment were listed. All legacy of decades of people slowly accruing bits and pieces of the larger system and naming things for local convenience rather for global understanding. As the systems rolled up these strings would <i>sometimes</i> get concatenated in different ways and in different orders.<p>His code looked like total gibberish, a library of a bunch of code that sort of looked like Perl but also sort of looked like a custom rule language, it had something like 1200 rules in it based on the kinds of &quot;atomics&quot; he&#x27;d observed. The rules were sort of pieces of regexes, and then a string with embedded functions in it.<p>And then some bizarre code elsewhere I also didn&#x27;t get at first.<p>It turned out the code was clever way of writing a meta program that would assemble new code on the fly that was capable of processing every possible string format -- potentially billions of them. At the core of the code was simple lexer that atomized the strings based on a few heuristics (nonstandard of course), and then would apply the rules to each lexical piece.<p>It turns out the rules were regexes that emitted code snippets on match. The snippets were often templated to take pieces of the atomic bits and the regex would parse the atom and put the pieces into the snippet.<p>There was some simple logic to assemble all of the emitted code into a &quot;program&quot; that when eval()&#x27;d would generate an output object that had all of the components of the original string, but also decoded, enriched, normalized, and ready for downstream work.<p>In the rare case an &quot;atom&quot; was encountered the system didn&#x27;t have a &quot;rule&quot; for, it would throw an error and dump the string out to a file where he&#x27;d take a look at it, and in about 30 seconds slap in a new &quot;rule&quot; to handle the case forever more.<p>The entire codebase was maybe the rules and a couple hundred more lines of code -- maybe 1400-1500 lines. Written in a few weeks, processing tens of millions of strings per day, silent and forgotten in the bowels of some giant enterprise automation system.<p>It, running on a Pentium II or III of some kind, had replaced a rack of Sun Pizza boxes, and an old codebase setup by a consulting company that went down or garbled the processing of the strings at least once a week and required two full-time people to keep running. When the company had a downturn they laid off that team and in a fit of desperation the greybeard had come up with this little monster -- the beauty of which was under 5 minutes of maintenance per week to check logged errors and write a new rule if needed.<p><i>edit</i> ahh here&#x27;s the video <a href="https:&#x2F;&#x2F;youtu.be&#x2F;r-A78RgMhZU" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;r-A78RgMhZU</a>
secondcoming超过 2 年前
Iterating through the set bits in an integer in O(# of set bits) time.
评论 #33417068 未加载
embit超过 2 年前
This is bit dated but when in my university days I reas code of xterm
skellington超过 2 年前
10 PRINT &quot;HELLO HELLO&quot; 20 GOTO 10
qwerty456127超过 2 年前
Is this code supposed to work?
solomonb超过 2 年前
Comonadic User Interface design.
alatkins超过 2 年前
Scalaz.
GoblinSlayer超过 2 年前
Discrete cosine transform.
VirusNewbie超过 2 年前
profunctor optics.
JediLuke超过 2 年前
In the Elixir kernel, defmacro is defined by calling the defmacro macro about itself<p><a href="https:&#x2F;&#x2F;github.com&#x2F;elixir-lang&#x2F;elixir&#x2F;blob&#x2F;main&#x2F;lib&#x2F;elixir&#x2F;lib&#x2F;kernel.ex#L5090" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;elixir-lang&#x2F;elixir&#x2F;blob&#x2F;main&#x2F;lib&#x2F;elixir&#x2F;l...</a>
评论 #33417073 未加载