Alphabet Loop

Sometimes during day to day work, you may want to render A to Z navigation link, you don't have to type them one by one. Just using "A" to "Z" loop. Like this :

Rails :

PHP :

Filed under  //

Comments [0]

Bilangan Prima

Java

Python

Ruby

Haskell

Comments [5]

MySQL & PostgreSQL RubyGem Installation on Fresh Install Snow Leopard

There's no big difference between Mac OSX Leopard and Snow Leopard environment for Rails stacks. You should upgrade your XCode to the latest XCode (version 3.2.x) or get it from Snow Leopard Installation DVD. Then you should be able to install MySQL and PostgreSQL gem smoothly on Snow Leopard.

Comments [0]

Paperclip Run Function Bug?

Sudah sebulan lebih rasanya file gambar yang memiliki nama file dengan karakter spasi " " tidak bisa diupload, saya kira ada masalah dengan browser atau ImageMagick. Selalu error 'File is not recognized by the 'identify' command', sudah juga mencoba solusi seperti dalam posting di sini.

Akhirnya setelah saya coba jalankan command identify di server langsung dan tidak ada masalah, saya coba menginstall plugin paperclip dan menggunakan plugin dibanding paperclip gem dan mencoba menelusuri codenya, ternyata masalahnya sederhana seperti ini:

file paperclip.rb yang original

file paperlcip.rb hasil modifikasi yang file_name_bug_free

Alhamdulillah!

Filed under  //

Comments [1]

Playing With Ruby Meta Programming

irb(main):001:0> require 'meta-test.rb'
=> true
irb(main):002:0> ["one", "two", "three"].repeat(3)
=> ["one", "one", "one", "two", "two", "two", "three", "three", "three"]
irb(main):003:0>

irb(main):003:0> %w{one two three four five six seven eight nine ten}.remove("i","o")
=> ["ne", "tw", "three", "fur", "fve", "sx", "seven", "eght", "nne", "ten"]

Meta Programming with Ruby is fun, isn't it? :)

Filed under  //

Comments [0]

Rails Tips : Prawnto PDF Generator Dynamic File Name

I was confuse how to generate dynamic file name for prawn generated pdf file, because there's lack of example and document here http://cracklabs.com/prawnto/demos.

What is Prawnto? Prawnto is is a rails plugin leveraging the new prawn library to produce compiled pdf views, as for me i'm using it for custom reporting tools. OK, let's getting back to the problem, what should you do is place prawnto definition in your method rather than in controller's callbacks : # /app/controllers/transactions_controller.rb

# /app/views/transactions/show.pdf.prawn

Hope this is useful, cheers :)

Filed under  //

Comments [0]

Ruby Tips : Mengubah Isi Array Menjadi Tipe Data Tertentu

Sebagai contoh kita ingin menggabungkan dua buah Array dengan elemen yang bervariasi, misalnya String dan Integer dan membuang elemen yang duplicated. Ilustrasinya sebagai berikut :
x = [1, 2, 3, 4]
y = ["1", "2", "3", 5]
Array x memiliki elemen dengan tipe data Integer sedangkan Array y memiliki String dan Integer yang sebenarnya jika String tersebut diubah tipe datanya menjadi Integer akan memiliki elemen yang hampir sama dengan Array x. Lalu bagaimana cara agar ketika kedua Array tersebut digabungkan kita mendapatkan Array dengan data yang unik? Caranya sangat sederhana dan cukup satu baris saja di Ruby : Dari String ke Integer
irb(main):003:0> z = (x+ y).flatten.collect { |i| i.to_i } 
=> [1, 2, 3, 4, 1, 2, 3, 5]
irb(main):004:0> z.uniq
=> [1, 2, 3, 4, 5]
Dari Integer ke String :
irb(main):005:0> z = (x+ y).flatten.collect { |i| i.to_s }
=> ["1", "2", "3", "4", "1", "2", "3", "5"]
irb(main):006:0> z.uniq
=> ["1", "2", "3", "4", "5"]
Atau bahkan Float
irb(main):007:0> z = (x+ y).flatten.collect { |i| i.to_f }
=> [1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 5.0]
irb(main):008:0> z.uniq
=> [1.0, 2.0, 3.0, 4.0, 5.0]
Demikian, semoga bermanfaat :)

Filed under  //

Comments [0]

Jakarta.rb December 2009

The last meeting Jakarta.rb in 2009 is going to be:

When:
Saturday, December 12nd at 10 AM
Where:

detikcom office Gedung Aldevco Octagon Lt. 2,
Jl. Warung Jati Barat Raya No. 75
Jakarta Selatan
Google Map Link

Call me: 0818-0308-1790 if you get lost. The building is across the street from the Pizza Hut Warung Buncit and Buncit Indah Busway Shelter.

The entrance to the building is in back by the parking lot.

Topics:

We will have 2 presentations no longer then 30 minutes each:

We are opening open submission, we welcome all your resources (codes, videos, documentations, slides, presentation) for our next meetup

Filed under  //

Comments [0]

Jakarta.rb Oktober 2009

Our next meeting is Saturday, October 17th, 10 AM at Detik meeting room and we’ve got three great talks lined up.

First up Daniel Armanto (Koprol) will be giving a talk on Rails Deployment Using Capistrano, we will discuss the Rails deployment, along with a short demo.

Next up Gerry Leo Nugroho (Product Planner - Detik) will be giving a presentation titled "Internet Product Planning, A Procedure". And Michael Smith (Klasifikasia) will close our presentation section with his presentation about Rails Deployment with Vlad and Mercurial.

Looking forward to hangin with you guys at the meeting, hopefully see you there. You can RSVP via Facebook Event

Filed under  //

Comments [0]