Skip to content

Instantly share code, notes, and snippets.

View discoNeko's full-sized avatar

Takuya Murata discoNeko

View GitHub Profile
@discoNeko
discoNeko / main.gs
Created March 30, 2020 12:51
M&A案件一覧を取得してslack通知、最新のものだけスプレッドシートに保存
function get(){
const response = UrlFetchApp.fetch("https://www.tranbi.com/buy/list/?prill=&priul=2500000&srl=&sru=&proll=&proul=&sd=1&sin=1&ft=&sort=-open_datetime&page_size=30");
const entries = Parser.data(response.getContentText()).from('<div class="buyListContents">').to('<div class="buyListBtn">').iterate();
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('A2');
const currentID = range.getValue();
const newEntries = []
entries.some(entry => {
// 1.昇順の順番に沿って挿入する
const a = [11, 22, 33, 44, 55, 66, 77, 88, 99]
let b = 50
let index = a.findIndex(v => v > b)
index < 0 ? a.push(b) : a.splice(index, 0, b)
console.log(a)
// output:
// > Array [11, 22, 33, 44, 50, 55, 66, 77, 88, 99]
@discoNeko
discoNeko / 順番の乱れたobjectをkeyでsortする.js
Last active January 29, 2020 00:27
順番の乱れたobjectをkeyでsortする.js
// 順番の乱れたobjectをkeyでsortする
const object1 = {
a: 'somestring',
c: false,
b: 42
};
console.log(Object.keys(object1));
// expected output: Array ["a", "c", "b"]
// これをa,b,cの順で処理したい
@discoNeko
discoNeko / onSnapshot.js
Created January 18, 2020 23:02
onSnapshot.js
/**
* @param {String} uid firebase/authentication のユーザーID
*/
checkStatus ({ commit, state }, uid) {
return new Promise(resolve => {
firestore.collection('users').doc(uid)
.onSnapshot(doc => {
// usersコレクションにレコードがあるかチェック
const user = doc.exists ? doc.data() : null
// もし管理者権限が無ければログイン画面に飛ばす
const id = "id1"
const results = { "aaa": { id: "id1", name: "111" }, "bbb": { id: "id1", name: "222" }, "ccc": { id: "id2", name: "333" }}
const array = Object.values(results).filter(result => result.id == id)
console.log(array)

> Array [Object { id: "id1", name: "111" }, Object { id: "id1", name: "222" }]

firebaseとdate型 firebaseに保存されている日付データの型はいくらか種類があるので調べる

firebase/authentication

認証時に保存されるユーザ作成日

const admin = require('firebase-admin')
admin.auth().listUsers.filter(user => {
    console.log(user.metadata.creationTime) // javascriptのdate型
<script>
const url1 = 'https://www.facebook.com/profile.php?id=100012461591178' // has number id
const url2 = 'https://www.facebook.com/takmurat' // has string id
const url3 = 'https://www.facebook.com/groups/155076295120010' // has group id
const url4 = 'https://www.facebook.com'
const url5 = 'https://www.facebook.com/'
const url6 = 'https://www.facebook.com//'
// split
console.log(url1.split('/'))

sudo rm -rf node_modules

npm lsでエラーが出るとき

ex.

/Users/cometqp
├── vue@2.6.10
├── UNMET PEER DEPENDENCY webpack@^2.0.0 || ^3.0.0 || ^4.0.0
@discoNeko
discoNeko / rename.sh
Last active July 14, 2020 22:55
一括リネーム.sh
# 重複しないよう_をプリフィックス、ファイル名にスペースがあると失敗する
for i in *.png;do mv $i _$i;done
# リネーム
# 0.png,1.png,...となるようリネーム
CNT=0;for i in *.png;do mv $i $CNT.png;CNT=$((CNT+1));done
# ファイル作成日yyyy-mm-dd-hh:mm:ss.pngにリネーム
for i in *.png;do stat $i | grep 'Access: 20.*' | cut -d' ' -f2,3| cut -d'.' -f1 | sed 's/ /-/g' | xargs -I{} mv $i {}.png;done
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
/*
sample input