Skip to content

Instantly share code, notes, and snippets.

@peng-huang-ch
peng-huang-ch / 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
*/
@sindresorhus
sindresorhus / esm-package.md
Last active April 24, 2024 02:07
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@matyunin
matyunin / linux_tune.md
Last active April 24, 2024 02:05
Linux network performance tuning

###Tuning

$ netstat -nao | grep 8080 | grep TIME_WAIT | wc -l

To achieve the top most performance you should tune the source server system limits:

net.ipv4.tcp_max_tw_buckets = 65536
@metajiji
metajiji / install-megacli.md
Last active April 24, 2024 02:04 — forked from fxkraus/debian-install-megacli.md
Install LSI MegaCli

download

wget https://docs.broadcom.com/docs-and-downloads/raid-controllers/raid-controllers-common-files/8-07-14_MegaCLI.zip

or

curl -LO https://docs.broadcom.com/docs-and-downloads/raid-controllers/raid-controllers-common-files/8-07-14_MegaCLI.zip
@Klerith
Klerith / vite-testing-config.md
Last active April 24, 2024 02:04
Vite + Jest + React Testing Library - Configuraciones a seguir

Instalación y configuracion de Jest + React Testing Library

En proyectos de React + Vite

  1. Instalaciones:
yarn add --dev jest babel-jest @babel/preset-env @babel/preset-react 
yarn add --dev @testing-library/react @types/jest jest-environment-jsdom
  1. Opcional: Si usamos Fetch API en el proyecto:
@tonY1883
tonY1883 / ValidateYoutubeVideoId.js
Created September 14, 2017 02:18
A small trick to check if youtube video exist with its id.
function validVideoId(id) {
var img = new Image();
img.src = "http://img.youtube.com/vi/" + id + "/mqdefault.jpg";
img.onload = function () {
checkThumbnail(this.width);
}
}
function checkThumbnail(width) {
//HACK a mq thumbnail has width of 320.
@Klerith
Klerith / configurar-node-ts.md
Last active April 24, 2024 01:52
Node con TypeScript - TS-Node-dev simplificado

Node con TypeScript - TS-Node-dev (preferido)

  1. Instalar TypeScript y demás dependencias
npm i -D typescript @types/node ts-node-dev rimraf
  1. Inicializar el archivo de configuración de TypeScript ( Se puede configurar al gusto)
npx tsc --init --outDir dist/ --rootDir src
@romitkarmakar
romitkarmakar / seo.md
Created November 22, 2023 12:10
SEO Resources
@SahilMahadwar
SahilMahadwar / bing-wallpaper.sh
Last active April 24, 2024 01:49
You can use this script to automatically set Bing's image of the day as your wallpaper. It downloads the image and saves it to a chosen folder. It also keeps track of downloaded images using a JSON file, so it won't download the same one twice. Just set it to run on every login to keep your wallpaper fresh!
#!/bin/bash
# Fetch wallpaper from the API - https://github.com/TimothyYe/bing-wallpaper
api_url="https://bing.biturl.top/?resolution=3840&format=json&index=0&mkt=zh-CN"
response=$(curl -s "$api_url")
# Parse JSON response
start_date=$(echo "$response" | jq -r '.start_date')
end_date=$(echo "$response" | jq -r '.end_date')
image_url=$(echo "$response" | jq -r '.url')
@vishnuhd
vishnuhd / mysql-client-k8s.md
Created August 22, 2019 13:21
mysql-client in Kubernetes to test your connection to mysql server

mysql-client in Kubernetes to test your connection to mysql server

kubectl run mysql-client --image=mysql:5.7 -it --rm --restart=Never -- /bin/bash

mysql -h mysql-service -uroot -proot_password -e 'SHOW databases;'

OR

mysql -h mysql-service -uroot -proot_password