Code Explainers

Code explainers tagged #normalization

php
<?php
 
class NameParser
{

Parsing a full name into components in PHP

string-parsing arrays normalization
Intermediate 8 steps
python
from typing import Iterable
 
 
def jaccard_similarity(tags_a: Iterable[str], tags_b: Iterable[str]) -> float:

Ranking tag sets by Jaccard similarity

set-operations similarity-metric generators
Intermediate 5 steps
ruby
class WeightedMovingAverageForecaster
  DEFAULT_WINDOW = 5
 
  def initialize(window: DEFAULT_WINDOW, weights: nil)

A weighted moving average forecaster in Ruby

forecasting weighted-average normalization
Intermediate 8 steps
javascript
class ShortcutManager {
  constructor(target = window) {
    this.target = target;
    this.bindings = new Map();

Building a keyboard shortcut manager in JavaScript

event-handling normalization map
Intermediate 9 steps
java
public final class UserAgentParser {
 
    private static final Pattern OS_PATTERN = Pattern.compile(
            "(Windows NT [0-9.]+|Mac OS X [0-9_]+|Android [0-9.]+|iPhone OS [0-9_]+|Linux)");

Parsing user-agent strings with regex in Java

regex parsing pattern-matching
Intermediate 9 steps
ruby
class MailingListDeduplicator
  GMAIL_DOMAINS = %w[gmail.com googlemail.com].freeze
 
  def initialize(subscribers)

Deduplicating a mailing list by canonical email

deduplication normalization service object
Intermediate 8 steps
javascript
function parseHexColor(hex) {
  const cleaned = hex.trim().replace(/^#/, '');
 
  const expand = (short) =>

Parsing hex colors into RGBA channels

parsing bitwise regex
Intermediate 7 steps
python
import pandas as pd
import numpy as np
 
 

Cleaning a customer DataFrame with pandas

data-cleaning regex normalization
Intermediate 9 steps
java
public final class EmailNormalizer {
 
    private static final Pattern EMAIL_PATTERN = Pattern.compile(
        "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"

Normalizing email addresses in Java

validation regex normalization
Intermediate 8 steps
python
from collections.abc import MutableMapping
 
 
class CaseInsensitiveDict(MutableMapping):

Building a case-insensitive dict in Python

data structures abstract base classes dunder methods
Intermediate 8 steps
typescript
interface ParsedName {
  first: string;
  middle: string;
  last: string;

Parsing human names into structured parts

parsing string-manipulation normalization
Intermediate 9 steps
typescript
import { parsePhoneNumberFromString, CountryCode } from 'libphonenumber-js';
 
export interface NormalizedPhone {
  e164: string;

Normalizing phone numbers to E.164 in TypeScript

validation normalization error-handling
Intermediate 7 steps
typescript
import slugify from "slugify";
 
interface SlugRepository {
  exists(slug: string): Promise<boolean>;

Generating unique URL slugs from titles

slugs normalization uniqueness
Intermediate 6 steps
rust
pub fn collapse_whitespace(input: &str) -> String {
    let mut result = String::with_capacity(input.len());
    let mut in_whitespace = false;
 

Collapsing runs of whitespace in Rust

string-processing state-machine iteration
Beginner 5 steps
typescript
type Handler = (event: KeyboardEvent) => void;
 
interface Binding {
  combo: string;

Building a keyboard shortcut manager in TypeScript

event-handling normalization closures
Intermediate 7 steps
go
package email
 
import (
	"errors"

Normalizing and deduping email addresses in Go

validation normalization deduplication
Intermediate 8 steps
php
<?php
 
namespace App\Support;
 

Normalizing phone numbers to E.164 in PHP

input-validation normalization regular-expressions
Intermediate 8 steps
javascript
function splitFullName(fullName) {
  const cleaned = (fullName || '').trim().replace(/\s+/g, ' ');
 
  if (!cleaned) {

Parsing full names into first and last

string-parsing regex edge-cases
Intermediate 8 steps