Skip to content

Instantly share code, notes, and snippets.

View unak's full-sized avatar

usa unak

View GitHub Profile
RSTRLEN_MAX = 50
N = 10000
# user system total real
# ana1 0.109000 0.000000 0.109000 ( 0.104961)
# ana2 0.078000 0.000000 0.078000 ( 0.074173)
require 'benchmark'
def ana1(s1, s2)
require "open-uri"
URL = 'http://typhoon.yahoo.co.jp/weather/jp/earthquake/list/?sort=1&key=1&b='
START = Time.local(2016,4,14,21,15,59)
GRAPH = 'test.tsv'
HEADERS = %w[
熊本県天草・芦北地方
熊本県熊本地方
熊本県阿蘇地方
大分県西部
@unak
unak / delete multi bench
Created April 4, 2016 15:49
the former is normal trunk, the latter is multi-delete patched
D:\> type bench.rb
require 'benchmark'
REPEAT = 10_000_000
Benchmark.bm do |x|
x.report do
REPEAT.times do
[1,2,3,4,5].delete(1)
end
end
end
class A
def initialize
p :A
end
end
class B < A
def initialize
p :B
end
@unak
unak / random_mapper.rb
Created March 22, 2015 17:46
中点変位法によるランダム地形生成器
#!ruby
require 'zlib'
PNG = 'sample.png'
WIDTH = 192
HEIGHT = 192
# 中点変位法による基礎データ生成
d = [WIDTH, HEIGHT].max
m = 1
#define UNICODE
#include <windows.h>
#include <stdio.h>
int wmain(int argc, WCHAR **argv)
{
BY_HANDLE_FILE_INFORMATION info;
WIN32_FILE_ATTRIBUTE_DATA attr;
int ret = 0;
HANDLE h;
@unak
unak / show_dependency_tree_of_rails.rb
Created January 29, 2015 16:59
Show dependency tree of Rails
#!ruby
require "rubygems/dependency"
require "rubygems/spec_fetcher"
def fetch_spec(dep)
dep = Gem::Dependency.new(dep, :runtime) unless dep.is_a?(Gem::Dependency)
Gem::SpecFetcher.fetcher.spec_for_dependency(dep).first.map{|spec, src| spec}.last
end
$spec_cache = []
(事務局(メール送信先)rubyprize@ruby.or.jp)
As follows recommendation format for Prize members
(Please contact us at rubyprize@ruby.or.jp)
------------------------------------------------------------------------------
Ruby Prize 2014 Recommendation Sheet
(Prize 会員用)
 氏名 姓             名
 ※CRuby Committerの方はSubversionのアカウント名をご記載ください
@unak
unak / constraint.rb
Last active October 26, 2019 17:29
type constraint
class Module
class ConstraintError < TypeError; end
def where(meth, constraint)
m = Module.new do
define_method(meth) do |*args|
args.zip(constraint.keys.first) do |arg, t|
raise ConstraintError, "type #{t} is expected, but #{arg.inspect} is passed" unless arg.is_a?(t)
end
ret = super(*args)
@unak
unak / class.foo.patch
Last active December 31, 2015 00:19
※あとで消す 第2版。手抜き。ripper用コードはあってるかどうか知らん。
Index: defs/id.def
===================================================================
--- defs/id.def (リビジョン 44137)
+++ defs/id.def (作業コピー)
@@ -1,5 +1,6 @@
# -*- mode: ruby; coding: us-ascii -*-
firstline, predefined = __LINE__+1, %[\
+ class
freeze
inspect