2013-01-28 atnd
- 何かアプリを乗せる話
- Java
def quicksort(arr) | |
return arr if arr.size <= 1 | |
pivot = arr.last | |
f, l = 0, arr.size - 1 | |
loop do | |
loop { break if arr[f].nil? || arr[f] > pivot; f += 1 } | |
loop { break if arr[l].nil? || arr[l] < pivot; l -= 1 } | |
break if l < f | |
arr[f], arr[l] = arr[l], arr[f] | |
end |
2013-01-28 atnd
% perlbrew install perl-5.16.2 | |
Fetching perl 5.16.2 as /Users/katsunori.kawaguchi/perl5/perlbrew/dists/perl-5.16.2.tar.bz2 | |
Installing /Users/katsunori.kawaguchi/perl5/perlbrew/build/perl-5.16.2 into ~/perl5/perlbrew/perls/perl-5.16.2 | |
This could take a while. You can run the following command on another shell to track the status: | |
tail -f ~/perl5/perlbrew/build.perl-5.16.2.log | |
Installation process failed. To spot any issues, check |
http://www.zusaar.com/event/489108
use 5.016; | |
use DateTime; | |
# beginning_of_day | |
say DateTime->now( time_zone=>'local' )->truncate( to => "day" )->strftime('%Y/%m/%d %H:%M:%S') | |
# => 2013/03/15 00:00:00 | |
# サマータイムで存在しない時刻を指定すると例外 | |
# (America/Chicago時刻では、2003-04-06 01:59:59 の次は 2003-04-06 03:00:00) | |
DateTime->new( time_zone => 'America/Chicago', year => 2003, month => 4, day => 6, hour => 2, minute => 0, second => 0 ); |
require "open3" | |
require "colorize" | |
guard 'shell' do | |
watch(/(.*).pm/) do |m| | |
arr = Open3.capture3("perl -c #{m[0]}") | |
line = arr.first.split("\n").first | |
unless line =~ /syntax OK/ | |
puts line.red | |
else |
[1] pry(main)> require "active_support/time" | |
=> true | |
[2] pry(main)> Time.parse("2013-03-31").next_month | |
=> 2013-04-30 00:00:00 +0900 | |
re.pl$ use DateTime | |
re.pl$ DateTime->new(year => 2013, month => 3, day =>31)->add( months => 1)->ymd; | |
"2013-05-01" |
use 5.016; | |
use utf8; | |
use Encode; | |
use Encode::Guess qw/utf8 euc-jp shiftjis/; | |
my $str = 'あああ'; | |
say guess_encoding($str)->name; | |
# => utf8 |
MAX_KETA = 15 | |
# 半径1の正n角系の辺の長さ | |
def edge_length_of_regular_polygon(n) | |
2 * n * Math.sin(Math::PI / n) | |
end | |
n = 6 | |
(0..MAX_KETA).each do |keta| | |
approximation_of_pi = (Math::PI * 10 ** keta).truncate * 1.0 / 10 ** keta |
class Player | |
def initialize | |
@step = :forward | |
@health = 20 | |
@max_health = 20 | |
@last_health = 20 | |
@touch_wall = false | |
end | |
def play_turn(warrior) |