Skip to content

Instantly share code, notes, and snippets.

@paulroth3d
paulroth3d / simpleBoxMuller.js
Created August 20, 2023 02:51
simple box muller
// https://stackoverflow.com/questions/25582882/javascript-math-random-normal-distribution-gaussian-bell-curve
module.exports.boxMueller = function boxMueller(min = 0, max = 1) {
const u = 1 - Math.random();
const v = Math.random();
let num = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
// translate from (-10,10) to (0,1) inclusive
num = num / 10.0 + 0.5; // Translate to 0 -> 1
num = Math.max(0, num);
num = Math.min(1, num);
@paulroth3d
paulroth3d / _chainMonadReadme.md
Last active March 31, 2024 19:44
Simple chain monad

Overview

Creates a very simple monad, so you can give it a value - continually modifying it as you'd like, and then get a value out of it.

Example

addTwo = (value) => value + 2;
addTwo(3); // 5

Very simple snippet to export a set of objects, into:

  • an array of values
  • tsv
  • html table
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Simple use of vega within iJavaScript / Jupyter Notebook

Note that vega (through altair) is supported in iPython through Altair

If we wanted to make simple charts within a JavaScript environment, such as the iJavaScript kernel, then what we need to do are four main steps.

The snippet below handles this for you, so you can do something like this:

Screenshot

Overview

Useful for snippets if you want to merge in additional data

Exporting

Calling the downloadData() function will immediately create a file download (as though you right clicked to download the file within the browser) for the data you provide - in JSON format.

Overview

This puts a table from a web page into the clipboard (as Tab Separated Values)

This means you can effectively: select within a table, click a button and then paste it into a spreadsheet.

Requirements

(This may work on other browsers, feedback welcome)

  • Google Chrome - main focus

overview

Writes a table to html (such as for notebooks)

Examples

datasets = require('vega-datasets');

(async () => {
 cars = await datasets['cars.json']();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.