Skip to content

Instantly share code, notes, and snippets.

View KentaYamada's full-sized avatar
🏠
Working from home

yamaken KentaYamada

🏠
Working from home
View GitHub Profile
@KentaYamada
KentaYamada / hoge.py
Last active September 10, 2016 13:52
ソースコード、テストコード、テストデータを分離
# -*-coding: utf-8 -*-
def add(x, y):
return x + y
@KentaYamada
KentaYamada / Makefile
Last active September 3, 2016 04:46
ユニットテストかそうでないかでアクセシビリティを切り替える
CXX=g++
CFLAGS=-Wall -O2
main: main.o hoge.o
$(CXX) $(CFLAGS) main.o hoge.o -o main
test: test_main.o hoge.o
$(CXX) $(CFLAGS) test_main.o hoge.o -o test
test_main.o: test_main.cpp hoge.h
@KentaYamada
KentaYamada / doctest-sample.py
Created August 11, 2016 08:38
今さらdoctest使ってみた
# -*-coding: utf-8 -*-
def hoge(n):
return n * 2
def piyo():
return "Hello."
@KentaYamada
KentaYamada / ofstream_sample.cpp
Created August 3, 2016 11:24
ofsstreamのサンプルコード
#include <iostream>
#include <string>
#include <fstream>
int main()
{
std::string data = "hoge, piyo, fuga";
std::ofstream ofs;
@KentaYamada
KentaYamada / pointers.c
Created July 18, 2016 09:33
ポインタの使い方いろいろ
#include <stdio.h>
static void func(const int *val);
static void func2(const char *val);
static void func3(const char val[]);
static void func4(int *val);
static void func5(const char *val);
int main(void)
@KentaYamada
KentaYamada / vim-clangver.vim
Last active June 29, 2016 12:02
vim-clangでclangのバージョンを確認する
function init_clang_conf()
for i in [6, 5, 4]
if executable("clang-3.".i) && executable("clang-format-3.".i)
let g:clang_exec = "clang-3.".i
let g:clang_format_exec = "clang-format-3.".i
return
endif
endfor
let g:clang_exec = "clang"
@KentaYamada
KentaYamada / fcc.cpp
Created June 27, 2016 15:05
パリティチェック?
#include <stdlib.h>
#include <iostream>
#include <string>
#include <sstream>
bool CheckFCC(std::string &buf, int start, size_t byte_count)
{
char fcc = buf[byte_count + 4];
char calc_fcc;
@KentaYamada
KentaYamada / vacuum.py
Last active June 10, 2016 00:29
Vacuum sqlite3 db file
# -*- coding: utf-8 -*-
import sqlite3
def vaccum(db_name):
with sqlite3.connect(db_name) as db:
try:
db.execute("VACUUM")
except:
raise IOError("Vacuum failed.")
@KentaYamada
KentaYamada / pysqlite3.py
Last active June 4, 2016 05:44
一度読み込んだSQLファイルをメモ化を使ってキャッシング
import sqlite3
queries = {}
def test1():
sql = ""
with open("./test.sql") as f:
sql = f.read()
with sqlite3.connect("./test.db") as db:
cursor = db.cursor()
cursor.execute(sql)
@KentaYamada
KentaYamada / sample_unittest.py
Created May 21, 2016 13:41
PythonでUnitTest
#coding -*- utf-8 -*-
import unittest
def add(x, y):
return x + y
class SampleUnitTest(unittest.TestCase):
#テストメソッドは先頭に必ず「test」と書く