Skip to content

Instantly share code, notes, and snippets.

View tksugimoto's full-sized avatar

Takashi Sugimoto tksugimoto

View GitHub Profile
@tksugimoto
tksugimoto / option.scala
Last active June 8, 2017 10:31
Scala Option snippet
val someValue: Option[Int] = Some(123)
val noneValue: Option[Int] = None
val doubledSomeValue: Option[Int] = someValue.map(_ * 2) // Some(246)
val doubledNoneValue: Option[Int] = noneValue.map(_ * 2) // None
// mapで型の変更も可能
val stringifySomeValue: Option[String] = someValue.map(_.toString + "__") // Some("123__")
val stringifyNoneValue: Option[String] = noneValue.map(_.toString + "__") // None
@tksugimoto
tksugimoto / either.scala
Last active June 11, 2017 10:37
Scala Either snippet
// Either: LeftとRightのどちらかを取りうるもの(OptionはSome(x)とNoneのどちらかを取りうるもの)
// 嬉しさ:OptionはSome(x), Noneだったが、EitherはRight(x), Left(y)になり、None相当のときに情報を持てる(エラー情報を持つことが多い)
// Scala 2.11
case class User(id: Int)
def findUserById(id: Int): Either[String, User] = {
id match {
case 2 => Left("存在しない")
case 5 => Left("バンされた")
@tksugimoto
tksugimoto / fetch.js
Created June 10, 2017 03:21
JavaScript fetch APIを書き換えて通信内容を変更する
(() => {
const isTarget = response => response.url.startsWith("http://example.com/path");
const changeJson = json => {
// jsonを書き変える
return json;
};
const originalFetch = window.fetch;
window.fetch = (...args) => {
@tksugimoto
tksugimoto / progress.js
Last active August 12, 2017 13:15
プログレス表示
const readline = require('readline');
console.log('start');
Array.from(Array(100), (_, i) => i + 1).forEach(i => {
setTimeout(() => {
/*
// ※ メッセージの長さが減少する場合は使えない
process.stdout.write(`working... ${i}%\r`);
/*/
@tksugimoto
tksugimoto / docker-stats.sh
Last active September 29, 2017 01:20
docker
# docker コンテナのリソース使用状況を表示
docker stats \
--all \
--format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}"
@tksugimoto
tksugimoto / curator-configuration.yml
Created October 15, 2017 15:46
elasticsearch-curator
client:
hosts:
- localhost
port: 9200
@tksugimoto
tksugimoto / docker-compose.yml
Created October 16, 2017 13:44
docker-volume-nest
version: '2'
services:
aaaa:
image: bbbb
volumes:
- ./.cccc:/cccc/
- ./dddd.conf:/cccc/dddd.conf
@tksugimoto
tksugimoto / connect-vpn-and-log.bat
Created November 2, 2017 02:24
docker-vpn-http-proxy
@echo off
docker-compose exec vpn sh -c "tail -f /var/log/squid/access.log & tail -f /etc/vpn-config/openvpn.log & openvpn /etc/vpn-config/*.ovpn"
#!/bin/bash
host=$(hostname --short)
catbon_host=localhost
catbon_port=2003
echo "send metric of '$host' to $catbon_host:$catbon_port"
javascript: (() => {
const query = Object.entries({
/* 元の言語 */
sl: 'en',
/* 翻訳する言語 */
tl: 'ja',
u: document.URL,
/* 原文を表示する */
anno: 2,
}).map(([key, value]) => {