Restful #01
(&rest rest)
Org table of HTTP return codes
Did you know you have all HTTP return codes and their descriptions in your Emacs?
It's in the url-http package. You can just look into the variable url-http-codes to see a list of lists.
Below I use xht to convert it to an Org table.
(require 'xht) (require 'url-http) ;; Compose a string (h-let-it `((ID Name Text) ,@url-http-codes) (format "%s: %s" 100 .100.Text)) => "100: Continue with request" ;; See them all (->> url-http-codes (cons '(ID Name Text)) h<-lol h->orgtbl) => "\ | ID | Name | Text | |-----+---------------------------------+-------------------------------------| | 100 | continue | Continue with request | | 101 | switching-protocols | Switching protocols | | 102 | processing | Processing (Added by DAV) | | 200 | OK | OK | | 201 | created | Created | | 202 | accepted | Accepted | | 203 | non-authoritative | Non-authoritative information | | 204 | no-content | No content | | 205 | reset-content | Reset content | | 206 | partial-content | Partial content | | 207 | multi-status | Multi-status (Added by DAV) | | 300 | multiple-choices | Multiple choices | | 301 | moved-permanently | Moved permanently | | 302 | found | Found | | 303 | see-other | See other | | 304 | not-modified | Not modified | | 305 | use-proxy | Use proxy | | 307 | temporary-redirect | Temporary redirect | | 400 | bad-request | Bad Request | | 401 | unauthorized | Unauthorized | | 402 | payment-required | Payment required | | 403 | forbidden | Forbidden | | 404 | not-found | Not found | | 405 | method-not-allowed | Method not allowed | | 406 | not-acceptable | Not acceptable | | 407 | proxy-authentication-required | Proxy authentication required | | 408 | request-timeout | Request time-out | | 409 | conflict | Conflict | | 410 | gone | Gone | | 411 | length-required | Length required | | 412 | precondition-failed | Precondition failed | | 413 | request-entity-too-large | Request entity too large | | 414 | request-uri-too-large | Request-URI too large | | 415 | unsupported-media-type | Unsupported media type | | 416 | requested-range-not-satisfiable | Requested range not satisfiable | | 417 | expectation-failed | Expectation failed | | 422 | unprocessable-entity | Unprocessable Entity (Added by DAV) | | 423 | locked | Locked | | 424 | failed-Dependency | Failed Dependency | | 451 | unavailable-for-legal-reasons | Unavailable for legal reasons | | 500 | internal-server-error | Internal server error | | 501 | not-implemented | Not implemented | | 502 | bad-gateway | Bad gateway | | 503 | service-unavailable | Service unavailable | | 504 | gateway-timeout | Gateway time-out | | 505 | http-version-not-supported | HTTP version not supported | | 507 | insufficient-storage | Insufficient storage |"
The exceptional capitalization in the names of codes 200 and 424 seems out of place. But I suppose that "fixing" that for the sake of consistency in a (defconst…) of a package that's been around since 1999 is not a good idea...
Faster, more elegant Bash FizzBuzz
I thought Bash FizzBuzz could get neither faster nor more elegant than this:
fizzbuzz() (seq "$1" | sed '3~3 s/.*/Fizz/ 5~5 s/.*/Buzz/ 15~15 s/.*/FizzBuzz/' | xargs)
Seems I was wrong. There's a new challenger:
fizzbuzz() (seq "$1" | sed '15~15 c FizzBuzz 5~5 c Buzz 3~3 c Fizz' | xargs)
Stripped of all the s/.*//, the latter is slightly shorter and more elegant.
It's also ~20% faster than the former, which was itself almost twice as fast as the next.
Have we reached the limit?
You can test it by pasting the function definition and then this in your terminal:
fizzbuzz 300 | xargs -n15 | column -ts$' ' | grep -E '..zz|$'
Then have a look at how fast it does one million:
time fizzbuzz 1000000 >/dev/null
Visualizing all territory flags at once
How could we create a 26×26 matrix of all possible two-letter territory emoji flag combinations — without using lookups?
I'm glad you asked, because I've just added, to the end of a previous post, my short Emacs Lisp and Bash solutions for that.
And by "short" I mean: literally six half-lines of code in either language — a simple pair of "dependent" nested loops.
📆 2025-11-26