Skip to content

Instantly share code, notes, and snippets.

View gh640's full-sized avatar
🦔

Goto Hayato gh640

🦔
View GitHub Profile
@gh640
gh640 / sample-google-analytics-data.py
Created January 16, 2023 05:14
Sample: Getting session data of GA4 with Python and `google-analytics-data`
"""A sample to get sessions with Python and Google Analytics Data API v1.
with: google-analytics-data = "^0.16.0"
"""
from pathlib import Path
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import (
DateRange,
Dimension,
@gh640
gh640 / openai_assistants_stream.py
Last active March 14, 2024 06:48
サンプル: OpenAI Assistants stream API を使う
"""OpenAI の Assistant stream API を使う
Usage:
python -m pip install 'openai==1.14.0'
export OPENAI_API_KEY='...'
python openai_assistant_stream.py
See: https://platform.openai.com/docs/assistants/overview?context=with-streaming
"""
@gh640
gh640 / waitFor.js
Created November 21, 2023 05:51
JavaScript: async `waitFor` function
/**
* Wait for the specified milliseconds.
*/
async function waitFor(msec) {
await new Promise((resolve) => setTimeout(resolve, msec));
}
@gh640
gh640 / use_python_poetry_cache_on_github_actions_workflow.yml
Last active February 28, 2024 19:35
Sample: Use Python Poetry cache on GitHub Actions workflow
name: Use Python Poetry cache on GitHub Actions workflow
on:
push:
branches:
- main
env:
PYTHON_VERSION: "3.11"
POETRY_VERSION: "1.4.2"
@gh640
gh640 / use_mysqltuner_in_mariadb_container.sh
Last active February 28, 2024 02:10
Sample: Use MySQLTuner in `mariadb` Docker container
# MySQLTuner: https://github.com/major/MySQLTuner-perl
# Open Bash with the container.
docker exec [mariadb_or_mysql] bash
# Change the working directory to `/tmp`.
cd /tmp
# Install wget.
apt-get update
@gh640
gh640 / dropbox-ignore.sh
Created February 13, 2024 04:09
Ignoring a direcotry in Dropbox on macOS
# Ignore
xattr -w 'com.apple.fileprovider.ignore#P' 1 my-directory
# Disable ignoring
xattr -d 'com.apple.fileprovider.ignore#P' my-directory
# My aliases
alias dropbox-exclude="xattr -w 'com.apple.fileprovider.ignore#P' 1"
alias dropbox-include="xattr -d 'com.apple.fileprovider.ignore#P'"
@gh640
gh640 / send_message_on_google_chat.py
Last active February 10, 2024 04:52
Sample: Send a message on Google Chat group with Python `requests`
"""A sample to send message on Google Chat group with Python requests.
Prerequisites:
- Google API v1
- A webhook URL taken
- Python 3
- Requests (last tested with 2.31.0)
Usage:
@gh640
gh640 / asyncio_streaming_example.py
Created December 12, 2021 02:45
Python: Stream output of `asyncio.create_subprocess_exec()`
"""Stream output of `asyncio.create_subprocess_exec()`"""
import asyncio
import sys
async def run(program: str, args: list[str]):
"""Capture output (stdout and stderr) while running external command."""
proc = await asyncio.create_subprocess_exec(
program, *args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
@gh640
gh640 / enumerate.py
Last active December 8, 2023 05:59
Prefix lines with natural numbers.
#!/usr/bin/env python3
"""Prefix lines with natural numbers."""
import sys
from typing import Literal
NUMBER_SUFFIX = "."
def main() -> str | Literal[0]:
if sys.stdin.isatty():
@gh640
gh640 / drupal-coding-standard-customization-for-Japanese.md
Created February 6, 2016 08:16
PHP Code Sniffer を日本語でも快適に使うための Drupal コーディングスタンダードファイルの修正箇所

LineLengthSniff.php:

// changed for Japanese text.
// public $lineLimit = 80;
public $lineLimit = 500;

FunctionCommentSniff.php:

// comment out for Japanese comment.

// if (preg_match('|[A-Z]|', $testShort[0]) === 0) {