
hachune.net本格運用開始、みくった〜♪界隈のお手伝いなどなど、
一年中はちゅねさんまみれだった気がしなくもない。
その中で、いろんな人にいろいろお世話になりました。
本当にありがとうございました。そして、来年もよろしくお願いします。
それでは、また来年。
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
require 'uri'
require 'socket'
uri = URI.parse(ARGV[0])
sock = TCPSocket.open(uri.host, uri.port)
sock.printf("GET %s HTTP/1.1\r\n", uri.path)
sock.printf("Host: %s\r\n\r\n", uri.host)
str = String.new
rsize = 512
while dat = sock.recv(rsize)
str << dat
break if dat.size < rsize
end
sock.close
str.each_line{|line|
puts $1 if line =~ /^Location:\s*(.*)$/
}
piapro = PIAPRO::Download.new(:user=>"miku", :passwd=>"Mi93kU3KumIKu")
piapro.download_url("http://piapro.jp/download/?view=content_image&id=mikumikumikumiku")
db = SQLite3::Database.new("test.db")
db.execute(<<EOS
CREATE TABLE IF NOT EXISTS Vocaloid
(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name CHAR UNIQUE NOT NULL,
Ver INTEGER NOT NULL
);
EOS
)
db.execute(<<EOS
INSERT INTO Vocaloid
(Name, Ver)
VALUES ('miku', 2 )
)
sql = <<EOS
INSERT INTO Vocaloid
(Name, Ver )
VALUES (?, ?)
EOS
db.execute(sql, "miku", 2)
sql = <<EOS
INSERT INTO Vocaloid
(Name, Ver )
VALUES (:Name, :Ver)
EOS
db.execute(sql, :Name => "miku", :Ver => 2)
pre = db.prepare(<<EOS
INSERT INTO Vocaloid
(Name, Ver)
VALUES (?, ? )
)
pre.execute("miku", 2)
pre.execute("rin", 2)
pre.execute("meiko", 1)
pre = db.prepare(<<EOS
INSERT INTO Vocaloid
(Name, Ver)
VALUES (:Name, :Ver)
EOS
)
pre.execute(:Name=>"miku", :Ver=>2)
pre.execute(:Name=>"rin", :Ver=>2)
pre.execute(:Name=>"meiko", :Ver=>1)
$ PATH="/mingw/bin:/usr/local/bin:/bin"
$ ./configure --prefix=/mingw
$ make
$ make install
$ ./configure --prefix=/ruby
$ make
$ make install
$ /usr/local/bin/ruby extconf.rb
$ make
$ make install
#load-module module-native-protocol-tcp
#load-module module-zeroconf-publish
load-module module-native-protocol-tcp auth-ip-acl=10.39.39.0/24
load-module module-zeroconf-publish
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
require "yaml"
require "yaml/encoding"
# String.is_binary_data?で必ずfalseを返すように書き換える
class String
def is_binary_data?
return false
end
end
data = {"はつね"=>"みく", "はちゅね"=>"みく", "かがみね"=>"りん・れん", "めぐりね"=>"るか"}
# 通常どおり表示
puts "Escape:"
puts yaml = YAML.dump(data)
# アンエスケープして表示
puts "Unescape:"
puts yaml = YAML.unescape(yaml)
#!/usr/ruby1.9/bin/ruby1.9
#-*- encoding: utf-8 -*-
require "webrick"
# HTTPServerを作成
httpd = WEBrick::HTTPServer.new(:Port => 3939)
# Basic認証の設定(引数にはパスワードファイルへのパスを渡す)
pswd = WEBrick::HTTPAuth::Htpasswd.new("dot.passwd")
pswd.set_passwd("mikubox", "miku", "mikumiku") #realm, user, passwd
auth = WEBrick::HTTPAuth::BasicAuth.new(:UserDB => pswd, :Realm => "mikubox")
# HTTPServerの/loginにBasic認証を設定
httpd.mount_proc("/login"){|req, res|
# 認証
auth.authenticate(req, res)
res.body = "<html><head><title>みくかわいいよみく</title></head><body><p>OK.</p></body></html>"
}
# INTシグナルでサーバを停止
trap("INT"){httpd.stop}
# サーバを開始
httpd.start()
#!/usr/ruby1.9/bin/ruby1.9
#-*- encoding: utf-8 -*-
require "webrick"
# HTTPServerを作成
httpd = WEBrick::HTTPServer.new(:Port => 3939)
# ダイジェスト認証の設定(引数にはダイジェスト認証用のデータベースのパスを渡す)
pswd = WEBrick::HTTPAuth::Htdigest.new("dot.digest")
if pswd.get_passwd("mikubox", "miku", false) == nil
pswd.set_passwd("mikubox", "miku", "mikumiku") # realm, user, passwd
pswd.flush # ファイルに書き込む
end
auth = WEBrick::HTTPAuth::DigestAuth.new(:UserDB => pswd, :Realm => "mikubox")
# HTTPServerの/loginにダイジェスト認証を設定
httpd.mount_proc("/login"){|req, res|
# 認証
auth.authenticate(req, res)
res.body = "<html><head><title>みくかわいいよみく</title></head><body><p>OK.</p></body></html>"
}
trap("INT"){httpd.stop}
httpd.start()
#!/usr/ruby1.9/bin/ruby1.9
#-*- encoding: utf-8 -*-
require "webrick"
httpd = WEBrick::HTTPServer.new(:Port => 3939)
httpd.mount_proc('/login') {|req, res|
WEBrick::HTTPAuth.basic_auth(req, res, "mikubox") {|user, pass|
user == 'miku' && pass == 'mikumiku'
}
res.body = "<html><head><title>みくかわいいよみく</title></head><body><p>OK.</p></body>
</html>"
}
trap("INT"){httpd.stop}
httpd.start
require "webrick"
WEBrick::HTTPServer.new(:Port => 3939, :DocumentRoot => ENV["HOME"]).start
http.mount(Webサーバ上でのパス, WEBrick::HTTPServlet::CGIHandler, CGIとして実行するファイルのパス)
http = WEBrick::HTTPServer.new(:ServerName => "miku.hachune.net", :DocumentRoot => "miku/")
http.virtual_host(WEBrick::HTTPServer.new(:ServerName => "append.haachune.net", :DocumentRoot => "append/", :Port => nil, :DoNotListen => true))
http.start
:DocumentRootOptions => {
:UserDir => "public_html"
}
newmime = {"wav"=>"Audio/wav"}
mime = WEBrick::HTTPUtils::DefaultMimeTypes.merge(newmime)
WEBrick::HTTPServer.new(:DocumentRoot => ENV[HOME], :MimeTypes => mime).start
:DocumentRootOptions => { :FancyIndexing => false }
:MaxClients => クライアント数
:DocumentRootOptions => {
:NondisclosureName => [".ht*", "*~", ".svn"]
}
http = WEBrick::HTTPServer.new(:Port => 3939)
http.mount_proc("/"){|req, res|
res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, 'http://hachune.net/')
}
http = WEBrick::HTTPServer.new(:Port => 3939)
http.mount_proc("/"){|req, res|
res["Set-Cookie"] = "hatsune=miku;Max-Age=3600;"
res.body = "<p>Cookieです。</p>"
}
:DocumentRootOptions =>{
:MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes.merge({"rhtml"=>"text/html"})
}
module WEBrick::HTTPServlet
WEBrick::HTTPServlet::FileHandler.add_handler('rb', WEBrick::HTTPServlet::CGIHandler)
WEBrick::HTTPServlet::FileHandler.add_handler('html', WEBrick::HTTPServlet::ERBHandler)
end
#!/usr/bin/env ruby
#-*- encoding: utf-8 -*-
require "socket"
SERVERIP = "192.168.0.105"
SERVERPORT = "62000"
clientList = Array.new
sock = UDPSocket.new
# サーバとして待ち受けるアドレスとポートを指定
sock.bind(SERVERIP, SERVERPORT)
while true
# sockに出力が来るのを待つ
# 来なかったらnilを返す
sel = IO::select([sock])
if sel != nil
sel[0].each {|s|
# 最大65535byte分のデータを受け取る。
# データは配列として渡される。
# ["文字列", ["アドレス種別", 送信元ポート番号, "送信元ホスト名", "送信元IPアドレス"]]
# ["192.168.0.105 :43433 miku > miku\n", ["AF_INET", 62000, "192.168.0.105", "192.168.0.105"]]
data = s.recvfrom_nonblock(65535)
string = data[0].chomp!
ip, port = data[1][3].to_s, data[1][1].to_i
clientList << {"ip"=>ip, "port"=> port}
clientList.uniq!
# 各クライアントに向けて返信する
clientList.each{|client|
printf("Server > %-15s:%5d %s\n", client["ip"], client["port"], string)
# 実際に返信する。send("文字列", フラグ, "送信先IPアドレス", "送信先ポート")
sock.send(sprintf("%-15s:%5d %s\n", client["ip"], client["port"], string), 0, client["ip"], client["port"])
}
}
end
end
sock.close
#!/usr/bin/env ruby
#-*- encoding: utf-8 -*-
require "socket"
if ARGV[0] == nil
puts "ex) ./client.rb miku"
exit 1
end
NAME = ARGV[0]
SERVERIP = "192.168.0.105"
SERVERPORT = "62000"
# UDPのソケットを作成
sock = UDPSocket.new
# バインドするIPアドレスとポートを自動で割り当てる
sock.bind("0.0.0.0", 0)
# サーバからの情報を受け取り表示するスレッドを作成
thread = Thread.new {
while true
# sockに出力が来るのを5秒待つ。
# 来なかったらnilを返す。
sel = IO::select([sock], nil, nil, 5)
if sel != nil
sel[0].each{|s|
data = s.recvfrom_nonblock(65535)
puts data[0].chomp!
}
end
end
}
# サーバに情報を送信するループ
while true
string = STDIN.gets.chomp!
sock.send(sprintf("%-5s> %s\n", NAME, string), 0, SERVERIP, SERVERPORT)
end
sock.close
#include<stdio.h>
int main(void){
int i;
#pragma omp parallel
for(i=0; i<20; i++){
printf("Thread %d : %d\n", omp_get_thread_num(), i);
}
return 0;
}
miku@kagamine:~/c-lang$ ./openmp_1
Thread 0 : 0
Thread 0 : 1
Thread 0 : 2
Thread 0 : 3
Thread 0 : 4
Thread 1 : 0
Thread 1 : 1
Thread 1 : 2
Thread 1 : 3
Thread 1 : 4
miku@kagamine:~/c-lang$ ./openmp_1
Thread 1 : 0
Thread 1 : 1
Thread 1 : 2
Thread 1 : 3
Thread 1 : 4
Thread 0 : 0
#include<stdio.h>
int main(void){
int i;
// 変数iをスレッド内プライベートとして渡し、スレッドを開始させる
#pragma omp parallel private(i)
for(i=0; i<3; i++){
printf("Thread %d : %d\n", omp_get_thread_num(), i);
}
return 0;
}
miku@kagamine:~/c-lang$ ./openmp_2
Thread 0 : 0
Thread 1 : 0
Thread 1 : 1
Thread 1 : 2
Thread 0 : 1
Thread 0 : 2
#include<stdio.h>
// 変数iをグローバルとして渡すが、printfとi++の部分を排他動作させる
int main(void){
int i;
i = 0;
#pragma omp parallel
while (i<10){
// 排他処理部分をブロックで指定
#pragma omp critical
{
printf("Thread %d : %d\n", omp_get_thread_num(), i);
i++;
}
sleep(1);
}
return;
}
miku@kagamine:~/c-lang$ ./openmp_3
Thread 1 : 0
Thread 0 : 1
Thread 1 : 2
Thread 0 : 3
Thread 1 : 4
Thread 0 : 5
Thread 1 : 6
Thread 0 : 7
Thread 1 : 8
Thread 0 : 9
#include<stdio.h>
#include<unistd.h> // usleep()
#include<stdlib.h>
// ダミー処理関数(CPUに負荷を掛ける)
void dummy(int number){
int n, i, tmp;
int array[number];
for(i=0; i<number; i++){
array[i] = i;
}
for (n=0; n<number; n++){
for (i=0; i<number - 1; i++){
if (array[i] < array[i+1])
{
tmp = array[i];
array[i] = array[i+1];
array[i+1] = tmp;
}
}
}
return;
}
// 変数iをグローバルとして渡すが、printfとi++、dummy(10000)の部分をシングルスレッド動作させる
int main(void){
int i, while_count;
i = 0;
while_count = 0;
#pragma omp parallel
while (<<100){
// ブロック内をシングルスレッド動作させる
#pragma omp single
{
printf("Thread %d : %d\n", omp_get_thread_num(), i);
i++;
dummy(10000);
}
printf("Thread %d : loop...\n", omp_get_thread_num());
usleep(10);
while_count++;
}
printf("loop Count: %d\n", while_count);
return;
}
#include<stdio.h>
#include<unistd.h> // usleep()
#include<stdlib.h>
// ダミー処理関数(CPUに負荷を掛ける)
void dummy(int number){
int n, i, tmp;
int array[number];
for(i=0; i<number; i++){
array[i] = i;
}
for (n=0; n<number; n++){
for (i=0; i<number - 1; i++){
if (array[i] < array[i+1])
{
tmp = array[i];
array[i] = array[i+1];
array[i+1] = tmp;
}
}
}
return;
}
// 変数iをグローバルとして渡すが、printfとi++、dummy(10000)の部分をシングルスレッド動作させる。
// もしその部分が別スレッドで処理中ならスキップする
int main(void){
int i, while_count;
i = 0;
while_count = 0;
#pragma omp parallel
while (i<100){
// single nowait : 他のスレッドがブロック内を実行中だったらスキップ
#pragma omp single nowait
{
printf("Thread %d : %d\n", omp_get_thread_num(), i);
i++;
dummy(10000);
}
printf("Thread %d : loop...\n", omp_get_thread_num());
usleep(10);
while_count++;
}
printf("loop Count: %d\n", while_count);
return;
}