Skip to content

Instantly share code, notes, and snippets.

View tai-sho's full-sized avatar
🏠
Working from home

ShoheiTai tai-sho

🏠
Working from home
View GitHub Profile
@tai-sho
tai-sho / carbon_tracking.gs
Created April 24, 2024 05:19
webサイトのCO2消費量をスプレッドシート出力する。 API Doc: https://api.websitecarbon.com/
const TARGET_URL = 'https://example.com';
const CARBON_API_URL = `https://api.websitecarbon.com/site?url=${TARGET_URL}`;
/**
* APIからデータを取得し、スプレッドシートに記録する
*/
function main() {
const response = callApi(CARBON_API_URL);
if (response !== null) {
writeToSpreadsheet(response);
@tai-sho
tai-sho / index.gs
Last active April 15, 2024 04:03
Google Apps Scriptを使用し1ヶ月分のバイオリズムをGoogleカレンダーに登録します。トリガーで毎月月初で登録をする想定で実装。冪等性があり、複数回実行した場合も重複は有りません。 This script calculates biorhythms based on a given birthday and adds them as events to a specified Google Calendar. Each event's title includes the biorhythm type and its value. It is designed to run on the 1st of every month and is idempotent, me…
/**
* This script calculates biorhythms based on a given birthday and adds them as events
* to a specified Google Calendar. Each event's title includes the biorhythm type and its value.
* It is designed to run on the 1st of every month and is idempotent, meaning it can run
* multiple times a month without causing duplicate entries. It deletes any existing biorhythm
* events for the month before adding new ones.
*
* Cycles:
* - Physical: 23 days
* - Emotional: 28 days
@tai-sho
tai-sho / main.gs
Last active July 16, 2023 03:46
Using GoogleAppsScript to link OuraRing's sleep score to the calendar
/**
* Refer to https://tech.affordigitalife.com/oura-api-sleep-log/
*/
function main() {
const days = 10;
for (let i = 0; i < days; i++) {
let today = new Date()
today.setDate(today.getDate() - i)
let yesterday = new Date()
yesterday.setDate(yesterday.getDate() - (i + 1))
@tai-sho
tai-sho / main.js
Created July 3, 2017 17:42
jsでURLの一番最後のディレクトリ名を取得する
location.pathname.replace(/\/+$/, "").split('/').pop();
@tai-sho
tai-sho / removeExif.php
Last active May 19, 2021 03:27
EXIF情報を削除する関数
<?php
/**
* JPEGのEXIF情報を削除します。
* 元画像は削除した上で変換後のファイルを置き換えます。
* @param string $path 画像パス
* @return boolean
*/
function removeExif($path) {
$status = true;
list(, , $type) = getimagesize($path);
@tai-sho
tai-sho / gitlab-ci.yml
Created December 19, 2020 16:53
Automate deployment to Shopify with Gitlab-CI.
image: python:2
stages:
- deploy
before_script:
- curl -s https://shopify.github.io/themekit/scripts/install.py | python
deploy_staging:
stage: deploy
@tai-sho
tai-sho / GenerationGapModelTask.php
Created December 8, 2019 17:22
bake with generation gap pattern
<?php
namespace App\Shell\Task;
use Bake\Shell\Task\ModelTask;
use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\ORM\TableRegistry;
/**
* Class GenerationGapModelTask
@tai-sho
tai-sho / DatabaseMigrateResetCommand.php
Created March 12, 2019 04:04
CakePHP3.6でデータベース初期化+マイグレーションを行う。 rails db:migrate:resetと同様
<?php
namespace App\Command;
use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\Datasource\ConnectionManager;
/**
@tai-sho
tai-sho / WebStorageQueue.js
Last active February 8, 2019 12:10
WebStorageを使用したQueue
/**
* WebStorageでQueueを管理するクラス
* @class WebStorageQueue
*/
;WebStorageQueue = (function() {
'use strict';
function WebStorageQueue(storage, key) {
if(!storage) {
throw new Error('Storageオブジェクトが取得できませんでした。');
}
@tai-sho
tai-sho / MyHtmlHelper.php
Last active December 10, 2017 15:46
SEO対策。microdataを付与したパンくずリストを生成する。HtmlHelper::addCrumbListを継承。
<?php
App::uses('HtmlHelper', 'View/Helper');
class MyHtmlHelper extends HtmlHelper {
/**
* microdata属性対応版
* @link https://support.google.com/webmasters/answer/185417?hl=en
* @see HtmlHelper::getCrumbList()
*/