Skip to content

Instantly share code, notes, and snippets.

View iamnivekx's full-sized avatar
:octocat:
Focusing

Nivek Huang iamnivekx

:octocat:
Focusing
View GitHub Profile
@iamnivekx
iamnivekx / encrypt.ts
Last active April 24, 2024 02:08
encrypt and decrypt the text using the password.
/**
* This file is used to encrypt and decrypt the text using the password.
* The password is used to derive the key using PBKDF2.
* The key is used to encrypt and decrypt the text using AES-GCM.
* The salt is used to derive the key using PBKDF2.
* The nonce is used to encrypt and decrypt the text using AES-GCM.
* The ciphertext is the encrypted text.
* The salt, nonce, and ciphertext are concatenated and converted to Base64.
* inspire by https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/controllers/user-storage/encryption.ts
*/
@iamnivekx
iamnivekx / visit.md
Last active September 4, 2023 01:54
rust visit dir
@iamnivekx
iamnivekx / csv.js
Last active April 24, 2024 02:05
node csv example
const fs = require('fs');
// const csv = require('csv');
const { stringify } = require('csv-stringify');
const { parse } = require('csv-parse');
const { transform } = require('stream-transform');
async function readFromCSVFile(filename = 'read.csv') {
const readStream = fs.createReadStream(filename);

Mistakes to Avoid: Docker Antipatterns

Whichever route you take to implementing containers, you’ll want to steer clear of common pitfalls that can undermine the efficiency of your Docker stack.

Don’t run too many processes inside a single container

The beauty of containers—and an advantage of containers over virtual machines—is that it is easy to make multiple containers interact with one another in order to compose a complete application. There is no need to run a full application inside a single container. Instead, break your application down as much as possible into discrete services, and distribute services across multiple containers. This maximizes flexibility and reliability.

Don’t install operating systems inside Docker containers

It is possible to install a complete Linux operating system inside a container. In most cases, however, this is not necessary. If your goal is to host just a single application or part of an application in the container, you need to install only the essential

@iamnivekx
iamnivekx / mark.md
Created June 11, 2020 03:45
JS mark
const dateFromObjectId =  (objectId) => new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
/* prettier的配置 */
"prettier.printWidth": 480, // 超过最大值换行
"prettier.tabWidth": 2, // 缩进字节数
"prettier.useTabs": false, // 缩进不使用tab,使用空格
"prettier.semi": true, // 句尾添加分号
"prettier.singleQuote": true, // 使用单引号代替双引号
"prettier.proseWrap": "preserve", // 默认值。因为使用了一些折行敏感型的渲染器(如GitHub comment)而按照markdown文本样式进行折行
"prettier.arrowParens": "always", // (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号
"prettier.bracketSpacing": true, // 在对象,数组括号与文字之间加空格 "{ foo: bar }"
"prettier.disableLanguages": ["vue"], // 不格式化vue文件,vue文件的格式化单独设置
{
"parserOptions": {
"parser": "babel-eslint",
"ecmaFeatures": {
// 启用对实验性的 object rest/spread properties 的支持。
"experimentalObjectRestSpread": true,
"jsx": true,
"globalReturn": false,
// 启用全局 strict mode
"impliedStrict": true