Skip to content

Instantly share code, notes, and snippets.

View masui's full-sized avatar

Toshiyuki Masui masui

View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pyPdf import PdfFileWriter, PdfFileReader
import sys
def main():
"""ファイル を 1ページごとに分割する"""
div = 1
@masui
masui / gist:2333386
Created April 8, 2012 01:18
増井研サーバへのアップロード
#!/usr/bin/ruby
require 'digest/md5'
file = ARGV.shift
exit unless file
exit unless File.exist?(file)
ext = ''
if file =~ /^(.*)(\.\w+)$/ then
#
# http://Gyazz.com/増井研/オリエンテーション2012 のようなGyazzページをスライドテキストに変換
# % ruby gyazz2slide 増井研 オリエンテーション2012 user pass > slide.txt
#
require 'rubygems'
require 'gyazz'
name = ARGV.shift
page = ARGV.shift
user = ARGV.shift
@masui
masui / gist:2424835
Created April 19, 2012 23:27
は+゛ のようなのを ば に変換
#「は」+「゛」のようなUTFを「ば」に変換する
# コード表
# http://orange-factory.com/sample/utf8/code3-e3.html
def normalize(ss)
s = ss.dup
while s =~ /^(.*)\xe3([\x81\x82\x83])(.)\xe3\x82\x99(.*)$/ do # 濁点
c1 = $2[0]
c2 = $3[0]
if c1 == 0x82 && c2 == 0xbf then # 「タ」
c1 = 0x83
def count_a(s)
s.split(//).map{|i| i == "a" ? 1 : 0}.inject(:+)
end
def count_a(s)
s.split(//).grep(/a/).length
end
def count_a(s)
count = 0
(0...s.length).each { |i|
count += 1 if s[i] == 97
}
count
end
require 'net/http'
Net::HTTP.start('masui.sfc.keio.ac.jp', 80) {|http|
http.post('/door/open')
}
a = [1, 2, 3, 4]
sum = a.inject(:+)
(1..100).each { |i|
s = ''
s += 'Fizz' if i % 3 == 0
s += 'Buzz' if i % 5 == 0
s = i.to_s if s == ''
puts s
}