Skip to content

Instantly share code, notes, and snippets.

def sim_dist items, user1, user2
keys = items.to_a.map{|x| x[1].keys}.flatten.uniq
sum = keys.map{ |item|
if items[user1][item] == nil or items[user2][item] == nil
0
else
Math.sqrt((items[user1][item] - items[user2][item]) ** 2)
end
}.reduce(0){|r, x| r + x}
1 / (sum +1)
#!/bin/env ruby
## -*- coding: utf-8 -*-
#
require 'open-uri'
require 'nokogiri'
def name url
"/music/ふぃあ通/" + url.split("/").last
end
# edit.html
<body>
<header />
<h1>Edit</h1>
<form>
<p id="l1">
<label>部署</label>
<select>
<option>---</option>
</select>
require "rack"
include Rack
class VerySmallHttpd
def get_path env
paths = env["PATH_INFO"].split("/")
paths.shift
paths.join("/")
end
var get_items = function(){
var parse_day = function(x){
var xs = x.replace('購入','').replace('日', '').replace('年', '月').split('月').map(function(x) parseInt(x))
return new Date(xs[0], xs[1] - 1, xs[2])
}
var parse_value = function(x){
return parseInt(x.replace('円','').replace(',',''))
}
var xs = $('.itemBlock').map(
function(){
# -*- coding: utf-8 -*-
id = ''
password = ''
denpyoNo = ''
date = '20101003'
time = '20100' # 20000, 20100, 20200, 20300, 20400, 20500, 20600
require 'mechanize'
Array.prototype.uniq = function(predicate){
this.sort()
ys = []
for(var i=0;i<this.length;i++){
if(ys.length == 0 || this[i] != ys[0]) ys.unshift(this[i])
}
return ys
}
xs = $("div.itemBlock").map(function(){
http://book.akahoshitakuya.com/add.php?asin=4047153737&image=http%3A%2F%2Fecx.images-amazon.com%2Fimages%2FI%2F61SQSeJD7qL._SL75_.jpg&page=0&author=%E8%97%A4%E7%9C%9F%20%E6%8B%93%E5%93%89&title=%E9%AD%94%E6%B3%95%E5%B0%91%E5%A5%B3%E3%83%AA%E3%83%AA%E3%82%AB%E3%83%AB%E3%81%AA%E3%81%AE%E3%81%AFViVid%20%281%29%20%28%E8%A7%92%E5%B7%9D%E3%82%B3%E3%83%9F%E3%83%83%E3%82%AF%E3%82%B9%E3%83%BB%E3%82%A8%E3%83%BC%E3%82%B9%20169-2%29&type=tun
http://book.akahoshitakuya.com/add.php?asin=4048688367&title=%e3%83%86%e3%82%b9%e3%83%88
https://order.my.rakuten.co.jp/?page=myorder&act=window&page_num=1&display_span=2008&display_month=all&search_item=&search_shop=&page=myorder&page_num=1
agent = WWW::Mechanize.new
# -*- coding: utf-8 -*-
require 'mechanize'
class RakutenOrder
def initialize
@agent = WWW::Mechanize.new
@agent.user_agent_alias = 'Windows IE 7'
end
def login id, password