Skip to content

Instantly share code, notes, and snippets.

@nkgrnkgr
nkgrnkgr / omit.md
Created February 22, 2022 00:23
omit.ts & omit.test.ts

object から 特定のobjectの一部を除外する

export function omit<T extends Record<string, unknown>>(
  object: T,
  keys: Array<keyof T>
) {
  return Object.fromEntries(
    Object.entries(object).filter(([key, _]) => !keys.includes(key))
 );
set fenc=utf-8
set nobackup
set noswapfile
set autoread
set hidden
set showcmd
set number
set cursorline
@nkgrnkgr
nkgrnkgr / index.html
Created December 6, 2018 14:41
Firebase SimpleChatApp Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B"
crossorigin="anonymous">
<script src="https://www.gstatic.com/firebasejs/4.12.1/firebase.js"></script>
service: demo-kotlin-serverless
provider:
name: aws
runtime: java8
stage: dev
region: ap-northeast-1
package:
artifact: build/distributions/demo-0.0.1-SNAPSHOT.zip
@nkgrnkgr
nkgrnkgr / FileIO.js
Created July 11, 2018 13:35
Basic FileIO for Node.js (file read, read line, write)
const fs = require("fs");
const readline = require("readline");
const stream = fs.createReadStream("./data/out1.txt", "utf8");
const reader = readline.createInterface({
input: stream
});
const writeFile = (path, data) => {
fs.writeFile(path, data, err => {
@nkgrnkgr
nkgrnkgr / lambda.js
Created July 2, 2018 21:56
Use array.map in combination with async await in AWS Lambda
const axios = require('axios');
const res = {
statusCode: 200,
body: []
}
const httpList = [
'https://transitlist.herokuapp.com/',
'https://www.google.co.jp',
@nkgrnkgr
nkgrnkgr / browser.js
Created July 1, 2018 13:52
Use Puppeteer in Proxy
const puppeteer = require('puppeteer');
(async() => {
const proxyUrl = 'http://proxy.example.com:8000';
const username = 'bob';
const password = 'password123';
const browser = await puppeteer.launch({
args: [`--proxy-server=${proxyUrl}`],
headless: false,
@nkgrnkgr
nkgrnkgr / round.js
Last active June 27, 2018 11:46
JavaScript で 小数点 第 n 位 で四捨五入する
// 非推奨
// const round = (num, decimalPoint) => Math.round(num * Math.pow(10, decimalPoint)) / Math.pow(10, decimalPoint);
const round = (num, decimalPoint) => Math.round(num * 10 ** decimalPoint) / 10 ** decimalPoint;
console.log(round(12.335, 2)); // => 12.34
@nkgrnkgr
nkgrnkgr / s3_IO.js
Created June 25, 2018 13:13
AWS-Labmda-S3-Read-Write.js
const aws = require('aws-sdk');
aws.config.region = 'us-east-1';
const s3 = new aws.S3();
const paramsToGet = {
Bucket: 'bucketname',
Key: 'dir/file.json'
};
const paramsToPut = body => {
@nkgrnkgr
nkgrnkgr / readJson.js
Created June 23, 2018 14:14
Node.js で JSONファイルの読み込み / Object.entries をつかった key, value 同時取得の実装
const fs = require('fs');
const json = JSON.parse(fs.readFileSync('./a.json', 'utf8'));
for (let o of json) {
for (let [key, value] of Object.entries(o)) {
console.log({ key, value });
}
}