GithubHelp home page GithubHelp logo

luke-clifton / memorable-bits Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 95 KB

Render difficult to remember data, hashes and other things, to memorable strings.

License: BSD 2-Clause "Simplified" License

Haskell 99.11% Nix 0.89%

memorable-bits's Introduction

Memorable Bits hackage-badge travis-badge

A library for generating human-readable (and memorable) phrases from data. What sets this library apart from most others, is that it is highly customisable. The phrases that are generated are described at the type level, which can ensure, at compile time, that the phrase generated has enough bits to cover the data being converted.

The library comes with some pre-baked themes:

λ> :set -XOverloadedStrings
λ> import Data.Word
λ> import Crypto.Hash
λ> import Network.IP.Addr
λ> import Data.Memorable
λ>
λ> import Data.Memorable.Theme.Fantasy
λ> renderMemorable (padHex rpgWeapons) (12345 :: Word32)
"ghostly-trident-of-zombie-tormenting-039"
λ>
λ> import Data.Memorable.Theme.Food
λ> renderMemorable (padHex desserts) $ ip4FromOctets 127 0 0 1
"bland-strawberry-pancakes-000001"
λ>
λ> import Data.Memorable.Theme.Words
λ> let h = hash ("an example" :: ByteString) :: Digest MD5
λ> renderMemorable (padHex eightEqualWordsFor64Bits) a
"than-high-bonk-gash-into-keen-rush-swat-7efea731142d8f84"
λ>
λ> import Data.Memorable.Theme.Science
λ> renderMemorable (padDec chemBabble) (0xdeadbeef :: Word32)
"tri-propyl-4-benzene-oxide-114415"

But you can easily create your own and mix and match:

λ> :set -XDataKinds -XTypeOperators
λ> import Data.Memorable.Theme.Fantasy as Fantasy
λ> import Data.Memorable.Theme.Food as Food
λ> type MyPattern = NumberWithOffset Dec 1 3 :- Food.DessertFlavours :- Fantasy.Monster
λ> let myPattern = Proxy :: Proxy MyPattern
λ> renderMemorable (padHex myPatter) (0x4321 :: Word16)
"3-blueberry-sphinx-01"

You can check how many bits are covered by your pattern:

λ> :kind! Depth MyPattern
Depth MyPattern :: Nat
= 7

Or using the getDepth function:

λ> getDepth words12
12
λ> getDepth (words12 .- words12)
24

If you are happy to have some non-human-readable parts in your pattern, use the convenience functions padHex and padDec:

λ> :set -XOverloadedStrings
λ> import Data.ByteString
λ> import Crypto.Hash
λ> let myPattern = padHex (four flw10)
λ> renderMemorable myPattern (hash ("anExample" :: ByteString) :: Digest MD5)
"bark-most-gush-tuft-1b7155ab0dce3ecb4195fc"

memorable-bits's People

Contributors

luke-clifton avatar

Stargazers

Attila Gulyas avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

toraritte

memorable-bits's Issues

Deserialise phrases

It would be nice to check that the patterns are unambiguous. My attempts so far at this have causes massive compile time blowouts.

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.