Skip to content

Instantly share code, notes, and snippets.

View yswallow's full-sized avatar

Sanagi yswallow

View GitHub Profile
@yswallow
yswallow / mishuna.rb
Created July 14, 2015 08:23
ミシュナ分配
module Mishuna
def self.mishuna(_isan, ary)
isan = _isan
size = ary.size
half_min = ary.min / 2
sum = ary.inject(&:+)
if isan <= half_min * size
return [ isan/size ]*size
elsif isan <= sum - half_min * size
new_ary = []
@yswallow
yswallow / unsortable-sort.rb
Created July 13, 2015 04:32
Rubyで可逆ソート
class Array
protected
attr_accessor :matrix
public
def sort_with_matrix
item_with_index = self.map.with_index { |item,i| [item,i] }
item_with_index.sort_by! { |item,i| item }
new_array = []
matrix = []

日本語入力システムの予測変換辞書を用いた文書圧縮

動機

  • 入力が楽→入力する文字数が少ない→入力した文字と変換キーを押した回数を記録すれば(文字列については)高効率に圧縮できるんじゃね?
  • 圧縮したあとの文字列も日本語風になるからそれを既存の圧縮方式でさらに圧縮することも可能(?)

実装

  • 入力文字は半角カナで、変換キー押下回数はそのまま数字で。英数字や珍しい漢字、特異な顔文字は制御文字に挟んで平文で。

Google IMEがクローズドソースだった場合

module Foo
def self.hoge
fuga
end
def fuga
'bar'
end
end
@yswallow
yswallow / mobilizer.rb
Created June 1, 2015 15:30
htmlの本文のxpathを探すアルゴリズム(その2)
require 'nokogiri'
def mobilizer(page)
page = Nokogiri::HTML(page.to_s) if page.class == String
remove_tags = ['script', 'style', 'select', 'a']
remove_tags.each do |tag|
page.xpath('//' + tag).each { |n| n.remove }
end
path = identifier(page, '/html/body')
@yswallow
yswallow / utlan-auth.rb
Created May 19, 2015 07:53
ITF大のLANの認証スクリプト
require 'net/http'
require 'uri'
utid13 = 'your id'
password = 'your password'
url = 'https://webauth03.cc.tsukuba.ac.jp:8443/cgi-bin/adeflogin.cgi'
res = Net::HTTP.post_form(URI.parse(url), {'name' => utid13, 'pass' => password })
puts res.body.scan(/Login.+?</) do |match|
@yswallow
yswallow / mobilizer.rb
Created February 15, 2014 04:18
htmlの本文のxpathを探すアルゴリズム()
#usage: xpath = mobilizer(html)
require 'nokogiri'
require 'kconv'
def search_equal(pathes)
return pathes[0] if pathes.size == 1
pathes.map! { |path| path.split('/') }
fullsize = pathes.size
path = []
@yswallow
yswallow / nenga2014.rb
Last active January 3, 2016 21:09
年賀はがきが当たりか確認する
#coding: UTF-8
loop do
num = gets.chomp
#puts num
puts 'ERROR 'if num.length != 6
puts ( if /97085$/ =~ num
'1等'
elsif /2344$/ =~ num
'2等'
elsif /(72|74)$/ =~ num
@yswallow
yswallow / search_enemy.rb
Created June 14, 2013 15:38
vcard.ameba.jp で戦いやすい相手を探す
# coding: UTF-8
require "./tools2"
require "pp"
require 'json'
require "nokogiri"
VCard.set_ua
baseurl = "http://vcard.ameba.jp/battle/battle-detail?enemyId="
10.times do
io = VCard.getio("/battle/ajax/battle-user-search?cond=level")
@yswallow
yswallow / check_gift_girls.rb
Created June 13, 2013 13:59
http://vcard.ameba.jp/giftbox でカードを枚数順に並べ替えて表示するスクリプト
# coding: UTF-8
#require "./tools"
require "open-uri"
require "pp"
require "nokogiri"
class VCard
@@cookie_changed = true
@@cookies = {}
@@ua = ""