Skip to content

Instantly share code, notes, and snippets.

View komasaru's full-sized avatar

mk-mode komasaru

View GitHub Profile
@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)
# 以下の場合は例外スロー
@komasaru
komasaru / logistic_regression.rb
Created October 11, 2022 02:33
Ruby script to calculate a logistic regression.
#! /usr/local/bin/ruby
#*********************************************
# Ruby script to compute a logistic regression analysis.
# (by extending the matrix class)
#*********************************************
#
require 'matrix'
class Matrix
ALPHA = 0.01 # 学習率
@komasaru
komasaru / calc.cpp
Last active January 21, 2024 22:45
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 / rmagick_watermark.rb
Last active August 20, 2023 12:00
Ruby script to write a watermark by rmagick.
#! /usr/local/bin/ruby
# coding: utf-8
#----------------------------------------------------
# Ruby script to write a watermark by rmagick.
#
# date name version
# 2016.04.24 mk-mode.com 1.00 New creation.
#
# Copyright(C) 2016 mk-mode.com All Rights Reserved.
#----------------------------------------------------
@komasaru
komasaru / conv_camel_snake.rb
Created October 28, 2016 08:48
Ruby script to convert CamelCase and snake_case each other.
class String
def to_camel
self.split(/_/).map(&:capitalize).join
# or
#self.split(/_/).map{ |w| w[0] = w[0].upcase; w }.join
end
def to_snake
self.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
@komasaru
komasaru / test_daemon.py
Last active July 20, 2023 19:31
Python script to do a process as a daemon.
#!/usr/local/bin/python3.6
import datetime
import sys
import traceback
from daemon import DaemonContext
from os import path
from time import sleep
from lockfile.pidlockfile import PIDLockFile
@komasaru
komasaru / simplex.f95
Last active July 17, 2023 21:18
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 / ecef2blh.f95
Last active July 12, 2023 01:45
Fortran 95 source code to convert ECEF to WGS84(BLH) coordinate.
!*******************************************************************************
! ECEF -> BLH 変換
! : ECEF(Earth Centered Earth Fixed; 地球中心・地球固定直交座標系)座標を
! WGS84 の緯度(Latitude)/経度(Longitude)/楕円体高(Height)に変換する。
!
! date name version
! 2019.02.21 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2019 mk-mode.com All Rights Reserved.
! ---