Skip to content

Instantly share code, notes, and snippets.

View eerien's full-sized avatar

Changhwan Song eerien

View GitHub Profile
@eerien
eerien / pstack
Created April 16, 2013 02:16
Print multi thread process backtrace.
#!/bin/sh
if test $# -ne 1; then
echo "Usage: `basename $0 .sh` <process-id>" 1>&2
exit 1
fi
if test ! -r /proc/$1; then
echo "Process $1 not found." 1>&2
exit 1
@eerien
eerien / insert_bulk_data.sql
Created May 14, 2013 02:22
INSERT bulk data procedure.
DECLARE
BEGIN
FOR i IN 1..100000 LOOP
INSERT INTO T1 VALUES (i);
END LOOP;
COMMIT;
END;
/
@eerien
eerien / forms.py
Last active May 12, 2024 11:20
Comma Separated Values Form Field for Django. There are CommaSeparatedCharField, CommaSeparatedIntegerField.
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
class MinLengthValidator(validators.MinLengthValidator):
message = 'Ensure this value has at least %(limit_value)d elements (it has %(show_value)d).'
class MaxLengthValidator(validators.MaxLengthValidator):
message = 'Ensure this value has at most %(limit_value)d elements (it has %(show_value)d).'
@eerien
eerien / aws_region.sh
Created January 28, 2014 07:10
Code snippet to recognize or determine region placed itself by using 169.254.169.254 on AWS.
AZ=`curl http://169.254.169.254/2012-01-12/meta-data/placement/availability-zone 2> /dev/null`
if [[ $AZ =~ 'us-east-1' ]]; then # N. Virginia
elif [[ $AZ =~ 'us-west-2' ]]; then # Oregon
elif [[ $AZ =~ 'us-west-1' ]]; then # N. California
elif [[ $AZ =~ 'eu-west-1' ]]; then # Ireland
elif [[ $AZ =~ 'ap-southeast-1' ]]; then # Singapore
elif [[ $AZ =~ 'ap-northeast-1' ]]; then # Tokyo
elif [[ $AZ =~ 'ap-southeast-2' ]]; then # Sydney
elif [[ $AZ =~ 'sa-east-1' ]]; then # Sao Paulo
else # Others
@eerien
eerien / aws_rss_feeds.xml
Last active March 6, 2020 06:57
AWS RSS Feeds OPML includes AWS Status, AWS Forum Announcements, AWS Blogs, AWS Partners, AWS News, AWS Release Notes and AWS Security Bulletins
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>AWS RSS Feeds</title>
</head>
<body>
<outline title="AWS Status" text="AWS Status">
<outline text="Amazon Mobile Analytics (N. Virginia) Service Status" title="Amazon Mobile Analytics (N. Virginia) Service Status" type="rss" xmlUrl="http://status.aws.amazon.com/rss/analytics-us-east-1.rss" htmlUrl="http://status.aws.amazon.com/" rssfr-favicon="http://status.aws.amazon.com/favicon.ico"/>
<outline text="Amazon AppStream (N. Virginia) Service Status" title="Amazon AppStream (N. Virginia) Service Status" type="rss" xmlUrl="http://status.aws.amazon.com/rss/appstream-us-east-1.rss" htmlUrl="http://status.aws.amazon.com/" rssfr-favicon="http://status.aws.amazon.com/favicon.ico"/>
<outline text="Auto Scaling (Tokyo) Service Status" title="Auto Scaling (Tokyo) Service Status" type="rss" xmlUrl="http://status.aws.amazon.com/rss/autoscaling-ap-northeast-1.rss" htmlUrl="http://status.a
@eerien
eerien / cloudwatch.sh
Last active August 29, 2015 14:05
Zabbix externalscript for CloudWatch on AWS (Amazon Web Services). It returns latest statistic value.
#!/bin/bash
# $1: Region
# $2: Namespace
# $3: Dimensions
# $4: Metric Name
# $5: Start Time (before n min)
# $6: Period (min)
# $7: Statistics (SampleCount, Average, Sum, Minimum, Maximum)
# $8: Output value when the result is null
@eerien
eerien / aws-autoscaling-set-desired-capacity.sh
Created September 2, 2014 03:42
AWS (Amazon Web Services) AutoScaling: set-desired-capacity script
#!/bin/bash
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
/usr/local/bin/aws autoscaling set-desired-capacity --region "$1" --auto-scaling-group-name "$2" --desired-capacity "$3" --no-honor-cooldown
@eerien
eerien / mysql_ping.sh
Created September 2, 2014 03:42
MySQL Ping script
#!/bin/bash
mysqladmin -h$1 -u$2 -p$3 ping | grep -c alive
@eerien
eerien / mysql_status.sh
Created September 2, 2014 03:43
A script to get any status variable value
#!/bin/bash
echo "show global status where Variable_name='$4';" | mysql -h$1 -u$2 -p$3 -N | awk '{print $2}'
@eerien
eerien / shaco.py
Last active January 4, 2022 18:23
Zabbix screen reporting script by using Selenium. It send email includes screenshot of pre-defined Zabbix screen. You can use this for periodical statistics report with Cron.
#!/usr/bin/python
#-*- coding: utf-8 -*-
# Install
# apt-get install xvfb python-imaging (firefox or chromium-chromedriver)
# pip install selenium pyvirtualdisplay boto
import sys
import os
import socket