Skip to content

Instantly share code, notes, and snippets.

View evalphobia's full-sized avatar

evalphobia

View GitHub Profile
@evalphobia
evalphobia / main_test.go
Created January 18, 2016 10:22
テストコード01
package main
import (
"bytes"
"io"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@evalphobia
evalphobia / main_test.go
Last active January 18, 2016 10:51
テストコード02
package main
import (
"bytes"
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
)

6 Concurrency 並行処理

  • ゴルーチンを使ったコード
  • レースコンディションの検知と修正
  • チャネルによるデータ共有

・スケジューラーがどのゴルーチンがどのプロセッサで動いているか管理している
・CSP message passing model(共有データをロックするのではなくチャネルでの受け渡し)

@evalphobia
evalphobia / nginx_cachet.conf
Created February 23, 2016 12:02
nginx config
# https://cachethq.io/
upstream _cachet {
# docker's ip and port
server 127.0.0.1:8001;
}
server {
listen 80;
server_name cachet.example.com;

9 Testing and benchmarking テストとベンチマーク

この章で学ぶこと

  • ちゃんと単体テストを書こう
  • httptestを使えばHTTPリクエストをモックできるよ
  • サンプルコードをつけてドキュメントを書こう
  • ベンチマークしてパフォーマンスを測定しよう

開発が終わるまでテストコードを待つ必要はない。開発のプロセスに組み込むことが出来る

@evalphobia
evalphobia / The Three Go Landmines.ja.markdown
Last active July 27, 2022 10:48 — forked from lavalamp/The Three Go Landmines.markdown
Go言語の地雷(原題: Golang landmines)

Goでよくやってしまうミスが3つあります。
私はそのミスを、分かりやすいように簡略した書き方ではなく、巷でよく見かける書き方のままここで説明します。
3つのミスの全てが、私の知る限り少なくとも1回づつ、Kubernetesの過去のコードレビューにありました。

1: ループ変数がループ外のスコープになっている

この各行はいったい何を行っているのでしょうか。想像してから下へスクロールしてください。

Ootahveali0weiChoo9eixir
@evalphobia
evalphobia / README.md
Last active February 22, 2024 18:28
Golang Benchmark: gob vs json

tl;dr

  • JSON is faster for small size data
    • map (key size < 50 and Unmarshalling intensive workload)
    • single struct
  • gob is faster for big size data
    • map (key size > 50 or Marshalling intensive workload)
    • slice

(old) about

@evalphobia
evalphobia / ssh_notify_to_slack.sh
Created October 24, 2016 03:07
Send Slack to SSH login alert
#!/bin/sh
# original from http://sandrinodimattia.net/posting-successful-ssh-logins-to-slack/
if [ "$PAM_TYPE" != "close_session" ]; then
whitelist="127.0.0.1 localhost" # change here
is_white=0
# check authorized host
for HOST in $whitelist
@evalphobia
evalphobia / ptquery_mail_qiita.rb
Last active November 1, 2017 20:06
RDS(MySQL) log analyzer using pt-query-digest and https://github.com/wvanbergen/request-log-analyzer
#!/usr/bin/env ruby
require "qiita"
require "slack-notifier"
require "aws-sdk"
require 'yaml'
require 'json'
class RDSLogDownloader