Code Explainers

Code explainers tagged #encoding

python
from pathlib import Path
 
import chardet
 

Reading text files of unknown encoding in Python

encoding byte-order-mark fallback
Intermediate 8 steps
php
<?php
 
function parseMultipartEmail(string $raw): array
{

Parsing multipart emails with mailparse

mime-parsing email encoding
Intermediate 9 steps
ruby
require "zlib"
require "stringio"
require "base64"
 

Compress-and-encode payloads in Ruby

compression encoding io-streams
Intermediate 8 steps
go
package token
 
import (
	"crypto/rand"

Generating secure random tokens in Go

cryptography randomness encoding
Intermediate 5 steps
javascript
function parseJwtPayload(token) {
  const parts = token.split('.');
  if (parts.length !== 3) {
    throw new Error('Invalid JWT: expected 3 segments');

Decoding a JWT payload in JavaScript

jwt base64url encoding
Intermediate 6 steps