This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
Benchmark.bmbm do |x| | |
x.report(' 10000 times << e ') do | |
(1..10000).reduce([]) { |m,e| m << e } | |
end | |
x.report(' 10000 times + [e]') do | |
(1..10000).reduce([]) { |m,e| m + [e] } | |
end | |
x.report('100000 times << e ') do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plus5div2 ary | |
plus5 = ->(input){ input + 5 } | |
div2 = ->(input){ input / 2 } | |
ary.map(&plus5).map(&div2) | |
end | |
plus5div2 [2, 4, 5, 3] # => [3, 4, 5, 4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This program has two feature. | |
# | |
# 1. Create a disk image on RAM. | |
# 2. Mount that disk image. | |
# | |
# Usage: | |
# $0 <dir> <size> <volume> | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun anything-c-sources-git-project-for (pwd) | |
(loop for elt in | |
'(("Modified files (%s)" . "--modified") | |
("Untracked files (%s)" . "--others --exclude-standard") | |
("All controlled files in this project (%s)" . "")) | |
collect | |
`((name . ,(format (car elt) pwd)) | |
(init . (lambda () | |
(unless (and ,(string= (cdr elt) "") ;update candidate buffer every time except for that of all project files | |
(anything-candidate-buffer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
result = (1..365).take_while { |i| | |
# 枝刈り | |
# (1..i)の合計(組み合わせの最小値)が1000を超えないものを対象にする | |
(1..i).reduce(:+) < 1000 | |
}.map { |i| | |
(1..365).to_a.combination(i) | |
}.map { |e| | |
# スレッドに分けて高速化 | |
Thread.new(e) { |g| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File.open('result.txt', 'w') do |f| | |
f << RUBY_DESCRIPTION | |
while line = STDIN.gets | |
f << line | |
STDOUT.print '0' | |
STDOUT.flush | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def gem_name | |
ARGV[0].chomp("/") | |
end | |
def constant_name | |
constant_name = gem_name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join | |
constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/ | |
constant_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'rack' | |
require 'rack/lobster' | |
NON_ASCII_VALUE = '日本語' | |
run Rack::Lobster.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Foo | |
a=1 # インスタンス変数じゃない! | |
define_method(:bar, lambda{ a+=1 }) | |
end | |
f = Foo.new | |
f.bar # => 2 | |
f.bar # => 3 | |
f.bar # => 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/usr/local% git diff | |
git diff | |
diff --git a/Library/Formula/poppler.rb b/Library/Formula/poppler.rb | |
index 79f8e4f..70088b6 100644 | |
--- a/Library/Formula/poppler.rb | |
+++ b/Library/Formula/poppler.rb | |
@@ -31,6 +31,9 @@ class Poppler < Formula | |
args = ["--disable-dependency-tracking", "--prefix=#{prefix}"] | |
args << "--disable-poppler-qt4" unless ARGV.include? "--with-qt4" | |
args << "--enable-xpdf-headers" if ARGV.include? "--enable-xpdf-headers" |