Skip to content

Instantly share code, notes, and snippets.

View yswallow's full-sized avatar

Sanagi yswallow

View GitHub Profile
@yswallow
yswallow / techtech-19-2.rb
Created April 28, 2013 01:42
東工大のクイズ(http://www.titech.ac.jp/publications/j/techtech19/06.html のNo.2)を力ずくで解く〜Ruby ver.〜
for i in 1..200
puts i if i%7 == 3 && i%5 == 2 && i%3 == 1
end
#=>52,157
@yswallow
yswallow / techtech17-2.c
Last active December 16, 2015 18:09
http://www.titech.ac.jp/publications/j/techtech17/06.html のNo.2 (C言語) 人力で解くアルゴリズムを考えさせる問題だと思うけど。
#include <stdio.h>
int main(void)
{
int i,t,sum;
for(i=1;i<250;i++)
{
sum = 0;
for(t=i;sum<500;t++)
for i in 1...250
sum = 0
t = i
while sum<500
sum += t
if sum==500
puts i
break
end
t += 1
@yswallow
yswallow / dl_every_voices.rb
Created May 6, 2013 15:35
vcard.ameba.jp の手に入れた音声を全てダウンロードするスクリプト(誰得
require "nokogiri"
require "./collection-post"
require 'open-uri'
ua = "Mozilla/5.0 (Linux; U; Android 4.0.3; ja-jp; URBANO PROGRESSO Build/010.0.3000) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
cookies = { "gameAuthId" => "Your own gameAuthId", "vcardPixelRatio" => "1" }
cookie_str = cookies.map { |cookie| cookie.join('=') }.join(';')
$header = { "Cookie" => cookie_str, "User-Agent" => ua }
def vcard_getio( url )
@yswallow
yswallow / akbmatome.rb
Created June 8, 2013 14:33
AKB総選挙の64位以上の獲得票数の合計を調べる
# coding: UTF-8
require "open-uri"
require "nokogiri"
url = 'http://akb48matome.com/archives/51881418.html'
page = Nokogiri::HTML(open(url))
File.write "matome.html" , page.to_html
#page = Nokogiri::HTML(open('./matome.html'))
items = page.xpath('//table/tbody/tr')
sum = 0
@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 = ""
@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 / 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 / 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 / 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|