Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active March 14, 2024 21:20
Show Gist options
  • Select an option

  • Save CMCDragonkai/0c427174dc8ba01f4eff to your computer and use it in GitHub Desktop.

Select an option

Save CMCDragonkai/0c427174dc8ba01f4eff to your computer and use it in GitHub Desktop.
CLI: Text Shortening (Text to ASCII Compression)

Text Shortening

Tools like gzip and xz compress bitstrings to bitstrings. We want something designed to do lossless compression on short to medium strings and produce printable ASCII or any kind of printable text. This would allow us to create our own URL shortening system.

We need to combine these 2:

Into one single command line tool.

Or at least both tools can be made into command line tools, and simple composition can allow us to have shortened text to text function.

http://www.chaos.org.uk/~eddy/project/ascii.html

For now we have:

> # needs about 40 words before we make any profit
> echo -n "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas efficitur, ante eu vehicula imperdiet, est sem maximus justo, non lacinia erat quam dictum nulla. Suspendisse feugiat sagittis lacinia. In tellus nulla, vulputate in convallis a, dapibus sit amet purus. Curabitur." | tee >(wc --chars) | gzip --stdout --best | base64 --wrap 0 | wc --chars
279
268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment