Giter VIP home page Giter VIP logo

goodcode's People

Contributors

ainzzorl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goodcode's Issues

Setup a website

Simply storing markdown files is good, but hosting them on GitHub pages is better.

[NEW EXAMPLE] AWS CLI - Shorthand parser

General

  • Project name: AWS CLI
  • Example name: Parsing any CLI options that use a "shorthand" syntax
  • Project home page: https://github.com/aws/aws-cli/
  • Programming language(s): Python
  • Frameworks, libraries used: N/A

Description

The module parses "shorthand" CLI options. E.g. 'foo=bar,baz=qux' => {'foo': 'bar', 'baz': 'qux'}. It supports arrays, CSVs, hashes, escaping...

Links

shorthand.py

test_shorthand.py

What makes it interesting

  • The problem is rather generic; it can be interesting to anyone writing CLI programs.
  • Written very clearly.
  • Very comprehensive testing.
  • Exemplary support for backwards-compatibility: they are very careful to preserve certain quirks of a legacy implementation of the parser.

Related work

N/A

Other

There's some insights in pull request discussions, e.g. https://github.com/aws/aws-cli/pull/1444/files

[NEW EXAMPLE] ZooKeeper - Snapshot comparison

General

  • Project name: ZooKeeper
  • Example name: Snapshot comparison in ZooKeeper
  • Project home page: https://github.com/apache/zookeeper
  • Programming language(s): Java
  • Frameworks, libraries used: N/A

Description

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.

Links

What makes it interesting

  • Computing meaningful tree diffs is a rather common problem. It can be reusable.

Related work

No.

Other

Test coverage seems to be lacking.

In a way it's similar to an existing article - Computing diff between infrastructure templates in AWS CDK.

[NEW EXAMPLE] JDK - StringTokenizer

General

Description

String tokenizer in Java standard library.

Links

What makes it interesting

  • Part of Java standard library.
  • Since Java 1.0
  • Written by James Gosling

Related work

No

Other

Alternatively, we can look at StreamTokenizer: https://github.com/openjdk/jdk/blob/739769c8fc4b496f08a92225a12d07414537b6c0/src/java.base/share/classes/java/io/StreamTokenizer.java

[NEW EXAMPLE] Stockfish - Chess board representation

General

Description

Stockfish is one of the most powerful chess engines. The example is how Stockfish represents and manipulates chess positions.

Links

I couldn't find any unit tests for it; perhaps they rely on more elaborate tests like Fishtest.

What makes it interesting

  • CPU- and memory-efficient code.
  • Teaches standard patterns in any chess-related software.
  • Very non-trivial.
  • Teaches object-oriented representation.

Related work

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.

Other

Board representation in anther popular chess engine, Lc0: https://github.com/LeelaChessZero/lc0/blob/master/src/chess/board.h

[NEW EXAMPLE] Ionic Framework - Gestures

General

Description

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.

Links

https://github.com/ionic-team/ionic-framework/tree/main/core/src/utils/gesture

What makes it interesting

  • Many apps are written on Ionic and use gestures. It's interesting to see how it works.

Related work

Manual: https://ionicframework.com/docs/utilities/gestures

Other

Not sure how all of this is tested.

[NEW EXAMPLE] Protobuf - Tokenizer

General

Description

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.

Links

What makes it interesting

  • Protobuf is a very famous software.
  • Very well documented code.
  • Very well explained design decisions.

Related work

No.

Other

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.

[NEW EXAMPLE] Httpie - Progress reporting

General

  • Project name: Httpie
  • Example name: Httpie's download progress reporter
  • Project home page: https://github.com/httpie/httpie
  • Programming language(s): Python
  • Frameworks, libraries used: N/A

Description

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.

Links

https://github.com/httpie/httpie/blob/64c31d554a367abf876bd355f07dca6e41476c3f/httpie/downloads.py#L369-L480

What makes it interesting

  • A common feature for CLI apps. Can be reused.
  • Nice and simple implementation.

Related work

N/A

Other

  • It seems there's no automated testing for this.

[NEW EXAMPLE] Terraform - Algorithms on graphs

General

  • Project name: Terraform
  • Example name: Implementation of different graph algorithms, including Tarjan's strongly connected components algorithm.
  • Project home page: https://github.com/hashicorp/terraform
  • Programming language(s): Go
  • Frameworks, libraries used: N/A

