Skip to content

Instantly share code, notes, and snippets.

View komasaru's full-sized avatar

mk-mode komasaru

View GitHub Profile
@komasaru
komasaru / simplex.f95
Last active October 27, 2024 01:19
Fortran 95 source code to solve a linear programming by simplex method.
!****************************************************
! 線形計画法(シンプレックス法)
!
! * 入力はテキストファイルをパイプ処理
! 1行目: 行数 列数 変数の数
! 2行目以降: 1行に列数分の係数 * 行数
!
! date name version
! 2018.12.05 mk-mode.com 1.00 新規作成
!
@komasaru
komasaru / Mysql.cpp
Created August 17, 2014 05:54
C++ source code to connect to MariaDB(MySQL).
/*
* Example to connect to MariaDB(MySQL)
*/
#include <iostream>
#include <mysql/mysql.h> // require libmysqlclient-dev
#include <string>
using namespace std;
/*
@komasaru
komasaru / binom_coeff.rb
Created October 19, 2019 07:42
Ruby script to calculate binomial coefficients.
#*********************************************
# 二項係数計算モジュール
#
# DATE AUTHOR VERSION
# 2019.10.19 mk-mode.com 1.00 新規作成
#
# Copyright(C) 2019 mk-mode.com All Rights Reserved.
#*********************************************
module BinomCoeff
# 二項係数の計算(1)
@komasaru
komasaru / calc_rcc_kendall.f95
Last active June 22, 2024 01:10
Fortran 95 source code to calculate a Kendall's Rank Correlation Coefficient.
!****************************************************
! ケンドールの順位相関係数の計算
!
! DATE AUTHOR VERSION
! 2019.12.13 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2019 mk-mode.com All Rights Reserved.
!****************************************************
!
module cst
@komasaru
komasaru / calc_rcc_spearman.rb
Last active June 22, 2024 01:09
Ruby script to calculate a Kendall's Rank Correlation Coefficient.
#! /usr/local/bin/ruby
class Array
def rcc_kendall(y)
# 以下の場合は例外スロー
# - 引数の配列が Array クラスでない
# - 自身配列が空
# - 配列サイズが異なる
# - 数値以外のデータが存在する
raise "Argument is not a Array class!" unless y.class == Array
@komasaru
komasaru / calc.cpp
Last active June 22, 2024 01:08
C++ source code to calculate a Kendall's Rank Correlation Coefficient.
#include "calc.hpp"
#include <algorithm> // for std::count
#include <cmath> // for std::sqrt
#include <iostream>
#include <unordered_map>
#include <vector>
Calc::Calc(std::vector<std::vector<double>>& data) {
try {
@komasaru
komasaru / prime_numbers.f95
Created April 20, 2017 05:04
Fortran code to compute prime numbers.
!****************************************************
! 素数一覧
! : 入力値以下の素数を全て出力する
!
! date name version
! 2017.04.20 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2017 mk-mode.com All Rights Reserved.
!****************************************************
!
@komasaru
komasaru / chudnovsky.cpp
Last active April 21, 2024 09:10
C++ source code to compute pi with Chudnovsky formula and Binary Splitting Algorithm using GMP libarary.
/***************************************************************
* Computing pi by Binary Splitting Algorithm with GMP libarary.
**************************************************************/
#include <cmath>
#include <iostream>
#include <fstream>
#include <gmpxx.h>
using namespace std;
@komasaru
komasaru / test_bash_cursor_1.sh
Created December 14, 2014 08:36
Bash script to control cursor position.(Ex.1)
#!/bin/bash
# 1. 指定文字数左へ移動後に echo
# ( 最後の echo 以外は改行しない )
#
echo -n `date +"%Y-%m-%d %H:%M:%S"`
for i in {0..4};
do
sleep 1
tput cub 19
@komasaru
komasaru / regression_curve_ln.rb
Last active February 2, 2024 00:36
Ruby script to calculate a simple regression curve.(ln)
#! /usr/local/bin/ruby
#*********************************************
# Ruby script to calculate a simple regression curve.
# : y = a + b * ln(x)
# : 連立方程式を ガウスの消去法で解く方法
#*********************************************
#
class Array
def reg_curve_ln(y)
# 以下の場合は例外スロー