# First, create a file as random seed, written as you like:
$ echo "<input_many_charactors_for_random_seed>" > random.txt
# Generate a private key:
$ openssl genrsa -rand random.txt 2048 > private.pem
# Generate a public key from above private key:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const { Transform } = require('stream'); | |
// upperCase transformer: | |
const upperCaseTr = new Transform({ | |
transform(chunk, encoding, callback) { | |
this.push(chunk.toString().toUpperCase()); | |
callback(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
... | |
<!-- for markdown --> | |
<script src="//cdn.jsdelivr.net/npm/marked/marked.min.js"></script> | |
<link rel='stylesheet' href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/styles/monokai.min.css" /> | |
<script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/highlight.min.js'></script> | |
<script | |
src="//code.jquery.com/jquery-3.3.1.slim.min.js" | |
integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E=" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sleep = msec => new Promise(resolve => setTimeout(resolve, msec)); | |
async function hoge() { | |
var ret = ""; | |
for (let len = 2, i = 0; i < len; i++) { | |
console.log("hoge loop ..."); | |
ret += await foo(); | |
} | |
return "HOGE!" + ret; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="node_modules/localforage/dist/localforage.nopromises.min.js"> | |
// $ npm install --save localforage | |
</script> | |
<script> | |
const dbname = "mydb"; | |
const opts = { | |
driver: localforage.INDEXEDDB, // localforage.WEBSQL, or localforage.LOCALSTORAGE | |
name: dbname | |
}; | |
console.log("creating instance with opts:", opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
/** | |
* clientside cookie session. | |
* it's faster than using any express-session-store, and not required any database server ;) | |
*/ | |
const sessions = require("client-sessions"); | |
app.use(sessions({ | |
cookieName: 'mySession', // cookie name dictates the key name added to the request object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create a short hash to **roughly** specify the accessed user's identity. | |
* The generated hash could be immutable only when either user's IP address and access date are same. | |
* | |
* CAUTION: | |
* NEVER use it for generate unique ID, it could NOT be unique! | |
*/ | |
const crypto = require("crypto"); | |
var text = "2018/04/01 xxx.xxx.xxx.xxx"; // "<Date> <IP>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
DDL: | |
CREATE TABLE `bindata` ( | |
`id` INT NOT NULL AUTO_INCREMENT, | |
`data` BLOB, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; | |
*/ | |
const fs = require("fs"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const dataUri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; | |
const outputFilename = "output"; | |
writeImage(dataUri, outputFilename); | |
readImage(outputFilename + ".png"); | |
function writeImage(dataUri, outputFilename) { | |
const regex = /^data:.+\/(.+);base64,(.*)$/; |