Skip to content

Instantly share code, notes, and snippets.

View gh640's full-sized avatar
🐻‍❄️

Goto Hayato gh640

🐻‍❄️
View GitHub Profile
@gh640
gh640 / waitFor.js
Created November 21, 2023 05:51
JavaScript: async `waitFor` function
View waitFor.js
/**
* Wait for the specified milliseconds.
*/
async function waitFor(msec) {
await new Promise((resolve) => setTimeout(resolve, msec));
}
@gh640
gh640 / use-WP_HTML_Tag_Processor.php
Created June 18, 2023 07:46
Sample: Using `WP_HTML_Tag_Processor` that is introduced WordPress 6.2.0
View use-WP_HTML_Tag_Processor.php
<?php
/**
* `WP_HTML_Tag_Processor` Modifies attributes in an HTML document for tags matching a query.
*/
$html = '<span><img src="hello.webp" alt="hello"></span>';
// Create an instance
$tags = new WP_HTML_Tag_Processor( $html );
@gh640
gh640 / saveFile.js
Created June 15, 2023 07:18
Saving a string as a file in browser console
View saveFile.js
// Function:
async function saveFile(fh, content) {
const stream = await fh.createWritable();
await stream.write(content, {type: "text/plain"});
await stream.close();
}
// Usage:
const content = 'Hello world';
const fh = await window.showSaveFilePicker();
@gh640
gh640 / apache2.conf
Last active June 8, 2023 01:45
Sample: Apache conf to ignore `internal dummy connection` in Docker image `php:8.0-apache`
View apache2.conf
# Exclude log records for internal dummy connections.
SetEnvIf Remote_Addr "127\.0\.0\.1" loopback
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!loopback
@gh640
gh640 / sample-ga-data-api.py
Last active April 11, 2023 06:00
Sample: Get pages with most sessions from GA4 with Python and Google Analytics Data API v1
View sample-ga-data-api.py
"""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 / action.yml
Created April 7, 2023 02:47
Sample: Composite action to install Python and Poetry on GitHub Actions workflows
View action.yml
name: 'Install Python and Poetry'
description: 'Add Poetry, dependency manager for Python'
inputs:
python-version:
description: 'Python version'
required: true
poetry-version:
description: 'Poetry version'
required: true
@gh640
gh640 / both-shifts-keypad-2.json
Last active February 23, 2023 01:22
Karabiner-Elements configuration to change sign keys to numpad sign keys if pressed with both shift keys
View both-shifts-keypad-2.json
{
"title": "Both shifts + signs => Keypad signs",
"rules": [
{
"description": "Both shifts + - => Keypad -",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "hyphen",
@gh640
gh640 / ripgrep-cheatsheet-ja.sh
Last active February 15, 2023 01:00
ripgrep コマンドチートシート
View ripgrep-cheatsheet-ja.sh
# 非表示ファイルを対象に含める
# -., --hidden
rg --hidden git
# マッチしない行を返す
# -v, --invert-match
rg -v 'docker' /var/log/syslog
# マッチした箇所のみを返す
# -o, --only-matching
@gh640
gh640 / both-shifts-keypad.json
Last active February 23, 2023 01:19
Karabiner-Elements configuration to change numbers with both shift keys if pressed with both shift keys
View both-shifts-keypad.json
{
"title": "Both shifts + numbers => Keypad numbers",
"rules": [
{
"description": "Both shifts + 1 => Keypad 1",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "1",
@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`
View sample-google-analytics-data.py
"""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,