Description

Terraform is a tool for building, changing, and versioning infrastructure.

Infrastructure resources form a graph. Terraform implements some graph algorithms to process them.

Links

What makes it interesting

It's interesting to see classical graph algorithms in the wild. Most of us only use them during whiteboard job interviews.

Other

N/A

[NEW EXAMPLE] ErrorProne - Test Helper

General

Description

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.

Links

What makes it interesting

  • Taken from a popular, mature project, maintained by a major tech company.
  • Example of testing things that are non-trivial to test.
  • DSL-like API.
  • Quite common pattern among any tools that do code analysis - see below.

Other

Many related products - linters, bug checkers, etc. - implement very similar patterns.

E.g. SonarQube's CheckVerifier, Rubocop's ExpectOffence.

[NEW EXAMPLE] Buck - ArtifactCache decorators

General

Description

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.

Links

What makes it interesting

  • Very instructive application of a classical OOP pattern.

Related work

No

Other

No

[NEW EXAMPLE] Jest - Diff

General

Description

"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",
  ]

Links

https://github.com/facebook/jest/tree/master/packages/jest-diff

What makes it interesting

  • Highly reusable.
  • Interesting functionality.
  • Standalone, requires no context.

Related work

No

Other

No.

[NEW EXAMPLE] Puppet - HTTP Connection Pool

General

Description

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.

Links

What makes it interesting

  • Idiomatic Ruby.
  • Very common problem, very reusable.
  • Simple, easy to understand.

Related work

No

Other

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

[NEW EXAMPLE] Ionic Framework - Gestures

General

Description

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.

Links

https://github.com/ionic-team/ionic-framework/tree/main/core/src/utils/gesture

Not sure if there are tests for this.

What makes it interesting

  • Handling gestures is common in GUIs.
  • Very instructive API.

Related work

Guide: https://ionicframework.com/docs/utilities/gestures

Other

N/A

[NEW EXAMPLE] Lucene - Rate limiting

General

  • Project name: Apache Lucene
  • Example name: Lucene's rate limiter for IO.
  • Project home page: https://github.com/apache/lucene
  • Programming language(s): Java
  • Frameworks, libraries used: N/A

Description

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.

Links

What makes it interesting

  • Somewhat standard problem, can be reused in some form by other projects.

Related work

N/A

Other

N/A

[NEW EXAMPLE] Spark - Cross-validation

General

  • Project name: Spark
  • Example name: Cross-validation
  • Project home page: https://github.com/apache/spark
  • Programming language(s): Scala
  • Frameworks, libraries used: N/A

Description

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.

Links

CrossValidator.scala

What makes it interesting

  • Machine learning workloads use cross-validation very often, but it's almost always delegated to different libraries. It's interesting to see how it's implemented in one of the most popular libraries.
  • Spark is known for its performance and scalability.

Related work

N/A

Other

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.

[NEW EXAMPLE] Homebrew - Download Strategy

General

  • Project name: Homebrew
  • Example name: Downloading software from a variety of sources in Homebrew
  • Project home page: https://github.com/Homebrew/brew
  • Programming language(s): Ruby
  • Frameworks, libraries used: Sorbet, rspec

Description

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.

Links

What makes it interesting

  • Taken from a very popular project.
  • The problem seems rather generic, the approach could be reused somewhere.
  • Complex, non-trivial implementation is hidden behind a simple interface.
  • Involves common OO design patterns: Strategy, Template Method.
  • Understandable without deep knowledge of Homebrew.

Other

N/A

[NEW EXAMPLE] Chaos Monkey - Database access layer

General

  • Project name: Chaos Monkey
  • Example name: Chaos Monkey's Database access layer
  • Project home page: e.g. https://github.com/foo/bar
  • Programming language(s): Go
  • Frameworks, libraries used: MySQL

Description

Chaos Monkey's MySQL-backed store for schedules and terminations. Provides application-level API for persistence.

Links

What makes it interesting

  • The need to implement persistence is very common. It's nice to see how they do it at Netflix.
  • It's quite short, while non-trivial.
  • Well-documented.

Other

The code is a bit dated (last updated in 2016), but still rather instructive.

[NEW EXAMPLE] ZooKeeper - Client connection

