Skip to content

Instantly share code, notes, and snippets.

Avatar

Mitsuo Yoshida ceekz

View GitHub Profile
View gist:5570475
use List::Util;
sub cosine_similarity {
my ($vector_1, $vector_2, $is_pearson) = @_;
my %union;
foreach (keys %{$vector_1}, keys %{$vector_2}) {
$union{$_}++;
}
my $avg_1 = List::Util::sum(values %{$vector_1}) / scalar(keys %union);
View sign_test.pl
# Reference:
# http://aoki2.si.gunma-u.ac.jp/lecture/Average/sign-test.html
# http://kusuri-jouhou.com/statistics/fugou.html
use strict;
use warnings;
use List::Util;
my @sign = qw(1 0 1 1 -1 1 1 -1 1 1);
View gist:4506257
use List::Util;
sub add_cloud_font_size {
my ($font_size_min, $font_size_max, $val_col, @lists) = @_;
if (scalar(@lists) == 0) {
return;
}
my $val_min = log(List::Util::min(map { $_->{$val_col} } @lists) + 1);
my $val_max = log(List::Util::max(map { $_->{$val_col} } @lists) + 1);
@ceekz
ceekz / wget_wrapper.pl
Last active Oct 7, 2015
Wget Wrapper for a Web Page Cache
View wget_wrapper.pl
#!/usr/bin/perl
# Wget のラッパー
# 任意の URL のページを画像込みで保存する
# $ wget_wrapper.pl Directory URL
# (Directory は URL ごとにユニークなものを指定する)
#
# .htaccess 設定例
# AddType text/html .htmlwget
# DirectoryIndex index.htmlwget index.html index.htm
@ceekz
ceekz / gist:3099041
Created Jul 12, 2012
An IP address is used at random.
View gist:3099041
# サーバに割り当てた任意の IP アドレスを利用する
# (本コードではランダムに選択)
use LWP::UserAgent (@LWP::Protocol::http::EXTRA_SOCK_OPTS);
# ランダムに IP を選択
{
my @IP = qw(
203.0.113.1
203.0.113.2
@ceekz
ceekz / UnlockPDF.bat
Created Jul 12, 2012
Unlock PDF with gswin32c for Windows
View UnlockPDF.bat
set ttt=%1
set tt=%ttt:~0,-4%
gswin32c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sFONTPATH=%windir%/fonts;xfonts;. -sPDFPassword= -dPDFSETTINGS=/prepress -dPassThroughJPEGImages=true -sOutputFile="%tt%_noPW.pdf" %1
@ceekz
ceekz / dbbackup.sh
Last active Oct 7, 2015
Backup shell script for MySQL
View dbbackup.sh
#!/bin/sh
keepday=14
dir=/home/dbbackup
file=dump.sql
now_date=`date +%Y%m%d`
old_date=`date "-d$keepday days ago" +%Y%m%d`
cd $dir