Skip to content

Instantly share code, notes, and snippets.

View TearTheSky's full-sized avatar

TearTheSky (Masumi Yoshida) TearTheSky

View GitHub Profile
@TearTheSky
TearTheSky / aws_waf_launch_some_http_method_restriction.yaml
Last active December 7, 2018 11:50
aws_waf_launch_some_http_method_restriction.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
# このテンプレート実行時に実行者に入力させる内容の定義
Parameters:
yourApplicationeName:
Description: use your Application Name as WAF ACL and Rules name prefix.
Type: String
Default: sampleApplication
#! /usr/bin/env python3
# coding: utf-8
import sys
import boto3
import botocore
import json
from boto3.session import Session
from botocore.exceptions import ClientError
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# before
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
response = aws_client.describe_db_instances(
DBInstanceIdentifier = target_rds_instance_name,
)
if response['DBInstances'][0]['MultiAZ'] == True :
response2 = aws_client.reboot_db_instance(
@TearTheSky
TearTheSky / sqlfile_read_and_execute_sample.py
Last active January 13, 2021 14:58
PostgreSQLのDBに対して引数で与えたSQLファイルの内容を実行するPythonサンプル
#!/usr/bin/python
# coding: utf-8
import sys
import psycopg2
def execute_sql_from_file(sqlfile):
try:
cnn = psycopg2.connect("dbname=my_db host=my_db_endpoint user=postgres password=my_password")
cur = cnn.cursor()
@TearTheSky
TearTheSky / logging_as_ltsv.py
Created February 27, 2016 02:56
Pythonで、LTSV形式でログを出力するサンプル。
import logging
import datetime
logging.basicConfig(level=logging.DEBUG,
format="time:%(asctime)s \tseverity:[%(levelname)s] \tmessage:%(message)s ", filename='myapp.log')
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
@TearTheSky
TearTheSky / setDisableKillByOOMKiller.sh
Created January 20, 2016 00:46
OOM Killer にプロセスがKillされて困ってましたがいちいちPIDを探すのがめんどくさいため書いてみました。
#!/bin/bash
targetProcessWord="key-word-for-search-a-process-with-ps-command"
executionUserName="ex.root"
processSearchCommand="ps aux | grep "${targetProcessWord}" | awk '{if(\$1==\""${executionUserName}"\"){print \$2 }}' | head -n 1"
targetProcessID=`eval $processSearchCommand`
echo "${targetProcessWord} のOOM優先度は `cat /proc/${targetProcessID}/oom_adj` です。"
sudo -i echo -17 > /proc/${targetProcessID}/oom_adj
echo "${targetProcessWord} のOOM優先度を `cat /proc/${targetProcessID}/oom_adj` に変更しました。"
<!-- HTML内埋め込み -->
<style type="text/css">
<!--
#menu li {
position: relative;
float: left;
margin: 0;
padding: 5px;
width: 200px;
#引数定義
Param (
[string]$pathName = "",
[int]$targetSheetNumber = -1,
[string]$targetCollumn = "",
[int]$targetRow = -1
)
#******************************************************************************
@TearTheSky
TearTheSky / BlackBoard.StorableColorTheme.ps1xml
Created May 7, 2014 06:08
個人用PowerShell_ISEのテーマ(カラースキーマ)
<?xml version="1.0" encoding="utf-16"?>
<StorableColorTheme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Keys>
<string>ErrorForegroundColor</string>
<string>ErrorBackgroundColor</string>
<string>WarningForegroundColor</string>
<string>WarningBackgroundColor</string>
<string>VerboseForegroundColor</string>
<string>VerboseBackgroundColor</string>
<string>DebugForegroundColor</string>
# トランスクリプト(ログ出力)の開始
$yourLogfilePrefix = 'ログファイルにつけたい名前'
try {
Stop-Transcript
}
catch{
Write-Output '既に実行されているトランスクリプトはありません。問題ありません。'
}
Start-Transcript -Path ( (split-path $MyInvocation.MyCommand.Path) + "\" + $yourLogfilePrefix + $tennant + "_" +(get-date -Format "yyyyMMddhhmmss") + ".log")