This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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("バンされた") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const isTarget = response => response.url.startsWith("http://example.com/path"); | |
const changeJson = json => { | |
// jsonを書き変える | |
return json; | |
}; | |
const originalFetch = window.fetch; | |
window.fetch = (...args) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require('readline'); | |
console.log('start'); | |
Array.from(Array(100), (_, i) => i + 1).forEach(i => { | |
setTimeout(() => { | |
/* | |
// ※ メッセージの長さが減少する場合は使えない | |
process.stdout.write(`working... ${i}%\r`); | |
/*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# docker コンテナのリソース使用状況を表示 | |
docker stats \ | |
--all \ | |
--format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t{{.BlockIO}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client: | |
hosts: | |
- localhost | |
port: 9200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
aaaa: | |
image: bbbb | |
volumes: | |
- ./.cccc:/cccc/ | |
- ./dddd.conf:/cccc/dddd.conf | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
host=$(hostname --short) | |
catbon_host=localhost | |
catbon_port=2003 | |
echo "send metric of '$host' to $catbon_host:$catbon_port" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (() => { | |
const query = Object.entries({ | |
/* 元の言語 */ | |
sl: 'en', | |
/* 翻訳する言語 */ | |
tl: 'ja', | |
u: document.URL, | |
/* 原文を表示する */ | |
anno: 2, | |
}).map(([key, value]) => { |
OlderNewer