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 / 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 / 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 / receiver.sh
Last active August 29, 2015 13:56
straceコマンドでSIGPIPEの発生を確認する
#!/bin/sh
sleep 1
cat
@doi-t
doi-t / awk_rand.bash
Created June 18, 2014 03:21
awkで乱数生成
#!/bin/bash
echo "---> sleep 0"
for loop in `seq 10`; do awk 'BEGIN{ srand(); print rand() }'; done
echo "---> sleep 0.5"
for loop in `seq 10`; do awk 'BEGIN{ srand(); print rand() }'; sleep 0.5; done
echo "---> sleep 1.0"
for loop in `seq 10`; do awk 'BEGIN{ srand(); print rand() }'; sleep 1.0; done
echo "---> srand(\$RANDOM)"
for loop in `seq 10`; do awk 'BEGIN{ srand('"$RANDOM"'); print rand() }'; done
@doi-t
doi-t / test_double_dig.c
Created June 21, 2014 07:19
0.1 + 0.1 + 0.1 == 0.3 ?
#include <stdio.h>
int
main(void)
{
double answer = 0.1 + 0.1 + 0.1;
if(answer == 0.3){
printf("True:%.100f\n", answer);
} else {
@doi-t
doi-t / mk_bulk_insert.bash
Created July 16, 2014 06:07
単純なinsertの繰り返しと、バルクインサートのDDLを生成するスクリプト
#!/bin/bash
if [ $# -ne 2 ]; then
echo "$0 [the number of insert] [output file]"
exit 1
fi
nmemb_insert=$1
ddlfile=$2
cat <<- EOF > $ddlfile
@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 / 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 *, ...);