Skip to content

Instantly share code, notes, and snippets.

@kozakana
kozakana / MT_Average.rb
Last active August 29, 2015 13:59
Rubyで使用されている乱数の均等分布について(メルセンヌ・ツイスタ) ref: http://qiita.com/kozakana/items/b5229094cf8d29767847
MAX_VAL = 101
REP_CNT = 10**6
sum = 0.0
prng = Random.new(Random.new_seed)
(0...REP_CNT).each{|idx|
p sum = (sum*idx + prng.rand(MAX_VAL))/(idx+1)
}
@kozakana
kozakana / body01.tmpl
Last active January 2, 2017 10:34
マークダウンを将棋用に拡張したフォーマットのngx_mruby版
</body>
</article>
</html>
@kozakana
kozakana / cloud_front_ips.sh
Last active June 5, 2022 15:01
CloudFrontのIPアドレスを取得してnginxのset_real_ip_fromの形式で出力
curl -s "https://ip-ranges.amazonaws.com/ip-ranges.json" |jq -r '.prefixes | map(select(.service == "CLOUDFRONT").ip_prefix) | "set_real_ip_from" + " " + .[] + ";"'
@kozakana
kozakana / gcv_api.rb
Last active September 6, 2021 13:38
Using Google cloud vision easily
require 'google/apis/vision_v1'
class GcvApi
def initialize api_key, option={}
default = {
retry: 5,
max_results: 2048,
language_hints: 'ja'
}
@option = default.merge option
@kozakana
kozakana / createIndex.js
Last active December 26, 2019 14:06
js-unigram
const Document = require('./document')
const fs = require('fs')
const TOKEN_DIR = './tokens'
const DOC_DIR = './docs'
const DOC_DATA = './docs.json'
const docFiles = fs.readdirSync(DOC_DIR).filter(fileName => fileName.match(/.+\.txt$/))
const docs = {}
@kozakana
kozakana / shoryuken_process_clean.sh
Created February 3, 2020 10:32
Send USR1 signal to shoryuken processes that did not terminate
#!/bin/sh
pid_files=("$@")
correct_pids=()
if [ ${#pid_files[@]} -le 0 ]; then
echo "Usage: ./shoryuken_process_clean.sh PID_FILE..."
exit 1
fi