Skip to content

Instantly share code, notes, and snippets.

View dceoy's full-sized avatar
Lazy

Daichi Narushima dceoy

Lazy
View GitHub Profile
@dceoy
dceoy / bedrock-logging.cfn.yml
Last active May 20, 2025 08:56
[CloudFormation] AWS resources for Amazon Bedrock model invocation logging
---
AWSTemplateFormatVersion: 2010-09-09
Description: CloudFormation template to create resources for Amazon Bedrock model invocation logging
Parameters:
SystemName:
Type: String
Default: brmil
Description: Name of the system for which the resources are being created.
EnvType:
Type: String
@dceoy
dceoy / ics.py
Last active May 14, 2025 07:27
[Python] Check if now is any event in iCalendar data
"""Utilities for iCalendar (ICS) data."""
from datetime import datetime
from zoneinfo import ZoneInfo
import recurring_ical_events # type: ignore[reportMissingTypeStubs]
from aws_lambda_powertools import Logger
from icalendar import Calendar
logger = Logger()
@dceoy
dceoy / test_twilio_signature_validator.py
Last active May 14, 2025 07:35
[Python] Twilio signature validator
"""Unit tests for twilio_signature_validator module."""
import base64
import pytest
from aws_lambda_powertools.event_handler.exceptions import (
BadRequestError,
UnauthorizedError,
)
from aws_lambda_powertools.utilities.data_classes import LambdaFunctionUrlEvent
@dceoy
dceoy / execution_time_logger.py
Last active April 23, 2025 15:36
[Python] Execution time logger
#!/usr/bin/env python
import logging
import time
from functools import wraps
from typing import Any, Callable
def log_execution_time(func: Callable[..., Any]) -> Callable[..., Any]:
@wraps(func)
@dceoy
dceoy / aws_sts_assume_role.py
Last active July 19, 2024 15:53
[Python] Assume an AWS IAM role and make a session with the role
#!/usr/bin/env python
import logging
from typing import Optional
import boto3
from pydantic import BaseModel, model_validator
from typing_extensions import Self
@dceoy
dceoy / press_esc_repeatedly.py
Created May 22, 2023 06:49
[Python] Press a key using PyAutoGUI
#!/usr/bin/env python
import signal
import time
import pyautogui
def press_esc_repeatedly(waiting_sec=300, pressed_key='esc'):
signal.signal(signal.SIGINT, signal.SIG_DFL)
@dceoy
dceoy / extract_lowercase_regions_from_fasta.py
Last active May 19, 2020 17:28
[Python] Extract lowercase regions in a FASTA file and write them into a BED file
#!/usr/bin/env python
import argparse
import bz2
import gzip
import logging
import os
from pathlib import Path
from pprint import pformat
@dceoy
dceoy / read_fasta.py
Created July 10, 2019 04:31
[Python] Read a FASTA file using Biopython
#!/usr/bin/env python
import bz2
import gzip
from Bio import SeqIO
def read_fasta(path):
if path.endswith('.gz'):
@dceoy
dceoy / git_rewind_days.sh
Created June 3, 2019 18:32
[Shell] Rewind days at the latest commit of Git logs
#!/usr/bin/env bash
#
# Usage: ./git_rewind_days.sh <int>
set -eux
DAYS_TO_REWIND="${1}"
COMMIT_DATE=$(git log -1 | sed -ne 's/^Date: \+//p')
REWIDED_DATE=$(date -d "${COMMIT_DATE% *} - ${DAYS_TO_REWIND} days" | awk '{print $1" "$2" "$3" "$4" "$6}')" ${COMMIT_DATE##* }"
@dceoy
dceoy / install_rbenv.sh
Last active May 7, 2019 10:11
[Shell] Install the latest version of Ruby with rbenv
#!/usr/bin/env bash
#
# https://github.com/dceoy/ansible-dev/blob/master/roles/ruby/files/install_rbenv.sh
set -uex
RBENV_DIR="${HOME}/.rbenv"
RB_BUILD_DIR="${HOME}/.rbenv/plugins/ruby-build"
RBENV="${RBENV_DIR}/bin/rbenv"
[[ ${#} -ge 1 ]] && RB_MAJOR_VER="${1}" || RB_MAJOR_VER=2