Git Product home page Git Product logo

qrmirror's Introduction

QR Mirror

Overview

This is a web server that can be used to encode a short message in a URL. It also serves a page at that URL, containing the message and a QR code pointing to that URL. Unlike with a URL shortener, the URL contains the full message in a compressed form so there is no need to store relations between messages and URLs server-side, and any URL that can be uncompressed to a message is automatically served. While this approach is appealing because it means no database or server state, the tradeoff is that messages must be short enough that their compressed URL form fits inside a QR code.

There is a live instance of this server at qr.samflam.com.

Compression algorithm

When compressing a message the server runs an ensemble of compression algorithms and chooses the one with the best compression ratio for the particular message. A 1-byte value is prepended to the compressed data indicating the algorithm that was used, which simplifies later decompression. Supported compression algorithms include:

  • trivial - No compression. Acts as fallback if everything else behaves poorly.
  • zlib - General lossless compressor.
  • smaz - Optimized for very short english text.
  • xz - Similar to zlib but has a slightly worse compression ratio in my testing. Disabled by default.
  • bwtc - Similar to zlib and has a slightly better compression ratio in some cases.

It's straightforward to add new algorithms to the ensemble as desired. The final URL is generated by encoding this compressed byte array in a URL-safe base64 string.

Running

This project requires node and yarn. In the cloned repo, first do

yarn install

to install dependencies.

Then do

yarn start

to run the server. You can also do

yarn dev

to run with nodemon, which automatically restarts the server whenever the source code changes.

By default the server generates QR codes for and runs on http://localhost:8000. You can change this with environment variables:

Variable Description
QRMIRROR_PORT The port the server should listen on. Defaults to 8000.
QRMIRROR_PREFIX The first part of the public URL including protocol and domain. Change this to match the URLs you want the QR codes to point to. Defaults to http://localhost:${QRMIRROR_PORT}.
QRMIRROR_ENSEMBLE_STATS If enabled, the default ensemble compressor console logs size statistics for all its members when processing a message. Enable by setting to a non-empty value. This is enabled automatically with yarn dev.

Questions and Troubleshooting

If you have questions or issues running the server please feel free to open an issue.

I do my testing and devlopment on a linux machine, so your mileage may vary on other platforms.

qrmirror's People

Contributors

aarongaut avatar

Watchers

 avatar

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.