Skip to content

Instantly share code, notes, and snippets.

@kimoto
kimoto / nginx
Created July 4, 2012 08:43
/etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
@kimoto
kimoto / sum_rand.rb
Created June 6, 2012 04:03
乱数の和が正規分布するやつのテストコード
def dice(max = 6)
(rand() * max).to_i + 1
end
# 1. まずrubyの乱数(rand)の性質を調べる
puts "ruby rand() test"
d = {}
1000.times{
n = dice
d[n] ||= 0
@kimoto
kimoto / yes_web_api.rb
Created June 1, 2012 08:03
yes WEB API (Ruby + Sinatra/Streaming)
# coding: utf-8
require 'sinatra'
require 'sinatra/streaming'
set server: 'thin', connections: []
th = Thread.new{
while true
puts "currently connection: #{settings.connections.size}"
settings.connections.each{ |e|
e << "yes\n"
@kimoto
kimoto / steam_subscriber_agreement.txt
Created April 10, 2012 08:47
STEAMTM SUBSCRIBER AGREEMENT (copy)
STEAMTM SUBSCRIBER AGREEMENT
This Agreement is written only in the English language, which language will be controlling in all respects. All communications to be made or given pursuant to this Agreement will be in the English language, except as may be required under applicable law.
1. REGISTRATION AND ACTIVATION.
Steam is an online service (.Steam.) offered by Valve Corporation (.Valve.).
You become a subscriber of Steam (.Subscriber.) by installing the Steam client software and completing the Steam registration. Additionally, as a Subscriber you may obtain access to certain services, software and content (.Subscriptions.) available to Subscribers. This Steam Subscriber Agreement (.Agreement.) is a legal document that explains your rights and obligations as a Subscriber. Please read it carefully.
@kimoto
kimoto / gist:2316890
Created April 6, 2012 04:34
RubyのHTML/XMLパーサー、nokogiriの間違えやすい問題について
# RubyのHTML/XMLパーサー、nokogiriの間違えやすい問題について
# Nokogiri関数に渡すXMLデータのどこかのタグの属性値に"HTML"という文字が含まれていると、
# HTML文書として解釈され、<html><body>というのが勝手に挿入される。そのため本来マッチするはずのXPathがマッチしなくなったりする。
#
# Nokogiri::XMLかNokogiri::HTMLを使いましょう! (当たり前)
# でも属性値にHTMLという文字が含まれてるだけでHTML文書として解釈するのはまずい気がする。。
#
# ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
# nokogiri (1.5.0)
require 'nokogiri'
@kimoto
kimoto / pubkey_url.rb
Created March 9, 2012 13:39
Generate public key data-uri from ssh-rsa private key
#!/bin/env ruby
# encoding: utf-8
# Author: kimoto
require 'open-uri'
require 'base64'
require 'openssl'
ssh_rsa_path = File.join(ENV['HOME'], ".ssh/id_rsa")
ssh_rsa = File.read(ssh_rsa_path)
pubkey = OpenSSL::PKey::RSA.new(ssh_rsa).public_key.to_s
@kimoto
kimoto / ssh_rsa_to_pubkey.rb
Created March 9, 2012 13:20
ssh-rsaの秘密鍵から公開鍵を生成するスクリプト
#!/bin/env ruby
# encoding: utf-8
# Author: kimoto
require 'openssl'
ssh_rsa_path = File.join(ENV['HOME'], ".ssh/id_rsa")
ssh_rsa = File.read(ssh_rsa_path)
print OpenSSL::PKey::RSA.new(ssh_rsa).public_key.to_s
@kimoto
kimoto / gig.rb
Created March 6, 2012 01:48
gig2.rb (Nokogiri+retry-handler+open-uri)
#!/usr/bin/env ruby
# vim:encoding=UTF-8:
=begin
# gig.rb
Github IRC Gateway
=end
require "logger"
require "ostruct"
@kimoto
kimoto / parallel_with_retry-handler.rb
Created March 5, 2012 01:36
parallel + retry-handlerのサンプルコード
Parallel.each(last_infos, :in_threads => 4){ |last_info|
begin
Proc.new do
timeout(20) do
Peercast::Screenshot.new(last_info.url).download_to(download_path)
end
last_info.capture = download_path
last_info.save
end.retry(:max => 3, :accept_exception => Timeout::Error, :logger => Logger.new(STDERR))
@kimoto
kimoto / hatefav.rb
Created March 2, 2012 04:04
はてなお気に入りのフィードのIRC Gateway
#!/bin/env ruby
# encoding: utf-8
# Author: kimoto
require 'net/irc'
require 'net/irc/mala'
require 'rss'
require 'open-uri'
class Net::IRC::HateFav < Net::IRC::Server::Session
def server_name