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 _sodium = require('libsodium-wrappers-sumo'); | |
(async () => { | |
await _sodium.ready; | |
const sodium = _sodium; | |
console.log(sodium.from_base64('SGVsbG8=', sodium.base64_variants.ORIGINAL)); // Uint8Array(5) [72, 101, 108, 108, 111] | |
console.log(sodium.from_hex('48656c6c6f')); // Uint8Array(5) [72, 101, 108, 108, 111] | |
console.log(sodium.from_string('Hello')); // Uint8Array(5) [72, 101, 108, 108, 111] | |
console.log(sodium.to_base64(new Uint8Array([72, 101, 108, 108, 111]), sodium.base64_variants.ORIGINAL)); // "SGVsbG8=" |
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
async function getAllDexieDatabaseNames(dexieRootName = '__dbnames') { | |
return new Promise((resolve, reject) => { | |
const DBOpenRequest = window.indexedDB.open(dexieRootName); | |
DBOpenRequest.onerror = () => reject(DBOpenRequest.error); | |
DBOpenRequest.onsuccess = () => { | |
const db = DBOpenRequest.result; | |
const dbNameStore = Array.from(event.target.result.objectStoreNames); | |
if (dbNameStore.length > 0) { | |
const transaction = db.transaction('dbnames', 'readonly'); | |
transaction.onerror = () => reject(transaction.error); |
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> | |
<head></head> | |
<body> | |
<input id="file-upload" multiple="multiple" type="file"/> | |
<img id="file-placeholder"/> | |
<script> | |
function blobToDataURI(blob) { | |
return new Promise((resolve, reject) => { | |
const reader = new FileReader(); |
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 config = require(`${process.cwd()}/knexfile`)[String(process.env.NODE_ENV)]; | |
const knex = require('knex')(config); | |
import {Model} from 'objection'; | |
module.exports = async () => { | |
await knex.migrate.latest(); | |
Model.knex(knex); | |
}; |
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 config = require(`${process.cwd()}/knexfile`)[process.env.NODE_ENV]; | |
const knex = require('knex')(config); | |
const {Model} = require('objection'); | |
beforeAll(async done => { | |
await knex.migrate.latest(); | |
await knex(Candlestick.tableName).truncate(); | |
Model.knex(knex); | |
done(); |
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
var isInPrivateMode = () => { | |
if (!window.indexedDB) { | |
return Promise.resolve(false); | |
} else { | |
return new Promise((resolve, reject) => { | |
const name = 'test'; | |
const DBOpenRequest = window.indexedDB.open(name); | |
DBOpenRequest.onerror = () => resolve(true); | |
DBOpenRequest.onsuccess = () => { | |
const db = DBOpenRequest.result; |
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 os = require('os'); | |
const fs = require('fs-extra'); | |
const file = 'logfile.txt'; | |
const options = {flag: 'a'}; | |
async function writeToFile(text) { | |
await fs.outputFile(file, `${text}${os.EOL}`, options); | |
} |
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
gource -1280x720 -o - --seconds-per-day 0.1 --hide progress,filenames | ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gource.mp4 |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<title>HTML5</title> | |
</head> | |
<body> | |
<p>Hello</p> | |
</body> | |
</html> |
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
class NetworkError extends Error { | |
constructor(public message: string) { | |
super(message); | |
Object.setPrototypeOf(this, NetworkError.prototype); | |
this.name = 'NetworkError'; // Don't use "constructor.name" here because it won't work as expected when minifying the code ;) | |
this.stack = new Error().stack; | |
} | |
} | |
export {NetworkError}; |