Instantly share code, notes, and snippets.

:octocat:
so sleepy...

michimani michimani

View GitHub Profile
@michimani
michimani / textbox-overlay-by-whitespace.html
Created Feb 6, 2019
Add overlay to a word separated by whitespace inputted at a textbox.
View textbox-overlay-by-whitespace.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Textbox Overlay Style by White Space</title>
<style type="text/css">
#overlay-sample {
margin: 30px;
font-family: inherit;
}
@michimani
michimani / sns_to_slack.py
Created Dec 20, 2018
Notify CloudWatch Alarm to Slack via SNS.
View sns_to_slack.py
import boto3
import json
import logging
import os
from base64 import b64decode
from urllib.error import URLError, HTTPError
from urllib.request import Request, urlopen
SLACK_CHANNEL = os.environ['slackChannel']
@michimani
michimani / auto_start_stop_ec2.py
Last active Dec 14, 2018
Automatically start / stop the EC2 instances that have tag name "AutoStartStop" and value "TRUE".
View auto_start_stop_ec2.py
import json
import boto3
import traceback
def lambda_handler(event, context):
try:
region = event['Region']
action = event['Action']
client = boto3.client('ec2', region)
responce = client.describe_instances(Filters=[{'Name': 'tag:AutoStartStop', "Values": ['TRUE']}])
@michimani
michimani / put-process-status.sh
Created May 23, 2018
Put linux process status to Amazon CloudWatch.
View put-process-status.sh
###################################################################################
# check process aliving (count process number)
# return integer 1 (process is running) or 0 (process is dead) or 9 (some error)
###################################################################################
function is_process_alive() {
count=`ps awux | grep -v grep | grep -v "$0" | grep -w "$1" | wc -l`
if [[ $count =~ ^[0-9]+$ ]]; then
if [ $count != 0 ]; then
echo 1
else
@michimani
michimani / .bash_profile
Created Mar 2, 2018
Coloring text and displaying git branch for bash prompt
View .bash_profile
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/'
}
function promps {
local BLUE="\[\e[34m\]"
local RED="\[\e[31m\]"
local GREEN="\[\e[32m\]"
local WHITE="\[\e[00m\]"
local GRAY="\[\e[37m\]"
local MAGENTA="\[\e[35m\]"
@michimani
michimani / rand_cowsay.php
Last active Mar 2, 2018
Run "cowsay -f" command randomly on PHP.
View rand_cowsay.php
<?php
if (count($argv) < 2)
{
echo 'parameter not enough.'."\n";
return false;
}
exec('which cowsay 2>&1', $cmd_t);
if (!isset($cmd_t[0]) || $cmd_t[0] == '')
@michimani
michimani / set_bg_color.php
Last active Mar 2, 2018
Fill the transparent part of transparent PNG with a solid color.
View set_bg_color.php
<?php
$fpath = $argv[1];
$o = new Bg();
$o->setBgColor($fpath);
class Bg
{
@michimani
michimani / change_default_icon.js
Last active Mar 2, 2018
Replace the icon image of Hatena blog with another image.
View change_default_icon.js
var icon = 'https://path-to-icon';
var hatenaid = 'michimani';
var toc = 200;
var tos = 900;
var p = document.getElementsByClassName('profile-icon');
for (var n = 0; n < p.length; n++){
p[n].src = icon;
}
window.onload = function(){
setTimeout(function(){
@michimani
michimani / hatena_sp_comment.css
Last active Dec 28, 2017
comment area style for Hatena Blog on mobile page.
View hatena_sp_comment.css
.entry-comment {
border: solid 3px #000;
border-radius: 10px;
margin: 20px 0px 10px 0px;
padding: 10px 10px 5px 10px;
}
p.comment-user-name {
z-index: 999;
margin-top:-30px;
@michimani
michimani / MoveToHeader.js
Last active Mar 2, 2018
Smooth movement from the table of contents in the Hatena blog article to the heading using jQuery.
View MoveToHeader.js
$(document).ready(function(){
// 見出しタグにclass追加
$(".entry-content h1").addClass("content-h");
$(".entry-content h2").addClass("content-h");
$(".entry-content h3").addClass("content-h");
$(".entry-content h4").addClass("content-h");
$(".entry-content h5").addClass("content-h");
// 「目次」表示