40 Lines URL Shortener App
Here is my another 40 lines simple ruby app, URL Shortener App.
I use a Base 62(0-9, A-Z, a-z) numbering system to represent the row id. And Fortunately, Ruby already has a library for it, The alphadecimal gem :)
%w(sinatra dm-core dm-migrations haml alphadecimal uri).each { |lib| require lib}
get '/' do haml :index end
get '/:url' do redirect Url.first(:id => params['url'].alphadecimal).origin end
post '/' do
uri = URI::parse(params['origin'])
raise "Invalid URL" unless uri.kind_of? URI::HTTP or uri.kind_of? URI::HTTPS
@url = Url.first_or_create(:origin => uri.to_s)
haml :index
end
class Url
include DataMapper::Resource
property :id, Serial
property :origin, String
def alias() self.id.alphadecimal end
end
configure do
DataMapper.setup(:default, "sqlite:///development.sqlite3")
DataMapper.auto_migrate!
end
__END__
@@ index
%html
%head
%title Klik - Url Shortener App
%body
%h1 Klik - Url Shortener App
- unless @url.nil?
%code= @url.origin
%a{:href => env['HTTP_REFERER'] + @url.alias}= env['HTTP_REFERER'] + @url.alias
%form{:action => '/', :method => 'POST'}
%input{:type => 'text', :name => 'origin'}
%input{:type => 'submit', :value => 'Pendekin!'}
Hello guys, its been a while since i last blogged about coding related stuff.
Now, I’d like to show you How simple and fun The Ruby Programming Language is.
I wrote Todolist with Sinatra (web framework) + DataMapper (db persistent) + Haml (view template) The total number of lines is just only 41, in a single file including the view template :)
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
require 'haml'
class Todo
include DataMapper::Resource
property :id, Serial
property :text, String
end
configure do
DataMapper.setup(:default, "sqlite:///development.sqlite3")
DataMapper.auto_migrate!
end
get '/' do
@todos = Todo.all
haml :index
end
post '/' do
Todo.create(:text => params['todo'])
redirect '/'
end
__END__
@@ index
!!!
%html
%head
%title Todo
%body
%h1 Todo
%ul
- @todos.each do |todo|
%li= todo.text
%form{:action => '/', :method => 'POST'}
%input{:type => 'text', :name => 'todo'}
%input{:type => 'submit', :value=> 'Todo!'}
The Real Wordpress to Tumblr Exporter
Usage: ruby therealwp2tumblr.rb [wpurl] [wpuser] [wppass] [tumblremail] [tumblrpass]
Redmine Tracker - Cara Install di Ubuntu
Saya ada Project baru dan saya tetapkan menggunakan Redmine Tracker instead of Bugzilla (default bug tracker di Balicamp) Redmine itu enaknya,
- tampilannya looks neat, bisa ganti2 themes
- ada pemisahan antara tracker untuk bug, feature, support, atau mau tambah apalagi, ga hanya melulu bug.
- last activity list (macam wall di facebook) jadi gampang liat perkembangan yg terjadi
- ada fitur forum, files, wiki, news, repository browser
- Calendar, Gant Chart Planning
- bisa nge track waktu kerja juga, bisa liat member kerja berapa jam setiap hari untuk suatu issue
- email & rss feed notification
- untuk repositorynya juga, ketika commit memberi pesan ditambahkan keywork refs/issueid #noissue bisa langsung muncul linknya ke issue bersangkutan di repository browser dan juga keliatan dilayar issuenya list revision2 hasil commit untuk issue tsb.
Nah, kemudian promo saya ini mungkin berhasil, dan ada satu project baru lagi, yg baru aja minta di installin Redmine juga.
Lansung ke topik utama. Berikut langkah2 installasi Redmine di Ubuntu
Installasi Ruby untuk berjalan di Apache HTTP :
- Pastikan apache2 telah di install
- Pastikan MySQL5 telah di install
- Install paket2 standard untuk kompilasi
$ sudo apt-get install build-essentials
- Install Ruby Enterprise Edition.deb (REE)download dari rubyenterpriseedition.com, libmysqlclient, libmysqlclient-dev
REE digunakan dari pada ruby dari ubuntu, karena REE diclaim lebih stabil dan hemat memory.
libmysqlclient bisa pake apt-get atau search di synaptic.
- Buat symlink dari installasi Ruby ke /usr/bin agar ruby dapat diexecute
$ sudo ln -sf /opt/ruby-blabla/bin/* /usr/bin
- pastikan ruby telah jalan
$ ruby -v
$ gem -v
- update rubygems (paket managernya Ruby) :
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
$ tar xzf rubygems-1.3.1.tgz
$ cd rubygems-1.3.1
$ sudo ruby setup.rb
$ gem -v
- install passenger (Apache Module agar Ruby dapat berjalan)
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
jika tidak ditemukan, jalankan langsung dari
$ cd /opt/ruby-enterprise/bin
$ sudo passenger-install-apache2-module
- Modifikasi apache2.conf untuk menambahkan module Ruby
$ sudo nano /etc/apache2/apache2.conf
tambahkan baris ini di dalamnya sebelum # Include the virtual host configurations
LoadModule passenger_module /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passeng$
PassengerRoot /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.0.6
PassengerRuby /opt/ruby-enterprise/bin/ruby
- restart apache
$ sudo /etc/init.d/apache2 restart
- Jika buka localhost sekarang sudah muncul footer, Phussion Passanger module berarti telah berhasil
Installasi Redmine :
- Ekstrak Redmine dimana saja misal : ~/myhome/redmine
$ cd redmine*
- tentukan koneksi database di app/config/database.yml (set dibagian production karena applikasi akan jalan di production)
- create database dan insert data.
dari root folder redmine :
$ rake db:create:all
akan membuat database sesuai setting di database.yml
$ rake db:migrate
akan meng insert data initial sql ke database
- set email.yml sesuaikan dgn smtp server anda. lagi2 dibagian production nya.
- script/server untuk menjalankan redmine dgn webserver internal ruby (Webrick)
cek apakah masih ada yg error. jika tidak berarti redmine siap di deploy ke ApacheHTTP
- jika masih error coba jalankan :
$ sudo rake gems:install
untuk install gems (library2) yg dibutuhkan oleh redmine
$ sudo rake gems:build
terkadang ada gems yg butuh build native sehingga harus menjalankan perintah tsb
- coba lagi script/server jika hingga sukses
Deploy Redmine ke ApacheHTTP
- buat symlink ke /var/www (docrootnya apache)
$ sudo ln -s ~/absolutepath_to_redmine/public /var/www/redmine
- modifikasi virtual host apache
$ sudo nano /etc/apache2/sites-enabled/000-default
tambahkan berikut RailsBaseURI /redmine (/redmine merupakan link yg kita create di /var/www):
NameVirtualHost *
Workshop Ruby on Rails @Balicamp
more detail visit http://www.facebook.com/event.php?eid=32430687965
Presentasi Ruby
Mau liat movienya ?
dpt nih hasil browse, lumayan, buat blajar presentasi
http://webcast.berkeley.edu/event_details.php?webcastid=20854
Java Ruby
“I always thought Smalltalk would beat Java. I just didn’t know it would be called ‘Ruby’ when it did” - Kent Beck
![Hello guys, its been a while since i last blogged about coding related stuff.Now, I’d like to show you How simple and fun The Ruby Programming Language is.
I wrote Todolist with Sinatra (web framework) + DataMapper (db persistent) + Haml (view template) The total number of lines is just only 41, in a single file including the view template :)
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
require 'haml'
class Todo
include DataMapper::Resource
property :id, Serial
property :text, String
end
configure do
DataMapper.setup(:default, "sqlite:///development.sqlite3")
DataMapper.auto_migrate!
end
get '/' do
@todos = Todo.all
haml :index
end
post '/' do
Todo.create(:text => params['todo'])
redirect '/'
end
__END__
@@ index
!!!
%html
%head
%title Todo
%body
%h1 Todo
%ul
- @todos.each do |todo|
%li= todo.text
%form{:action => '/', :method => 'POST'}
%input{:type => 'text', :name => 'todo'}
%input{:type => 'submit', :value=> 'Todo!'}](http://28.media.tumblr.com/tumblr_lf6jxcm6mE1qb6uwyo1_500.jpg)

