Instantly share code, notes, and snippets.

View sublimetext-ignore-goto-definition-by-pattern.md

Sublime Text 3: Ignores some "goto definition" candidates by file/folder patterns filter

Open Project -> Edit Project

{
  "folders": [
    {
      "path": "hoge-project",
      "follow_symlinks": true,
View async-iterator-example.js
const fs = require("fs");
const inputFilePath = process.argv[2];
console.log("file:", inputFilePath);
async function main(inputFilePath) {
const readStream = fs.createReadStream(inputFilePath, { encoding: 'utf8', highWaterMark: 1024 });
// NOTE: Async-Iterator starts with NodeJS v10, but it's experimental yet. (Current latest LTS version: v10.13.0)
for await (const chunk of readStream) {
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",