Saturday, September 29, 2012

Calculate the firefox year (Fixed)

(Check also phosphorescence: Calculate the firefox year)

Firefox team announced changing their "Rapid release" plan.

The reason is "the Happy Holidays". BTW, I fix previous "Calculate the firefox year" ruby code for this change.
$ irb -rfiber -rdate
irb(main):001:0> next_firefox = Fiber.new do
irb(main):002:1*   ff5 = Date.new(2011, 6, 21)
irb(main):003:1>   ff_next = 6
irb(main):004:1>   ff_next_date = ff5 + 7 * 8
irb(main):005:1>   loop do
irb(main):006:2*     Fiber.yield ff_next, ff_next_date
irb(main):007:2>     ff_next += 1
irb(main):008:2>     ff_plan_date = ff_next_date + 7 * 6
irb(main):009:2>     ff_happy_holiday = Date.new(ff_next_date.year, 12, 25)
irb(main):010:2>     if ff_happy_holiday.year >= 2012 && (ff_next_date..ff_plan_date).include?(ff_happy_holiday)
irb(main):011:3>       ff_next_date = ff_plan_date + 7
irb(main):012:3>     else
irb(main):013:3*       ff_next_date = ff_plan_date
irb(main):014:3>     end
irb(main):015:2>   end
irb(main):016:1> end
=> #<Fiber:0x2dc0af8>
irb(main):017:0> next_firefox_version, next_firefox_date = next_firefox.resume
=> [6, #<Date: 2011-08-16 ((2455790j,0s,0n),+0s,2299161j)>]
irb(main):018:0> while (next_firefox_version < next_firefox_date.year) do
irb(main):019:1>   next_firefox_version, next_firefox_date = next_firefox.resume
irb(main):020:1> end
=> nil
irb(main):021:0> puts "The version equals release year", next_firefox_version, next_firefox_date
The version equals release year
2277
2277-11-06
=> nil

Thursday, September 27, 2012

Learning F# 3.0 : auto-property

Fundamentally, any instances on F# should be immutable. But, if we use F# as C# substitute, we might want mutable object like POCO/POJO. Until F# 2.0, we writed like that:
type Person2() =
    let mutable firstName:string = ""
    let mutable lastName:string = ""
    let mutable age:int = 0
    member this.FirstName with get() = firstName
                          and set(n) = firstName <- n
    member this.LastName with get() = lastName
                         and set(n) = lastName <- n
    member this.Age with get() = age
                    and set(n) = age <- n
But, this is a little complicated. So that, since F# 3.0, here comes the syntax sugar called auto-property:
type Person3() =
    member val FirstName:string = "" with get, set
    member val LastName:string = "" with get, set
    member val Age:int = 0 with get, set
It looks like "Plain Old F# Object"!

Monday, September 24, 2012

Euler's formula does not equal because of Float in Ruby

Euler's formula does not equal because of Float in Ruby. Let's show the example at x = Π.

$ irb -rcmath
irb(main):001:0> include CMath
=> Object
irb(main):002:0> left_euler = exp(-1.0*sqrt(-1.0)*PI)
=> (-1.0-1.2246063538223773e-16i)
irb(main):003:0> right_euler = cos(PI) + sqrt(-1.0) * sin(PI)
=> (-1.0+1.2246063538223773e-16i)
irb(main):004:0> left_euler == right_euler
=> false
irb(main):005:0> left_euler === right_euler
=> false

(check also phosphorescence: Euler's formula in Ruby)

Friday, September 21, 2012

UUID in Ruby

There are 3 ways to deal UUID in Ruby.

(1) Use SecureRandom class

Check my article.

(2) Install uuid gem

Check Github page of uuid gem.

(3) [for JRuby] Using java.util.UUID

irb(main):001:0> require 'java'
irb(main):002:0> import java.util.UUID
irb(main):003:0> UUID.randomUUID.to_s
=> "e42ccfce-d6a0-4cb5-a0c0-9fae6ca05b84"
irb(main):003:0> UUID.randomUUID.to_s
=> "80a31bb3-3fce-4e6f-9c8a-5a819de45960"

Tuesday, September 18, 2012

VWDExpress 2012 goes green for F#

A week ago, Micsosoft announced about F# Tools for Visual Studio 2012 Express for Web in this blog. That is the biggest reason for using VWDExpress 2012 instead of VWDExpress 2010.
And This can install F# MVC4 tools.

Saturday, September 1, 2012

Autumn vacation 2012, and more...

I take a autumn vacation, and I encounter the training "personnel management on correspondence education" in this month :-<

So I suspend posts and comments to this blog for a moment. Resume will be September 18, 2012.