Skip to content

Instantly share code, notes, and snippets.

@ybenjo
ybenjo / power_of_human.rb
Created February 25, 2012 09:52
annotation whether anime/not
# -*- coding: utf-8 -*-
tmp = [ ]
open("../data/results/0225_0200/seiyu_graph_all.txt", "r"){|f|
tmp = f.read.split("\n")
}
women_seiyu = []
open("../data/seiyu_namelist_women.txt", "r"){|f|
women_seiyu = f.read.split("\n")
}
@ybenjo
ybenjo / gist:1827733
Created February 14, 2012 15:57
$HOME
y_benjo@SuperBENZA:~% tree -d -L 1
.
├── Desktop
├── Documents
├── Downloads
├── Dropbox
├── Library
├── Movies
├── Music
├── Pictures
@ybenjo
ybenjo / simple_bagging.R
Created January 24, 2012 13:00
bagging
# simple_bagging.R
library(mvpart)
bootstrap.data <- function(data, size = nrow(data)){
data[sample(nrow(data), size, replace = TRUE), ]
}
mode <- function(data){
data.table <- table(data)
# -*- coding: utf-8 -*-
# usage: ruby report_zangyou.rb --time 1h20m --day 6/6
require "rubygems"
require "tmail"
require "tlsmail"
require "net/smtp"
require "net/pop"
require "kconv"
require "yaml"
require "optparse"
@ybenjo
ybenjo / google_tex.rb
Created May 5, 2011 16:12
Convert 'hatena tex' to google chart
require 'cgi'
google_url = "http://chart.apis.google.com/chart?cht=tx&chl="
$<.each{|l|
l.chomp!
l.scan(/(\[tex:(.*?)\]){1,}/).each do |e|
math = e[1]
url_math = CGI.escape(math)
l.sub!(/#{Regexp.quote(e[0])}/,"<img src=\"#{google_url}#{url_math}\">")
end
puts l
@ybenjo
ybenjo / crawl_mtg_text.rb
Created April 23, 2011 09:05
crawl mtg wiki
require "nokogiri"
require "open-uri"
require "progressbar"
def parse_flavor_text(card_url)
page = Nokogiri(open(card_url))
card_title = (page/"td.mc"/"b").inner_text
fravor_text = (page/"i").inner_text.delete("\n\r\t")
# .zshrc
export LANG=ja_JP.UTF-8
export PATH=/opt/local/bin:/usr/local/bin:/opt/local/sbin:/usr/X11R6/bin:/usr/bin:/bin:/opt:local/sbin:/usr/sbin:/sbin
export MANPATH=/opt/local/man:$MANPATH
export RUBYLIB=/opt/local/lib/site_ruby/1.8/:/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8
export EDITOR='emacs'
export CPATH=$CPATH:$HOME/usr/local/bin/include:$HOME/local/include
;;; デフォ
(set-language-environment "Japanese")
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(set-locale-environment "utf-8")
(setenv "LANG" "ja_JP.UTF-8")
;;; みみっちい設定
file = [ ]
$<.each do |l|
file.push l.chomp
end
file.shuffle!
s = (file.size.to_f / 10).floor
open("./train.tsv", "w"){|f|
@ybenjo
ybenjo / one
Created March 14, 2011 14:03
aaa
cat f_1.csv|ruby -e '$<.each{|l|ary = l.chomp.split(",");3.upto(4){|i|ary[i]=0 if ary.include?("未満");if ary[i] != "-";ary[i]=ary[i].gsub(/[^0-9\.]/,"");end;};puts ary.join(",")}' | less