Skip to content

Instantly share code, notes, and snippets.

View doi-t's full-sized avatar
🧗‍♂️
Be open-minded

Toshiya Doi doi-t

🧗‍♂️
Be open-minded
View GitHub Profile
@doi-t
doi-t / awk_avg.bash
Last active December 29, 2015 10:59
awkで算出した平均等をgnuplotでグラフ化する
#!/bin/bash
#log format:[log_msg time]
calc_avg(){
awk 'BEGIN{ OFS="\t"; sum=0; max=0; }
NR==1 { min=$2; }
{ sum+=$2; if($2>max){max=$2}; if(min>$2){min=$2}; }
END{ print($1, sum, NR, max, min, sum/NR) }'
}
@doi-t
doi-t / calc_avg.awk
Created November 26, 2013 16:21
awkで合計、回数、最大、最小、平均を算出する
awk 'BEGIN{ OFS="\t"; sum=0; max=0; }
NR==1 { min=$2; }
{ sum+=$2; if($2>max){max=$2}; if(min>$2){min=$2}; }
END{ print($1, sum, NR, max, min, sum/NR) }'
@doi-t
doi-t / setting_default_value.bash
Last active April 2, 2023 11:35
シェル変数のデフォルト値を設定する
#!/bin/bash
foo=${1:-hoge}
echo $foo #$1がなかったらhogeをデフォルト値としてfooに代入する
#var自身にデフォルト値としてhogeを代入としたいので以下のように書きたい
${var:=hoge} #このままでは、hogeが展開されてしまって、hogeなんてコマンドはないとシェル怒られる
echo "1:$var"
var=
@doi-t
doi-t / err_msg.c
Created December 9, 2013 16:41
エラーメッセージ関数のサンプル
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <unistd.h>
#define ERROR(fmt, ...) err_msg(__FILE__, __FUNCTION__, __LINE__, "error", fmt, ##__VA_ARGS__)
#define WARNNING(fmt, ...) err_msg(__FILE__, __FUNCTION__, __LINE__, "warnning", fmt, ##__VA_ARGS__)
@doi-t
doi-t / wrapsend.c
Created January 17, 2014 16:19
send(2)のラッパー関数とマクロ定義
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
void err_msg(const char *, const char *, int, const char *, const char *, ...);
@doi-t
doi-t / Makefile
Created January 20, 2014 16:31
makeでライブラリ(.a)のビルドを管理するサンプル(gcc.ver)
CC := gcc
RM := rm -f
CFLAGS = -Wall
programs := run
.PHONY: all
all: $(programs)
$(programs): libhello.a
@doi-t
doi-t / Makefile
Last active August 29, 2015 13:55
makeでライブラリ(.a)のビルドを管理するサンプル(g++.ver)
RM := rm -f
CXXFLAGS := -Wall
programs := run
.PHONY: all
all: $(programs)
$(programs): libhello.a
@doi-t
doi-t / Makefile
Created January 29, 2014 20:11
makeでライブラリ(.a)のビルドを管理するサンプル(gccとg++の混在ver)
CC := gcc
RM := rm -f
CFLAGS := -Wall
CXXFLAGS := -Wall
programs := run
.PHONY: all
all: $(programs)
@doi-t
doi-t / gtest_install
Created February 4, 2014 18:49
gtestを/usr/local以下にインストール/アンインストールするシェルスクリプト
#!/bin/bash
version=gtest-1.7.0
root=/usr/local
sudo apt-get install cmake
wget https://googletest.googlecode.com/files/$version.zip -P ~
(cd ~; unzip ${version}.zip;)
@doi-t
doi-t / Makefile
Last active February 3, 2022 05:22
GNU Make 第3版、第6章の非再帰makeのサンプルコードに対するメモ
### 非再帰的make(non-recursive make)
# ソースファイルツリーが常に整頓されている前提
# 使っていないソースファイルが紛れ込まないようにしなければならない、その辺はGitで管理する
# 内容的には "GNU Make 第3版、6章 大きなプロジェクトの管理" に載っているコードとほぼ同じ
#
### 参考
#論文: "Recursive Make Considered Harmful"
#http://miller.emu.id.au/pmiller/books/rmch/
#実際にnon-recursive makeを適用しているOSSプロダクト(OpenRADIUS)のMakefile解説(上記論文のサイトにもリンクが貼られている)
#http://evbergen.home.xs4all.nl/nonrecursive-make.html