Instantly share code, notes, and snippets.

View chart.js-simple-stock-chart-example.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Char.js Simple Stock Chart Example</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js" integrity="sha256-XF29CBwU1MWLaGEnsELogU6Y6rcc5nCkhhx89nFMIDQ=" crossorigin="anonymous"></script>
View parsePaymentURIScheme.js
/**
* Payments URI Scheme Parser
* @param {String} - eg. "bitcoin:1XXX?amount=123&comment=%66%77"
* @see also: https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
*/
function parsePaymentURIScheme(s) {
const tmp = s.match(/^(\w+)\:(\w+)\??(.+)?/);
const protocol = (tmp && tmp.length >= 1) ? tmp[1] : null;
const address = (tmp && tmp.length >= 2) ? tmp[2] : null;
const qstr = (tmp && tmp.length >= 3) ? tmp[3] : null;
View generate-entropy-on-mouse-moving.js
// const entropy = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
const entropy = [];
let captureStart = false;
/**
* Mouse Moving Entropy Generator on browser.
* Returns an entropy which is 16 bytes long array of unsigned char integer (0-255).
*/
$(document).on("mousemove", "html", function(e) {
const MAX_LEN = 16; // size of entropy's array
View aes-encrypt-decrypt.js
const aesjs = require('aes-js');
const pbkdf2 = require('pbkdf2');
const password = "mySecretPassword";
const message = "HelloWorld!";
const encrypted = encrypt(message, password);
console.log("encrypted:", encrypted); // 3ed20b7c474c96af513d1c
const decrypted = decrypt(encrypted, password);
console.log("decrypted:", decrypted); // HelloWorld!
View ripple-tx-validation-check-memo.md
// submit tx:
submitTx(signedTx, (err, res) => {
  if (err) throw err;
  // Check if `engine_result` is "tesSUCCESS": 
  if (res.engine_result !== "tesSUCCESS") {
    // the tx's failed immediately.
    return;
  }
  const txhash = res.tx_json.hash;
View ripple-understand-rippled-book_offers-request-response.md

Ripple: Understand rippled book_offers request & response

Request example (on TestNet)

{
  "id": 4,
  "command": "book_offers",
  "taker": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
  "taker_gets": {
    "currency": "XRP"
View WsClient.js
/*
websocket client module (supports either NodeJS and browser)
NOTE:
`browserify` makes this websocket client lib browser-compatible.
# Usage
```
const onmessage = function(e) {
console.log("onmessage:", e);
View RpcClient.js
// Simple JSON RPC Client
const request = require("request");
const requestAsync = require("request-promise");
// const axios = require("axios");
module.exports = class RpcClient {
constructor({
url,
jsonrpc = "2.0",
View getCounterwalletAddress.js
/*
* Usage:
* $ node ./getCounterwalletAddress.js "<livenet_or_testnet>" <derived_index> "<passphrase of 12 words>"
*/
const network = process.argv[2]; // "testnet" or "livenet"
const index = process.argv[3]; // derived address's index
const passphrase = process.argv[4]; // passphrase
// Mnemonic function inspired by:
// Mnemonic.js v. 1.0.0
View headlesschrome-puppeteer-example.js
const puppeteer = require('puppeteer');
const evaluateFn = async() => {
// const title = document.title; // by pure js
const title = $("title").text(); // by jquery
return {
title,
// width: document.documentElement.clientWidth,
// height: document.documentElement.clientHeight,