General

  • Project name: ZooKeeper
  • Example name: Managing the socket i/o for the client in ZooKeeper.
  • Project home page: https://github.com/apache/zookeeper
  • Programming language(s): Java
  • Frameworks, libraries used: N/A

Description

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.

ZooKeeper has a smart client that:

  • maintains a list of available servers to connect to and "transparently" switches servers it is connected to as needed.
  • does smart error handling.
  • generates heart beats.
  • has an event loop.

Links

https://github.com/apache/zookeeper/blob/c583a6e79654359b5daad5093d1730e370d3b75b/zookeeper-server/src/main/java/org/apache/zookeeper/ClientCnxn.java

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

What makes it interesting

  • Smart client.
  • Non-trivial error handling.
  • Event loop.

Related work

No.

Other

N/A

[NEW EXAMPLE] Firecracker - Rate limiting

General

Description

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.

Links

https://github.com/firecracker-microvm/firecracker/blob/2f92f4a2d189c504aa358928b3ad490aafa61cff/src/rate_limiter/src/lib.rs

What makes it interesting

  • Rate limiting is a common problem.
  • Classical rate limiting implementation in software known to be high-performant.

Related work

No

Other

N/A

[NEW EXAMPLE] Puppet - Graph Algorithms

General

Description

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.

Links

What makes it interesting

  • Generic topic.
  • Should be reusable.
  • Well-documented.

Related work

No

Other

We already have an article about graph algorithms in Terraform - it would be nice to compare them.

[NEW EXAMPLE] Puppet - Connection Pool

General

Description

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.

Links

What makes it interesting

  • Generic, reusable.
  • Short and simple.
  • Idiomatic Ruby.

Related work

No

Other

Again, it's not the most interesting part of Puppet by a long shot, but it's understandable in isolation.

[NEW EXAMPLE] Lc0 - Chess Board Representation

General

Description

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.

Links

What makes it interesting

  • Uses standard patterns in any chess-related software.
  • Very non-trivial.
  • Very object-oriented.

Related work

Other

N/A

Add an FAQ

There should be a page answering most common questions.

[NEW EXAMPLE] Bat - Decorations

General

  • Project name: Bat
  • Example name: Decorations
  • Project home page: https://github.com/sharkdp/bat/
  • Programming language(s): Rust
  • Frameworks, libraries used: N/A

Description

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.

Links

Add links to the code. Include tests.

decorations.rs

There are no unit tests; integ tests: https://github.com/sharkdp/bat/blob/master/tests/integration_tests.rs.

What makes it interesting

  • Decorator pattern.
  • Clever testing.

Related work

N/A

Other

N/A

Jest - Test Sequencing

General

Description

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.

Links

Implementation

Test

What makes it interesting

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.

Related work

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.

Other

N/A

[NEW EXAMPLE] ZooKeeper - Trie

General

  • Project name: ZooKeeper
  • Example name: Trie implementation
  • Project home page: https://github.com/apache/zookeeper
  • Programming language(s): Java
  • Frameworks, libraries used: N/A

Description

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.

Links

https://github.com/apache/zookeeper/blob/e642a325b91ab829aefa47708c7b4b45811d2d23/zookeeper-server/src/main/java/org/apache/zookeeper/common/PathTrie.java

https://github.com/apache/zookeeper/blob/e642a325b91ab829aefa47708c7b4b45811d2d23/zookeeper-server/src/test/java/org/apache/zookeeper/common/PathTrieTest.java

What makes it interesting

  • Trie is a popular data structure, very frequently used in job interview problems :-)

Related work

N/A

Other

N/A

[NEW EXAMPLE] AWS CDK - Diff computation

General

  • Project name: AWS CDK
  • Example name: Compute diff between infrastructure templates
  • Project home page: https://github.com/aws/aws-cdk
  • Programming language(s): Typescript
  • Frameworks, libraries used: AWS, CloudFormation

Description

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.

Links

What makes it interesting

  • Computing meaningful diffs is a rather common problem.
  • Testing is exemplary.

Other

N/A

[NEW EXAMPLE] Ruby - Did you mean?

General

Description

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.

Links

Add links to the code. Include tests.

https://github.com/ruby/ruby/blob/master/lib/did_you_mean

What makes it interesting

  • Part of Ruby standard library.
  • Classical algorithm.
  • Very reusable.

Related work

No

Other

N/A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.