Skip to content

Instantly share code, notes, and snippets.

View vwrs's full-sized avatar
🏠
Working from home

Hideaki Kanehara vwrs

🏠
Working from home
View GitHub Profile
@vwrs
vwrs / slack-theme-material-dark
Created September 24, 2018 17:40
Slack Custom Sidebar Theme
#303E4D,#60a8cc,#0f658a,#64fcda,#546e7a,#eceff1,#40c4ff,#ff5252
@vwrs
vwrs / counter-plot.py
Last active November 25, 2018 05:52
matplotlib utils
import matplotlib.pyplot as plt
import seaborn as sns
from collections import Counter
def counter_plot(values, max_count=len(set(values)),
figsize=(17,5), dpi=80,
fontsize=12, rotation=90,
xoffset=.05, yoffset=.1):
c = Counter(values)
l, v = zip(*c.most_common(max_count))
@vwrs
vwrs / proxy.pac
Last active November 27, 2018 08:49
Socks Proxy
function FindProxyForURL(url, host) {
return "SOCKS localhost:10080";
}
@vwrs
vwrs / ec2-stop-instance.sh
Last active February 22, 2019 08:11
Stop an AWS EC2 instance
#!/bin/bash -eu
DEFAULT_REGION=ap-northeast-1
INSTANCE_ID=`curl -fsSL http://169.254.169.254/latest/meta-data/instance-id/`
if [ $? = 0 ]; then
echo "instance-id:["$INSTANCE_ID"]"
else
echo "An unexpected error occurred when trying to get instance-id."
exit 1
fi
import sys
import os
import dotenv
from slackclient import SlackClient
dotenv.load_dotenv('/path/to/.env')
def post_slack(text: str, channel: str):
slack_token = os.environ['SLACK_API_TOKEN']
# -*- coding: utf-8 -*-
import logging
import sys
from nvdloader import NVDLoader
def main():
argv = sys.argv
if len(argv) != 2 or argv[1] not in ['2', '3']:
print('Usage: $ python %s 2|3 (CVSS ver.)' % argv[0])
import os
PATH_DIR = '/path/to/dir'
if not os.path.exists(PATH_DIR):
print('mkdir', PATH_DIR)
os.mkdir(PATH_DIR)
@vwrs
vwrs / show-progress.py
Created June 8, 2019 15:20
print utility for checking training progress in command line
import sys
def show_progress(e, i, t, l, v):
'''
Prints the training progress recursively.
Args:
e (int): the current epoch
i (int): the current batch
t (int): the total batches
@vwrs
vwrs / curl-post.sh
Created June 25, 2019 07:09
Send POST request by cURL
# use --trace-ascii to show the payload
curl -i -d 'key=value' [-v] [--trace-ascii /dev/stdout] https://example.com/
@vwrs
vwrs / apiview-swagger-example.py
Last active June 25, 2019 10:01
Simple Django's class-based View implementation with Swagger support using rest_framework and drf_yasg
from rest_framework.views import APIView
from rest_framework.decorators import parser_classes
from rest_framework.parsers import FormParser
from django.http import JsonResponse
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
class TestView(APIView):
'''Test API