Skip to content

Instantly share code, notes, and snippets.

View gh640's full-sized avatar
🦔

Goto Hayato gh640

🦔
View GitHub Profile
@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
"""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
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
{
"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 コマンドチートシート
# 非表示ファイルを対象に含める
# -., --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
{
"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`
"""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 / amazon-exclude-marketplace-items.js
Last active January 6, 2023 09:20
Bookmarklet: Exclude marketplace items from Amazon search
javascript:(() => {
let url = new URL(document.location.href);
url.searchParams.append('rh', 'p_6:AN1VRQENFRJN5');
window.location.assign(url);
})()
@gh640
gh640 / import_path.py
Last active September 2, 2022 01:06
Python: importing a Python module without `.py` extension
from importlib.machinery import SourceFileLoader
from importlib.util import module_from_spec, spec_from_file_location
from pathlib import Path
def import_path(path: Path):
module_name = path.stem.replace('-', '_')
loader = SourceFileLoader(module_name, str(path))
spec = spec_from_file_location(module_name, path, loader=loader)
@gh640
gh640 / pyproject.toml
Created August 14, 2022 00:31
Sample: Pyright settings to use a virtualenv with `pyproject.toml`
[tool.pyright]
include = ["mypackage"]
pythonVersion = "3.10"
venvPath = "/path/to/poetry/virtualenvs"
venv = "venv_dir_name"
@gh640
gh640 / timestamp-macos.sh
Last active August 9, 2022 03:23
Get and parse timestamp on macOS
# Get timestamp of current date/time.
alias timestamp='date "+%s"'
# Get timestamp of today 00:00:00.
alias timestamp_today='date -v0H -v0M -v0S "+%s"'
# Take timestamp and print it in human-readable format (in the current timezone).
alias timestamp_parse='date -r'
# Take timestamp and print it in human-readable format (in UTC).