Skip to content

Instantly share code, notes, and snippets.

@naosim
naosim / note.txt
Created March 22, 2024 13:32
てすと
テストだよ
@naosim
naosim / tableSchema.json
Created February 11, 2024 11:38
テーブル定義のためのJSON Schema
{
"type": "array",
"items": {
"$ref": "#/$defs/table"
},
"$defs": {
"table": {
"name": "table",
"type": "object",
"properties": {
@naosim
naosim / pocco.mjs
Last active December 22, 2023 20:29
pocco
import http from "http";
import fs from "fs";
import path from "path";
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const server = http.createServer((req, res) => {
const reqPath = req.url;
const sanitizedPath = path.normalize(reqPath).replace(/^(\.\.[\/\\])+/, '');
@naosim
naosim / renameGitBranch.md
Last active December 20, 2023 12:09
ローカルとリモートのブランチ名を変更する

#ローカルとリモートのブランチ名を変更する

以下、ブランチ名を hoge から foo に変更する例

  • ローカルのブランチ名変更
git branch -m hoge foo
  • リモートのブランチを消す
@naosim
naosim / ipv6.js
Last active November 28, 2023 13:37
ipv6
function getBitsAfter33(ipv6) {
function hexTo2Bits(v, bitLength = 4) {
if(v >= 10) {
v = "ABCDEF"[v - 10]
}
return (new Array(bitLength).fill("0").join("") + parseInt(v, 16).toString(2)).slice(-bitLength);
}
function bit2toHex(num) {
var p = num.split("").reverse().map((v, i) => Math.pow(2, i) * parseInt(v)).reduce((memo, v) => memo + v, 0);
if(p < 10) {
@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 / gasToMisskey.js
Created March 1, 2023 09:20
GoogleAppsScriptでMisskeyに投稿する
/**
* @param {string} text
* @param { {server: string, token: string} } options options.serverはたとえば"misskey.io"
*/
function postToMisskey(text, options) {
return UrlFetchApp.fetch(
`https://${options.server}/api/notes/create`,
{
'method': 'POST',
'headers' : {'Content-Type': 'application/json'},
@naosim
naosim / todo.js
Last active July 31, 2023 14:11
spreadsheetでtaskAPIを使ってタスクを管理する
// いい感じに同期します
// 新規タスクの追加
// 変更点の更新
// GoogleTasksの読み込み
function update() {
new MainService().update();
}
function onOpen() {
const customMenu = SpreadsheetApp.getUi()
@naosim
naosim / todaysSchedule.js
Created April 17, 2023 11:26
Googleカレンダーの予定取得
function exportCalendarEvents() {
// カレンダーIDを入力してください
var calendarId = "primary";
// フォーマット
var format = "yyyy/MM/dd HH:mm:ss";
// 今日の日付を取得
var today = new Date();
// 今日の0時0分0秒を計算
var startOfDay = new Date(today.getFullYear(), today.getMonth(), today.getDate());
@naosim
naosim / gasGannt.js
Created March 23, 2023 02:22
GoogleSpreadSheetでガントチャートを使うときのユーティリティ
const headers = ["ID", "タスク名", "開始日", "終了日", "日数", "依存タスク"];
function setup() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("シート1");
if(sheet.getRange(1, 1).getValue() == "入力用") {
throw new Error("すでに実行済みです");
}
sheet.appendRow(["入力用"])
sheet.appendRow(headers)