Skip to content

Instantly share code, notes, and snippets.

@Kim-YongJin
Kim-YongJin / puppeteer-cluster-lambda.js
Created February 22, 2021 08:40
[Puppeteer Cluster]Configuration for running in AWS lambda
const chromium = require('chrome-aws-lambda');
const { Cluster } = require('puppeteer-cluster');
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_PAGE,
maxConcurrency: 3,
puppeteer: chromium.headless ? require('puppeteer-core') : require('puppeteer'),
puppeteerOptions: {
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
@Kim-YongJin
Kim-YongJin / remote-file.js
Created February 22, 2021 07:45
[NodeJS]How to get a remote file size
const got = require("got");
async getRemoteFileSize(url) {
const response = await got(url, { method: 'head' });
const result = response.headers['content-length'];
console.log(`Target size: ${result}`);
return result
}
@Kim-YongJin
Kim-YongJin / local-file.js
Created February 22, 2021 07:44
[NodeJS]How to get a local file size
const fs = require('fs');
function getLocalFileSize(filePath) {
const stat = fs.statSync(filePath);
const result = stat.size;
console.log(`file size: ${result}`);
return result
}
@Kim-YongJin
Kim-YongJin / download.js
Last active February 22, 2021 07:36
[NodeJS]How to download a file from a Url
const got = require("got");
const { createWriteStream } = require("fs");
const stream = require("stream");
const { promisify } = require("util");
const pipeline = promisify(stream.pipeline);
async function download(targetUrl, savePath) {
const downloadStream = got.stream(targetUrl);
downloadStream.on("downloadProgress", ({ transferred, total, percent }) => {
const percentage = Math.round(percent * 100);
@Kim-YongJin
Kim-YongJin / Easy-way-to-attach-image-file-to-gist.md
Last active January 30, 2021 09:27
Easy way to attach image files to Gist

Easy way to attach image files to Github and Gist

  1. Scroll to comment window at page of Gist
  2. Copy&Paste or Drag&Drop image files to comment window. Some of tag will be genarated as the following. Easy way to attach image files to Gist
  3. Use genarated tags.

Note: Please don't click "comment" button.

@Kim-YongJin
Kim-YongJin / Easy-way-to-attach-image-file-to-gist.md
Created December 21, 2018 00:35
Easy way to attach image files to Gist

Easy way to attach image files to Gist

@Kim-YongJin
Kim-YongJin / wrap-cloudwatch-monitoring-memory-disk-for-ec2-linux.sh
Created December 17, 2018 08:24
Wrapper for cloudwatch-monitoring-memory-disk-for-ec2-linux.sh
# Download sh
curl https://gist.githubusercontent.com/Kim-YongJin/55ebad68ab16a86c9643a411a29f70a9/raw/cd9415ac72458226c692d744f57b7d50d78dd3eb/cloudwatch-monitoring-memory-disk-for-ec2-linux.sh -O
# Run sh
. cloudwatch-monitoring-memory-disk-for-ec2-linux.sh
# Delete sh
rm cloudwatch-monitoring-memory-disk-for-ec2-linux.sh
@Kim-YongJin
Kim-YongJin / cloudwatch-monitoring-memory-disk-for-ec2-linux.md
Last active December 17, 2018 08:15
[Only 2 step]Monitoring Memory and Disk Metrics for AWS EC2 Linux Instances

Step 1(permissions)

Ensure the permissions. It needs 4 permissions the following.

  • cloudwatch:PutMetricData
  • cloudwatch:GetMetricStatistics
  • cloudwatch:ListMetrics
  • ec2:DescribeTags

You can attach permittions using one of the following options.

  • Associate an IAM role with your instance