ainzzorl / goodcode Goto Github PK
View Code? Open in Web Editor NEWA curated collection of annotated code examples from prominent open-source projects
Home Page: https://codecatalog.org
License: Creative Commons Attribution 4.0 International
A curated collection of annotated code examples from prominent open-source projects
Home Page: https://codecatalog.org
License: Creative Commons Attribution 4.0 International
Firecracker - Rate Limiting [Rust] Status PUBLISHED Project Firecracker Project home page https://github.com/firecracker-microvm/firecracker Language Rust Tags #rate-limiting #token-bucket Table of contents
Homebrew - Downloading Software From a Variety of Sources [Ruby] Status PUBLISHED Project Homebrew Project home page https://github.com/Homebrew/brew Language Ruby Tags #strategy #template-method Table of contents
https://codecatalog.org/articles/homebrew-download-strategy/
There should be a page answering most common questions.
Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time. It's comprised of hundreds of mostly independent bug checkers.
They employ a clever test helper to streamline testing these checkers, in a DSL-like fashion.
Many related products - linters, bug checkers, etc. - implement very similar patterns.
E.g. SonarQube's CheckVerifier, Rubocop's ExpectOffence.
Error Prone - Testing Bug Checkers [Java] Status PUBLISHED Project Error Prone Project home page https://github.com/google/error-prone Language Java Tags #dsl #test-helper #builder Table of contents
Puppet, an automated administrative engine for your Linux, Unix, and Windows systems, performs administrative tasks (such as adding users, installing packages, and updating server configurations) based on a centralized specification.
Puppet implements a pool for reusing HTTP connections.
No
A library implementing similar functionality: https://github.com/mperham/connection_pool/blob/master/lib/connection_pool.rb
Similar functionality in Rails: https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
ZooKeeper operates with znodes - data objects organized hierarchically as in file systems. In some cases it needs to find the longest stored prefix for a given path. For this, it uses the Trie data structure.
N/A
N/A
Homebrew needs to download and unpack the resource from the specified location, but how to do it depends on the exact URL. For instance, downloading a tarball is not the same as downloading repository content from Github. Some resources need to be unpacked, some don't.
Homebrew employs Strategy pattern to describe various ways to download a resource.
N/A
Stockfish - Chess Board Representation [C++] Status PUBLISHED Project Stockfish Project home page https://github.com/official-stockfish/Stockfish Language C++ Tags #chess #bitboard Table of contents
https://codecatalog.org/articles/stockfish-board-representation/
ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
ZooKeeper operates with znodes - data objects organized hierarchically as in file systems. It periodically takes snapshots of the data. To compare the snapshots, it implements SnapshotComparer
.
No.
Test coverage seems to be lacking.
In a way it's similar to an existing article - Computing diff between infrastructure templates in AWS CDK.
HTTPie - Reporting Download Progress [Python] Status PUBLISHED Project HTTPie Project home page https://github.com/httpie/httpie Language Python Tags #cli #status-reporting #spinner Table of contents
Bat - Text Decoration [Rust] Status PUBLISHED Project Bat Project home page https://github.com/sharkdp/bat Language Rust Tags #cli #decorator Table of contents
HTTPie (pronounced aitch-tee-tee-pie) is a command-line HTTP client. Its goal is to make CLI interaction with web services as human-friendly as possible.
HTTPie features a download mode in which it acts similarly to wget. When enabled using the --download, -d flag, response headers are printed to the terminal (stderr), and a progress bar is shown while the response body is being saved to a file.
Progress bar is a very common thing among CLI apps. Let's see how Httpie does it.
N/A
Bat is an alternative for the cat
command.
The displayed text is "decorated" with line numbers, borders and line change annotations that can be turned on or off. decorations.rs is where they are implemented.
Add links to the code. Include tests.
There are no unit tests; integ tests: https://github.com/sharkdp/bat/blob/master/tests/integration_tests.rs.
N/A
N/A
New Article: Rate Limiting in Firecracker 05 August 2021
https://codecatalog.org/2021/08/05/firecracker-rate-limiting.html
Terraform - Graph Algorithms [Go] Status PUBLISHED Project Terraform Project home page https://github.com/hashicorp/terraform Language Go Tags #graph #algorithm Table of contents
https://codecatalog.org/articles/terraform-graph-algorithms/
Terraform is a tool for building, changing, and versioning infrastructure.
Infrastructure resources form a graph. Terraform implements some graph algorithms to process them.
It's interesting to see classical graph algorithms in the wild. Most of us only use them during whiteboard job interviews.
N/A
Jest - Test Sequencer [TypeScript] Status PUBLISHED Project Jest Project home page https://github.com/facebook/jest Language TypeScript Tags #test-framework Table of contents
ZooKeeper - Trie [Java] Status PUBLISHED Project Apache ZooKeeper Project home page https://github.com/apache/zookeeper Language Java Tags #trie #data-structure #algorithm Table of contents
Chaos Monkey's MySQL-backed store for schedules and terminations. Provides application-level API for persistence.
The code is a bit dated (last updated in 2016), but still rather instructive.
"Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
When the actual output doesn't match the expectation, Jest "displays differences clearly so people can review changes confidently."
E.g. (borrowed from README.md):
const a = ['delete', 'common', 'changed from'];
const b = ['common', 'changed to', 'insert'];
const difference = diff(a, b);
- Expected
+ Received
Array [
- "delete",
"common",
- "changed from",
+ "changed to",
+ "insert",
]
https://github.com/facebook/jest/tree/master/packages/jest-diff
No
No.
Ionic Framework is a powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
Ionic Gestures is a utility that allows developers to build custom gestures and interactions for their application in a platform agnostic manner.
https://github.com/ionic-team/ionic-framework/tree/main/core/src/utils/gesture
Manual: https://ionicframework.com/docs/utilities/gestures
Not sure how all of this is tested.
Stockfish is one of the most powerful chess engines. The example is how Stockfish represents and manipulates chess positions.
I couldn't find any unit tests for it; perhaps they rely on more elaborate tests like Fishtest.
I'm not aware to anything discussing the actual code, but there are numerous articles about chess board representations, in general about Stockfish in particular.
Board representation in anther popular chess engine, Lc0: https://github.com/LeelaChessZero/lc0/blob/master/src/chess/board.h
Puppet, an automated administrative engine for your Linux, Unix, and Windows systems, performs administrative tasks (such as adding users, installing packages, and updating server configurations) based on a centralized specification.
Puppet uses graphs to represent its catalog. They implement a number of graph algorithms, e.g. Tarjan's algorithm.
No
We already have an article about graph algorithms in Terraform - it would be nice to compare them.
Firecracker is an open source virtualization technology that is purpose-built for creating and managing secure, multi-tenant container and function-based services that provide serverless operational models. Firecracker runs workloads in lightweight virtual machines, called microVMs, which combine the security and isolation properties provided by hardware virtualization technology with the speed and flexibility of containers.
Firecracker needs to rate limit IO operations. The implementation is based on the Token Bucket algorithm.
No
N/A
Protocol Buffers (a.k.a., protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. You can find protobuf's documentation on the Google Developers site.
Parsing protobufs depends on this custom stream tokenizer.
Why it needs a custom tokenizer and why it is the way it is is described in detail in this comment.
No.
The tokenizer is not the most interesting part of Protobuf, but the rest of the code seems either overwhelmingly complex, or impossible to reason about in isolation, usually both.
Puppet, an automated administrative engine for your Linux, Unix, and Windows systems, performs administrative tasks (such as adding users, installing packages, and updating server configurations) based on a centralized specification.
Puppet client implements a connection pool to reuse server connections.
Connections are borrowed from the pool, yielded to the caller, and released back into the pool. If a connection is expired, it will be closed either when a connection to that site is requested, or when the pool is closed. The pool can store multiple connections to the same site, and will be reused in MRU order.
No
Again, it's not the most interesting part of Puppet by a long shot, but it's understandable in isolation.
Ionic Framework is an open source mobile UI toolkit for building cross-platform native and web app experiences.
Ionic Gestures is a utility that allows developers to build custom gestures and interactions for their application in a platform agnostic manner.
https://github.com/ionic-team/ionic-framework/tree/main/core/src/utils/gesture
Not sure if there are tests for this.
Guide: https://ionicframework.com/docs/utilities/gestures
N/A
Test Article [TestLanguage] Status DRAFT Project Test Project home page https://github.com/example/example Language Test Tags #test-tag-1
String tokenizer in Java standard library.
No
Alternatively, we can look at StreamTokenizer: https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/java.base/share/classes/java/io/StreamTokenizer.java
Chaos Monkey - MySQL-backed Store for Schedules and Terminations [Go] Status PUBLISHED Project Chaos Monkey Project home page https://github.com/Netflix/chaosmonkey Language Go Tags #data-access #sql #dao #chaos-engineering Table of contents
Welcome to Code Catalog! 16 July 2021
AWS CDK is an infrastructure-as-code tool. When updating infrastructure, it needs to compute semantic diff between infrastructure templates. The algorithm is rather straightforward.
N/A
Buck - Artifact Cache Decorators [Java] Status PUBLISHED Project Buck Project home page https://github.com/facebook/buck Language Java Tags #decorator Table of contents
https://codecatalog.org/articles/buck-artifact-cache-decorators/
Buck is a fast build system that encourages the creation of small, reusable modules over a variety of platforms and languages.
Buck caches build artifacts. Decorators can be used to add bells and whistles to the default cache implementation.
No
No
did_you_mean is a typo-detecting gem that ships with Ruby since Ruby 2.3.
We can just focus on the spell-checker. It's based on Levinstein distances.
Add links to the code. Include tests.
https://github.com/ruby/ruby/blob/master/lib/did_you_mean
No
N/A
Test Article [TestLanguage] Status DRAFT Project Test Project home page https://github.com/example/example Language Test Tags #test-tag-1
Puppet - HTTP Connection Pool [Ruby] Status PUBLISHED Project Puppet Project home page https://github.com/puppetlabs/puppet Language Ruby Tags #connection-pool Table of contents
Jest is a "delightful JavaScript Testing Framework with a focus on simplicity".
The order in which it runs tests is not arbitrary because "it has a great impact on the user-perceived responsiveness and speed of the test run." First it runs tests that failed in the previous run, then tests that are slow or expected to be slow.
The code itself is quite simple and not that interesting, but what's instructive is this observation that you can improve user experience by prioritizing tests.
Sorting tests in JUnit: https://github.com/junit-team/junit4/blob/9ad61c6bf757be8d8968fd5977ab3ae15b0c5aba/src/main/java/org/junit/runner/manipulation/Sorter.java, https://github.com/junit-team/junit4/blob/9ad61c6bf757be8d8968fd5977ab3ae15b0c5aba/src/main/java/org/junit/runner/manipulation/Ordering.java. As far as I can see, it runs them alphabetically.
N/A
Spark is a unified analytics engine for large-scale data processing. It has support for running machine learning workloads with MLlib. MLlib supports cross-validation: a standard procedure used to evaluate machine learning models on a limited data sample.
N/A
There are so many things to learn from Spark, but it's so big it's hard to get started with the code base. This example, however, seems rather independent from the rest of the code.
Protocol Buffers - Stream Tokenizer [C++] Status PUBLISHED Project Protocol Buffers Project home page https://github.com/protocolbuffers/protobuf/ Language C++ Tags #tokenizer #parsing Table of contents
Discussion is crucial for a project like this. The most natural choice for this is https://utteranc.es/
The most obvious example is http://aosabook.org
Lucene is a high-performance, full featured text search engine library written in Java. It powers many other projects, including Elasticsearch and Apache Solr.
They have a mechanism to rate limit their IO.
N/A
N/A
Simply storing markdown files is good, but hosting them on GitHub pages is better.
AWS CLI - Shorthand Parser [Python] Status PUBLISHED Project AWS CLI Project home page https://github.com/aws/aws-cli/ Language Python Tags #cli #parsing #visitor Table of contents
Lc0 is a UCI-compliant chess engine designed to play chess via neural network, specifically those of the LeelaChessZero project.
It has a class to represent chess board position.
We already have an article describing chess board representation in Stockfish. Lc0's implementation seems quite a bit more readable and better tested in comparison.
N/A
The module parses "shorthand" CLI options. E.g. 'foo=bar,baz=qux'
=> {'foo': 'bar', 'baz': 'qux'}
. It supports arrays, CSVs, hashes, escaping...
N/A
There's some insights in pull request discussions, e.g. https://github.com/aws/aws-cli/pull/1444/files
AWS CDK - Computing Diff Between Infrastructure Templates [TypeScript] Status PUBLISHED Project AWS CDK Project home page https://github.com/aws/aws-cdk Language TypeScript Tags #aws #cloud #diff #infrastructure-as-code Table of contents
ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.
ZooKeeper has a smart client that:
Tests: https://github.com/apache/zookeeper/blob/c583a6e79654359b5daad5093d1730e370d3b75b/zookeeper-server/src/test/java/org/apache/zookeeper/ClientRequestTimeoutTest.java https://github.com/apache/zookeeper/blob/c583a6e79654359b5daad5093d1730e370d3b75b/zookeeper-server/src/test/java/org/apache/zookeeper/ClientReconnectTest.java https://github.com/apache/zookeeper/blob/c583a6e79654359b5daad5093d1730e370d3b75b/zookeeper-server/src/test/java/org/apache/zookeeper/ClientCnxnSocketFragilityTest.java
No.
N/A
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.