
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@strong-roots-capital/cartesian-product-generator
Advanced tools
ES2015 generator (iterable iterator) for cartesian product. Put combinatorial explosion back in the kennel.
An ES2015 generator of the Cartesian product—you know, where you have several arrays and want to iterate over all combinations, but might not want to store them all in memory at the same time, which is what many existing libraries, e.g., lodash.product
, do.
Another iterable cartesian product library called product-iterable
is available, but I wanted this library to be dead simple: it uses a single dependency, ind2sub
, to handle converting linear indexes into subscripts into a list of arrays, then indexes over all combinations, yield
ing repeatedly. Furthermore, since it's a TypeScript project, this library is easy to use with TypeScript or other ES6+ environments.
Node.js In your Node project's directory, execute the following in the command line:
$ npm install --save cartesian-product-generator
Then you can load it into Node via
const product = require('cartesian-product-generator').product;
const iterator = product(['r', 'g', 'b'], ['early', 'late'], ['high', 'low']);
console.log([...iterator])
// [ [ 'r', 'early', 'high' ],
// [ 'g', 'early', 'high' ],
// [ 'b', 'early', 'high' ],
// [ 'r', 'late', 'high' ],
// [ 'g', 'late', 'high' ],
// [ 'b', 'late', 'high' ],
// [ 'r', 'early', 'low' ],
// [ 'g', 'early', 'low' ],
// [ 'b', 'early', 'low' ],
// [ 'r', 'late', 'low' ],
// [ 'g', 'late', 'low' ],
// [ 'b', 'late', 'low' ] ]
Note how product
returns an iterator/iterable. You can use this in Array.from
, new Set()
, array slicing like above, and anywhere else in ES2015 that takes an iterable or iterator, including for...of
, which allows you to iterate over each combination without ever storing all of them in memory:
for (let combo of product(['r', 'g', 'b'], ['early', 'late'], ['high', 'low'])) {
console.log('Look ma! Easy on the memory: ' + combo.join('+'));
}
For TypeScript, import it as
import {product} from 'cartesian-product-generator';
If you see errors about type 'IterableIterator'
, you have to add "es2015"
to the "lib"
key in your tsconfig.json
. If you then encounter errors complaining that Type IterableIterator is not an array or string type
, you need to enable "downlevelIteration": true
in your tsconfig.json
, which, according to the documentation, "Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'". (Hopefully this second error message is improved by the time you read this: see issue.)
Browser Load cartesian-product-generator-browser.js
into your HTML via <script>
, then access it through
const iterator = cartesianProductGenerator.product(['r', 'g', 'b'], ['early', 'late'], ['high', 'low']);
console.log([...iterator])
FAQs
ES2015 generator (iterable iterator) for cartesian product. Put combinatorial explosion back in the kennel.
We found that @strong-roots-capital/cartesian-product-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.