Skip to content

Instantly share code, notes, and snippets.

@masatomix
masatomix / Swagger
Created December 12, 2022 11:20
Power Automateに処理させるように少しだけ修正した、UiPath Orchestrator APIのSwaggerの定義ファイル
{
"swagger": "2.0",
"info": {
"title": "UiPath.WebApi 15.0",
"description": "Orchestrator API",
"version": "15.0"
},
"host": "cloud.uipath.com",
"basePath": "/mvpjapankino/enterpriseTenant/orchestrator_/",
"schemes": [
@masatomix
masatomix / xlsx2csvString2JSON.ts
Last active March 19, 2020 00:59
Excel → JSON。(データ中心)any[][] を経て、ヘッダ部とデータ部を使ってJSON化。各行ごとに、データ部を左から順次走査して、同じIndexのヘッダ部を取得してプロパティにする
const XlsxPopulate = require('xlsx-populate')
// 指定された場合は、一行目の文字列群を使ってプロパティを作成する
const workbook: any = await XlsxPopulate.fromFileAsync(inputFullPath)
const headers: string[] = workbook
.sheet(sheetName)
.usedRange()
.value()
.shift()
@masatomix
masatomix / xlsx2csvString2JSON.ts
Last active March 19, 2020 00:58
Excel → JSON。(ヘッダ中心)。any[][] を経て、ヘッダ部とデータ部を使ってJSON化。各行ごとに、ヘッダ部を左から順次走査して、同じIndexのデータ部を取得してプロパティにする
const XlsxPopulate = require('xlsx-populate')
// 指定された場合は、一行目の文字列群を使ってプロパティを作成する
const workbook: any = await XlsxPopulate.fromFileAsync(inputFullPath)
const headers: string[] = workbook
.sheet(sheetName)
.usedRange()
.value()
.shift()
@masatomix
masatomix / xlsx2csvString2JSON.ts
Last active March 19, 2020 00:59
Excel → CSV文字列 → JSON。any[][] を経て csv文字列を愚直に作成。csvtojson で先頭行をPropertyにJSON化。
const XlsxPopulate = require('xlsx-populate')
const workbook: any = await XlsxPopulate.fromFileAsync(inputFullPath)
const headers: string[] = workbook
.sheet(sheetName)
.usedRange()
.value()
.shift()
hoge(x: number, y: number, z: number): number {
return x + y + z
}
hoge_curry(x: number): (y: number) => (z: number) => number {
return (y: number): ((z: number) => number) => {
return (z: number): number => {
return x + y + z
}
}
@masatomix
masatomix / reduce.ts
Last active March 19, 2020 01:05
Reduceのサンプル. 収集するaccumulatorと初期値を設定するのが重要
const array1 = [1, 2, 3, 4,5];
const reducer = (accumulator, currentValue,index) => {
console.log(`---`)
console.log(`Index: ${index}`)
console.log(`A: ${accumulator}`)
console.log(`C: ${currentValue}`)
return {value: accumulator.value + currentValue}
return accumulator+currentValue
}
@masatomix
masatomix / Group Indication.ts
Last active March 19, 2020 01:03
同じ key値のデータを、配列としてまとめる。
const re: { [key: string]: any[] } = {}
const datas = [
{ key: 'a', id: 'a_id1', value: '11' },
{ key: 'a', id: 'a_id2', value: '12' },
{ key: 'a', id: 'a_id3', value: '13' },
{ key: 'b', id: 'b_id1', value: '21' },
{ key: 'b', id: 'b_id2', value: '22' },
]
for (const row of datas) {
@masatomix
masatomix / gist:d0d00bceff0d46da38fc75a1872d20ed
Last active March 2, 2020 15:03
日付考慮コード。
const moment = require('moment-timezone')
// シンプルに
console.log(moment().format()) // 2020-02-13T10:47:10+09:00 (いま日本で10:47です)
console.log(new Date().toLocaleString()) // 2020-2-13 10:50:22 AM
// ってやると本番に行くと値が9時間ずれるよね、みたいな件。。
// 日付をあつかうには
// どのタイムゾーンの日付か(Timezone)
// どの言語で表示するか(Locale)
const request = require('request')
const url = 'https://rss.techplay.jp/event/w3c-rss-format/rss.xml'
request(url, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
const regex = /[\b]/
body = body.replace(regex)
const json = xml2json(body)
// for (var i in json.rss.channel.item) {
@masatomix
masatomix / cloudformation_orch.json
Last active July 9, 2019 02:34
AWS CloudFormationを使って、セキュリティグループとEC2インスタンスを作成する Infra as code.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"VpcId": {
"Type": "AWS::EC2::VPC::Id",
"Description": "VpcId of your existing Virtual Private Cloud (VPC)"
},
"SubnetId": {
"Type": "AWS::EC2::Subnet::Id",
"Description": "SubnetId of your existing Subnet"