Giter VIP home page Giter VIP logo

dicephrase's People

Contributors

chrstntdd avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

dicephrase's Issues

Add diy route

Add an extra /diy route to let folks lookup words on the wordlist directly with a datalist for cases when they want to roll their own dice.

Generalize and reuse ReScript parsers in CLI

Description:
No validation exists for the CLI. Any args possible -- allows impossible states like a negative count and handles some characters strangely

Acceptance Criteria:

  • dicephrase cli package validates the arguments

Concept:

  • More ReScript utils to operate on a generic arguments object, not just the URLSearchParams.

Improve perf of `make_wl_keys`

Given the current code:

let make_wl_keys = count => {
  open Js.TypedArray2
  let chunk_size = 5
  let key_count = count * chunk_size
  let raw_bits = Uint32Array.fromLength(key_count)

  // Fill (mutates the raw_bits in place)
  getRandomValues(raw_bits)

  let min = 1
  let max = 6

  let rec bits_to_keys = (bits, acc, idx) => {
    if mod(idx, chunk_size) == 0 {
      acc
      ->Js.Array2.push(
        bits
        ->Uint32Array.subarray(~start=idx, ~end_=idx + chunk_size)
        ->Uint32Array.map((. x) => {
          let roll = mod(x, max) + min
          roll
        })
        ->Uint32Array.joinWith(""),
      )
      ->ignore
    }

    if idx + 1 === key_count {
      acc
    } else {
      bits_to_keys(bits, acc, idx + 1)
    }
  }

  bits_to_keys(raw_bits, [], 0)
}

We have excessive iterations in the recursive bits_to_keys function. As we recurse, we only increment the index. This causes the need for the if mod(idx, chunk_size) == 0 check at the beginning and thus we call more often, though the if check avoids doing the more expensive operations.

To explain, this is what the current implementation would look like if we log the idx each loop of bits_to_keys when the count is 6 :

0 // useful
1
2
3
4
5 // useful
6
7
8
9
10 // useful
11
12
13
14
15 // useful
16
17
18
19
20 // useful
21
22
23
24
25 // useful
26
27
28
29

As mentioned, the if check is ensuring we can skip "expensive" work for the non-useful iterations , but theres a better way!

We can increase the idx by the chunk size instead to avoid extra iterations and avoid the if check to produce this output when logging idx given the same input as above:

0
5
10
15
20
25

Acceptance Criteria:

  • Tests still pass
  • Less iterations observed when logging as described

More settings

Some password requirements suggest more variations that currently are not supported such as:

  • An uppercase letter
  • A number

Personally, I'll add the missing requirements myself, but it would be nice to have this handled natively.

Will require reconsideration of how the controls are laid out since the new fields might crowd the screen on smaller screen devices.

Remove worker experiment

The apps/main-worker workspace can be removed now โ€” it's dead code.

At this time, the App is entirely self contained in the browser. I once thought it would be nice to do SSR with Cloudflare workers for a progressive enhancement, but decided against it for simplicity & privacy.

This could change in the future, but for now it's best to be removed.

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.