Skip to content

Instantly share code, notes, and snippets.

@naosim
naosim / SheetDb.js
Last active July 17, 2019 01:26
【GAS】シートをDBのように扱う。オブジェクト版
function SheetDb(spreadSheet) {
/**
* レコードの全取得
*/
function findAll(name /* シート名 */) {
var sheet = spreadSheet.getSheetByName(name);
var table = sheet.getDataRange().getValues()
return JSON.parse(JSON.stringify(table));
}
@naosim
naosim / GithubApi.js
Created July 16, 2019 22:46
【GAS】GithubApiライブラリ
function GithubApi(
accessToken,
owner,
repo
) {
var requestOptions = {
headers: { Authorization: 'token ' + accessToken }
}
function exec(url) {
@naosim
naosim / loadLibForMethods.js
Created July 16, 2019 22:42
【GAS】複数メソッドをロードする
/**
* 複数メソッドをロードする
* 依存:
* - retryFetch https://gist.github.com/naosim/8fc6033b6f92e426eddc0424e7f7aa71
*/
function loadLibForMethods(methodNames, url) {
eval(retryFetch(url))
var result = {};
methodNames.forEach(function(name) {
@naosim
naosim / retryFetch.js
Created July 16, 2019 22:12
【GAS】リトライありのfetch
function retryFetch(url) {
var lastError = null;
for(var i = 0; i < 3; i++) {
try {
var res = UrlFetchApp.fetch(url)
if(res.getResponseCode() == 200) {
return res.getContentText("UTF-8")
} else {
lastError = 'HTTPステータスコードが200以外: ' + res.getResponseCode() + ', ' + url;
}
@naosim
naosim / loadLibForOneMethod.js
Last active May 11, 2021 19:58
【GAS】githubやgist上のライブラリを読み込むスニペット
/**
* 外部ファイルからjsを読み込む
* githubやgists上にあるコードを使いたい時用
*/
function loadLibForOneMethod(mainMethodName, url) {
// リトライありのfetch
function retryFetch(url) {
var lastError = null;
for(var i = 0; i < 3; i++) {
try {
@naosim
naosim / sheet.js
Last active July 12, 2019 22:23
GASでスプレッドシートを操作する
/**
* レコードの全取得
*/
function findAll(name /* シート名 */) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(name);
var table = sheet.getDataRange().getValues()
return JSON.parse(JSON.stringify(table));
}
/**
@naosim
naosim / lastupdate.js
Created December 18, 2018 02:02
ディレクトリ配下で最後に更新したファイルを取得する
// 最後に更新されたファイルを取得する
// 利用例
// ls -l | node lastupdate.js
// => 2018-12-18 10:50 ./worklog/index.js
//
// サブディレクトリも対象にするならこう
// find . -type f | xargs ls -l | node worklog index.js
//
// 事前準備
// npmで'textpipe'を入れておくこと
@naosim
naosim / table.js
Created June 12, 2018 21:59
markdownからcreatetableを作るメモ
// node . inputfile outRootDir
if(process.argv.length == 2) {
const msg = 'USAGE\nnode . inputMarkdownFile outRootDir'
console.log(msg)
throw msg
}
const inputMarkdownFile = process.argv[2]
const outRootDir = process.argv[3]
@naosim
naosim / table2md.html
Created June 5, 2018 21:30
htmlのテーブルからmarkdownを作る
<!DOCTYPE html>
<div id="div20180606">
<table border="1">
<tr><th>名前</th><th>備考</th>
<tr><td>ほげ</td><td>改行<br>テスト</td></tr>
<tr><td>ふー</td><td>改行<br>テスト</td></tr>
</table>
</div>
<script>
@naosim
naosim / vo_string.js
Created May 13, 2018 07:47
バリューオブジェクト生成 (String)
const template = `
package __PACKAGE__;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
@AllArgsConstructor
@EqualsAndHashCode
public class __CLASS__ {
private final String value;