rioastamal.net

Just things inside my head…

Archive for the ‘Tutorial’ Category

Tutorial: Updating Twitter Status via Shell Script

Posted by rio On February - 9 - 2010

The Goal

Updating twitter status via shell script. The command used to send the HTTP request is POST a.k.a lwp-request (a perl script) that included in most linux distribution.

Twitter Status Update

The Process

  1. Open your text editor i.e. gedit/geany/etc or even vi you are die hard fans of this editor.
  2. Copy and paste code below.

    #!/bin/bash
    #
    TUNAME="lesstalkme"
    TUPASS=""
    TSTATUS=""
    TURL="http://twitter.com/statuses/update.xml"
    TDATA="source=LTME&status="
     
    # print some fancy header :)
    echo "-----------------------------------------"
    echo "         Twitter Status Updater"
    echo " http://www.less-talk-more-example.info/"
    echo "------------------------------------------"
     
    echo -n "Twitter Password: "
    read -ers TUPASS
    echo -e "\nEnter Twitter Status:"
    read TSTATUS
     
    # replace some characters ( I'm too lazy to replace all the characters :))
    TSTATUS=`echo $TSTATUS | sed 's/ /%20/g'` # space => %20
    TSTATUS=`echo $TSTATUS | sed 's/@/%40/g'` # @ => %40
    TSTATUS=`echo $TSTATUS | sed 's/\//%2F/g'` # / => %2F
    TSTATUS=`echo $TSTATUS | sed 's/:/%3A/g'` # : => %3B
    TSTATUS=`echo $TSTATUS | sed 's/#/%23/g'` # # => %23
     
    # now POST the data
    echo ""
    echo -n "Updating status..."
    echo "${TDATA}${TSTATUS}" | POST -C $TUNAME:$TUPASS $TURL | grep $TUNAME > /dev/null
    # check status
    # ------------
    # successfull request always return XML format that containts our username
    # so we grep that to check the status
    if [ $? -eq 0 ]; then
      echo "DONE."
    else
      echo "ERROR."
    fi
  3. Replace TUNAME value with your own username.
  4. Save to somewhere i.e. /tmp directory just for testing.
  5. Name it twitter.sh
  6. Open the shell terminal in GNOME System » Application » Terminal
  7. Go to /tmp directory and give execute permission to the file.
    $ cd /tmp
    $ chmod +x twitter.sh
  8. Execute the file, you’ll be promted to enter twitter password and status.
    $ ./twitter.sh
  9. Fill it and voila!! your twitter status has been updated :).
    Twitter Status

Screencast



Download the Code

twitter.sh.zip via ziddu.com.
Size: 0.69kb
MD5 Checksum: f9d38c632430a617331cc4f8d298fcf1

Source:
http://www.less-talk-more-example.info/2010/02/update-twitter-status-via-shell-script.html

bookmark bookmark bookmark bookmark bookmark bookmark

Mengganti Hostname pada Distro Berbasis Debian

Posted by rio On November - 17 - 2009

hostname notePernahkah ada keinginan dari anda untuk mengganti hostname dari sistem anda. Biasanya ketika kita menginstall misal distro ubuntu hostname kita akan menjadi username-laptop dsb. Nah bagaimana kita mengubahnya? Caranya sebenarnya cukup simple. Buka terminal anda klik Application » Accessories » Terminal

lug@username-laptop:~$ sudo gedit /etc/hostname

Nah disitu ada nama dari hostname lawas anda, ganti dengan yang baru misal stikom-surabaya. Sistem seharusnya mengupdate otomatis file /etc/hosts karena ada perubahan di /etc/hostname namun untuk memastikan buka saja file tersebut:

lug@username-laptop:~$ sudo gedit /etc/hosts

Cari string hostname lama anda jika ada lalu ganti ke hostname yang baru. Untuk mengecek kita dapat menggunakan perintah sysctl.

lug@username-laptop:~$ sysctl kernel.hostname
kernel.hostname = stikom-surabaya
lug@username-laptop:~$

Agar tampilan prompt bash juga berubah silahkan buka session bash baru dengan menekan kombinasi Ctrl-Shift-T. Seharusnya tampilan hostname pada bash akan berubah menjadi yang baru.

lug@stikom-surabaya:~$

Selamat Mencoba ;)

bookmark bookmark bookmark bookmark bookmark bookmark

Sorry if there are any spelling or grammatical errors, I’m learning English… :)

Before I start, Let me explain what google android is, taken from android official distribution.

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

Pre-Installation

You must have Java and Apache Ant installed to make android fully works(especially for development). You can refer to my other article about installing Java and Apache on Ubuntu Linux here:

My Environment

  • My $HOME is located in /home/astadev
  • I put android package in $HOME/archive/a
  • I extract the package to $HOME/programs
  • My Android SDK version is 1.1 Release 1

Installation

Download the latest version of Google Android at http://www.android.com/. I save it to $HOME/archive/a. The archive in ZIP format. So we need to extract it using unzip command.

$ unzip ~/archive/a/android-sdk-linux_x86-1.1_r1.zip -d ~/programs/
$ cd programs
$ ln -s android-sdk-linux_x86-1.1_r1 android

The last command is to make symbolic link to directory android-sdk-linux_x86-1.1_r1. So, you can also access the directory in $HOME/programs/android. It will make directory more easy to read and quite useful in development.

Running The Emulator

The easiest way to test your installation is to run the Android Emulator. The emulator located inside the tools/ directory. Follow the instruction below to run the emulator.

$ cd ~/programs/android/tools/
$ ./emulator

Note: Be patient, it takes quite longtime to be fully loaded even with my Intel core2 duo and 1GB of RAM.

As an alternative you can create a launcher(short-cut) on your Desktop. I assume your Desktop is using GNOME. Although it will be quite similar to other Desktop like KDE or XFCE.

  1. Right click on your desktop
  2. Choose Create Launcher…
  3. Fill “Android Emulator” in Name field
  4. On Command field fill it with “/home/astadev/programs/android/tools/emulator” (without quote and make sure the path is point to the correct directory of your android installation)
  5. Click OK
  6. Double click the launcher to test it

Here’s the screenshot. To flip the orientation of the emulator use combination of CTRL+F11.

Google Android Emulator

Reference:
Android Official Site

bookmark bookmark bookmark bookmark bookmark bookmark

Lama gak nulis dalam Bahasa Indonesia nulis lagi ah… :)

Salah satu audio player yang sangat populer di X Window adalah XMMS. Bagi sebagian orang mungkin menganggap bahwa XMMS sudah tua dan dan tidak lagi terupdate. XMMS versi terakhir adalah 1.2.11 yang dirilis tahun 2007(Minor Update). Developer XMMS sendiri sudah tidak berniat untuk membuat versi terbarunya. Sayang sekali :(. Namun bagi saya pribadi belum ada player lain yang mampu membuat saya “berpaling hati” :).

Berbagai player sudah saya coba di Linux mulai dari bawaan standard Ubuntu seperti Rythmbox, Banshee, Audacious, dll. Namun masih belum sreg juga. Terutama dari sekian banyak player tersebut output volumenya tidak sekeras XMMS pada laptop saya, meskipun sudah dipasang plugin tambahan untuk audio boost dan kawan-kawannya. Yang ada malah suaranya pecah.

Ok, langsung saja ke topik artikel ini yaitu bagaimana membuat plugin yang menampilkan lyric dari lagu yang sedang diputar. “Senjata” andalan saya masihlah shell script :). Sebenarnya ide ini sudah lama saya pendam(hehe… kayak cinta aja dipendam) karena tersandung masalah males dan kelupaan jadi ya baru kesampaian sekarang. Sebelum ini saya sudah mencoba plugin lyric bernama “singit” tapi gak tau kenapa kok g bisa. Jadi ya buat sendiri deh, meski sederhana yang penting “muncul” :). Toh lyric ini kan kita lihat waktu gak fokus sama pekerjaan.

Assumption

Asumsi saya adalah anda sudah menginstall XMMS. Jika belum silahkan pergi ke situs http://www.xmms.org/ disana juga terdapat paket debian/ubuntu dan repositorynya.

My Environment

  • OS: Ubuntu Linux 8.04
  • Desktop Environment: Gnome
  • GTK+ Dialog: Zenity
  • XMMS: Versi 1.2.10
  • Song Change Plugin: Versi 1.2.10
  • Path Script: /home/astadev/shellscript/xmms-lyrics.sh
  • Direktori Lyric: /media/sda11/feisty/SecondHome/personal/lyrics/

Note: Song Change Plugin merupakan plugin general dari XMMS, jadi seharusnya sudah terinstall secara default.

Step by Step

1. Menulis Plugin

Langkah pertama tentu adalah membuat pluginnya terlebih dahulu. Buka teks editor lalu salin kode berikut:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
 
# function to convert space to dash and UPPERCASE to lowercase
function toLowerHypen() {
   # take all the string
   the_string=$*
   echo "$the_string" | tr [:blank:] "-" | tr "[A-Z]" "[a-z]"
   return
}
 
# function to split "singer - song" format
function splitSingerSong() {
   the_format=$*
   # see man IFS
   IFSdef=$IFS
   IFS="-"
   declare -a tempdata=($the_format)
   IFS=$IFSdef
   singer=${tempdata[0]}
   song=${tempdata[1]}
}
 
splitSingerSong $*
# trim
singer=`toLowerHypen $singer | tr -s " "`
song=`toLowerHypen $song | tr -s " "`
 
# change lyric_dir according to your own setting
lyric_dir="/media/sda11/feisty/SecondHome/personal/lyrics"
 
lyric_file="${lyric_dir}/${singer}/${song}.txt"
lyric_content=
 
if test -f "$lyric_file"
then
  lyric_content=`cat "$lyric_file"`
else
  lyric_content=`echo -e "Lyric File Not Found\n\n($lyric_file)"`
fi
 
# get previous process and kill it
zenity_proc=`cat /tmp/xmms.lyrics.pid`
kill -9 $zenity_proc > /dev/null 2> /dev/null
 
sleep 0.1
zenity --notification --text="$lyric_content" & 
echo $! > '/tmp/xmms.lyrics.pid'

Ganti nilai dari lyric_dir sesuai dengan letak direktori lyric anda nantinya. Simpan file ini, dalam contoh saya simpan pada /home/astadev/shellscript/xmms-lyrics.sh. Selanjutnya kita memberikan permission execute untuk file ini.

$ chmod +x /home/astadev/shellscript/xmms-lyrics.sh

Note: Sesuaikan dengan lokasi file anda.

2. Mengaktifkan Script Melalui Plugin Song Change

  1. Klik kanan XMMS
  2. Pilih Options » Preferences
  3. Pilih tab General Plugins
  4. Pilih Song Change 1.2.10
  5. Centang Enable Plugin pada pojok kanan bawah
  6. Klik Configure
  7. Pada Command xmms start a new song
  8. Isikan lokasi script anda, pada contoh: /home/astadev/shellscript/xmms-lyrics.sh
  9. Klik OK » Apply » OK

general plugins Song Change Plugin

4. Membuat File Lyric

Agar plugin dapat menemukan file lyric sesuai dengan penyani dan judul lagunya. Maka perlu adanya konvensi(aturan) dalam membuat file lyric. Sebuah contoh, misal nama artisnya Michael Heart dan judul lagunya We Will Not Go Down maka struktur direktorinya adalah:

  • Lyric Dir: /media/sda11/feisty/SecondHome/personal/lyrics/
  • Artist Dir: michael-heart
  • File Name: we-will-not-go-down.txt

Nama artis dan judul lagu harus HARUS ditulis dalam huruf kecil(lowercase) dan spasi diubah menjadi tanda “-” (hypen). Judul lagu harus berakhiran dengan ekstensi “.txt”. Dalam contoh diatas lokasi lengkap dari lyric adalah:

/media/sda11/feisty/SecondHome/personal/lyrics/michael-heart/we-will-not-go-down.txt

5. Let’s Test The Plugin

Sediakan sebuah file lyric untuk sebuah lagu, lalu mainkan lagu tersebut. Lihat pada System Tray akan muncul sebuah icon notifikasi. Arahkan mouse tersebut ke icon notifikasi maka akan muncul lyric dari lagu tersebut.

Plugin Test

Selamat Mencoba :).

PS:
- Thanks to Michael Heart, your powerful song and lyric makes me write this plugin.
- Script ini juga bisa digunakan untuk Audacious

Referensi:
http://www.xmms.org/
http://www.rioastamal.net/files/ebook/tutorial-mini-shell.gz

bookmark bookmark bookmark bookmark bookmark bookmark

Tutorial: How to Create Simple Telephone Application

Posted by rio On November - 29 - 2008

Sorry if there are any spelling or grammatical errors, I’m learning English… :)

This afternoon while searching about XML for my assignment, I came across to the term “VoiceXML”. Well, that term sounds strange to me but some of you may have heard it or even have been master on VoiceXML :). “How can an XML structure produce some voice?” is a question that came across my head. According to the wikipedia the definition of VoiceXML is:

VoiceXML (VXML) is the W3C’s standard XML format for specifying interactive voice dialogues between a human and a computer. It allows voice applications to be developed and deployed in an analogous way to HTML for visual applications

So, what things that we need to build our first telephone application. Not much here the list:

  • Account at voxeo.com
  • A web server to host your VoiceXML document
  • Skype software
  • Text Editor

Here step-by-step how to build your first telephone application.

1. Create an account at voxeo.com

Voxeo.com is a company that provide IVR (Interactive Voice Response) hosting and all related voice application including VoIP. Start creating account by clicking this link evolution.voxeo.com. Complete all the steps to get an account.

2. Install Skype Software

Skype is the most popular VoIP application. Download the latest version at Skype.com, in this tutorial I’m using Skype for Ubuntu Linux.

3. Create the VoiceXML file

Using your favorite text editor create a new file and write code below:

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1" >
  <form>
    <block>
    <prompt>
      Hello there, enjoy my blog.
    </prompt>
    </block>
  </form>
</vxml>

Save the file, in this example I named the file “hello.xml”.

Code above shows that we use VoiceXML version 2.1. Keep in mind all tags like <form>, <block> are differ from HTML tag. Sentences inside prompt tag will be read by the voxeo IVR.

4. Upload the VoiceXML file

The next step is to upload the file to web server so Voxeo server can grab and read the file. If you don’t have a hosting account, byethost.com is a good and free web hosting service you may try. After uploading the file just remember the location, in this example my VoiceXML file located at http://rioastamal.net/voice/hello.xml.

5. Creating the Application at Voxeo

After logged into voxeo member area, follow these steps:

  1. click Account => Application Manager
  2. click Add Application
  3. On Development Platform choose Prophecy 8.0 - VoiceXML 2.1
  4. click Next
  5. Fill “Hello Blog” at Application Name
  6. Fill “http://your-url-to/hello.xml” at Start URL 1
  7. click “Create Application”

Click the “Phone Numbers” tab to get your application phone number. Take a look at Skype VoIP phone number. That is number you should call from skype in order to test your application.

Voxeo phone settings

6. Testing the Application

The last step is testing our application. Testing the application is easy, we just need to call the number from Skype or other VoIP software. Let’s try it:

  1. Open Skype
  2. Click “Call ordinary phones”
  3. Enter your Application phone number
  4. Click dial (green phone button)
  5. You should hear sentences that you wrote before.

If you want to test my application, just dial this number on your Skype +99000936 9991424802. You may ask, how much the charge when calling these number from skype? The good news is Voxeo and Skype have been partnership. So, you don’t have to pay when calling your application :).

call a number  calling number

References
http://en.wikipedia.org/wiki/VoiceXML
http://www.voicexml.org/
http://www.vxml.org/

bookmark bookmark bookmark bookmark bookmark bookmark

Tutorial: How to Install Apache Ant on Ubuntu Linux

Posted by rio On October - 14 - 2008

Sorry if there are any spelling or grammatical errors, I’m learning English… :)

On my last article I’ve show you how to install Java Development Kit(JDK) on Ubuntu Linux. In this tutorial we will try to install Apache Ant or Ant in short. Before going more deeper, some of you may ask, What is ant?

Apache Ant is a software tool for automating software build processes. It is similar to make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects.

If you ever try building some application from source in Linux, I bet you have used build tool called make. Ant is very similar to it but Ant use XML based configuration for it’s build process. Ant is also used internally by NetBeans IDE to compile project. OK, enough talk let’s install Ant.

My Environment

  • My $HOME is located in /home/astadev
  • I put Ant package in $HOME/archive/a
  • I extract the package to $HOME/programs
  • My Ant version is 1.7.1

Pre-Installation
You must have Java installed first, go to my Java installation tutorial if you have not install Java yet.

Installation
Download the latest version of Ant from http://ant.apache.org. Saved to some location e.g: I save to $HOME/archive. First we need to extract the package.

$ tar -jxvf ~/archive/a/apache-ant-1.7.1-bin.tar.bz2 -C ~/programs
$ cd programs
$ ln -s apache-ant-1.7.1 ant

Note: if your ant package in .gz format use -zxvf instead.

The next step is to add Apache Ant directory to shell environment variables. So we need to edit .bashrc file located in our home directory.

$ gedit ~/.bashrc

Put this at the end of .bashrc file, after editing your file look something like this:

JAVA_HOME=/usr/local/java
JAVA_BIN=$JAVA_HOME/bin
ANT_HOME=/home/astadev/programs/ant
PATH=$PATH:$JAVA_HOME:$JAVA_BIN:$ANT_HOME/bin
export PATH

Save the file, and then open new bash session by pressing CTRL-Shift-T. Try to execute ant.

$ ant
Buildfile: build.xml does not exist!
Build failed

Error? No. Error above indicate that ant command is recognized by shell but it did not find build.xml file that needed to compile ant projects. So, it’s absolutely normal and the installation was successful.

Comment and feedback are welcome :).

References:
http://ant.apache.org/
http://en.wikipedia.org/wiki/Apache_Ant

bookmark bookmark bookmark bookmark bookmark bookmark

Tutorial: How to Install Java on Ubuntu Linux

Posted by rio On October - 2 - 2008

Sorry if there are any spelling or grammatical errors, I’m learning English… :)

By default ubuntu comes with pre-installed Java Runtime Environment called gij (The GNU Java bytecode interpreter). But gij interpreter known to be not compatible with some Java code. So, most of linux user update their JVM to Sun JVM.

Basically we have two methods to install Java/JDK on ubuntu. The first is using apt-get command that will install Java through ubuntu repository, and the second one is manually install Java using traditional method “unpack and run”. The first method is the most easiest way to install Java, but the package(Java version) maybe quite out of date. My recommendation is to use the second method since it provide you the latest JDK version. Let’s try the first method.

Install using apt-get

Open your terminal(Application - Accessories - Terminal) then type:

$ sudo apt-get install sun-java6-jdk

Note: We are using sun-java6-jdk not sun-java6-jre since I assume we are going to use it to develop Java programs not only for running the programs.

Follow the instruction to complete the instalataion. Done? yeah what do you expect more? we are in debian world :). Then we need to check whether the Sun JVM is properly installed or not by typing:

$ java -version

You should get information about your current JVM. The JVM should provided by Sun NOT gij anymore. Now let’s move to the second method.

Install using “unpack and run” method

In this method off course you need to download the JDK package from Sun’s Website. Go to http://java.sun.com/ and grab the latest JDK version. In this tutorial I use JDK version 1.6.0 Update 7. Download the file jdk-6u7-linux-1586.bin and save it to some location e.g: /home/user/jdk-6u7-linux-1586.bin.

Open the terminal to extract the package, move to the saved location first:

$ cd /home/user
$ sh jdk-6u7-linux-1586.bin

You will be asked “License Agreement” and type yes to Agree. After you complete those steps a folder named “jdk1.6.0_07″ created. Now, I don’t want to run jdk from my home folder, so I move it to /usr/local. Since /usr/local is owned by root we need sudo command.

$ sudo mv jdk1.6.0_07 /usr/local
$ sudo ln -s /usr/local/jdk1.6.0_07 /usr/local/java

The second command ln -s is used to make symbolic link. Now you can also access /usr/local/jdk1.6.0_07 with /usr/local/java.

We have successfully install the new JDK, but when type java -version the current JVM is still gij. So, how do I change this? We need to tell the shell that we want to use our JDK located in /usr/local/java not the gij, for that purpose we use update-alternatives command.

$ update-alternatives --list java
/usr/bin/gij-4.2

After running that command we knew that there is no alternative for java. So, we need to add our new JDK to the alternatives. Since we are modifying the system, sudo command is needed to do so.

$ sudo update-alternatives --install /usr/bin/java java /usr/local/java/bin/java 100
$ sudo update-alternatives --config java
There are 2 alternatives which provide `java'.
 
  Selection    Alternative
-----------------------------------------------
*         1    /usr/bin/gij-4.2
 +        2    /usr/local/java/bin/java
 
Press enter to keep the default[*], or type selection number: 2
$ java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)

For more information about update-alternatives see the manual page man(1) update-alternatives.

Now let’s test our new environment, for this purpose we will create simple Java program. Open your favorite text editor, e.g gedit (Application - Accessories - Text Editor) and try this following code.

1
2
3
4
5
public class Hello {
   public static void main(String[] args) {
      System.out.println("Hello World!") 
   }
}

Save it to some location, since this is only a test I would recommend to save it under /tmp directory. I name it Hello.java. Now go back to the terminal and compile the file using javac command.

$ cd /tmp
$ javac Hello.java
bash: javac: command not found

Oops…, what am I missing? No you don’t, the are few steps that we did not completed yet :). We need to add /usr/local/java in shell environment variables by editing .bashrc file located in our home directory.

$ gedit ~/.bashrc

Add the following lines into .bashrc (put these code at the end of file).

JAVA_HOME=/usr/local/java
JAVA_BIN=$JAVA_HOME/bin
PATH=$PATH:$JAVA_HOME:$JAVA_BIN
export PATH

Save the file and close the editor. Now we need to close our Terminal to take affect. Open the terminal again and try to compile Hello.java. All the things should work :).

$ cd /tmp
$ javac Hello.java
$ java Hello
Hello World!

Comment and feedback are welcome… :)

bookmark bookmark bookmark bookmark bookmark bookmark

Tutorial: Membuat “Kata Bijak Hari Ini” Saat Start-up

Posted by rio On August - 15 - 2008

Kadang sebuah aplikasi menampilkan “Tip of The Day” saat ia dijalankan. Salah satu program yang melakukannya adalah program favorit saya yaitu GIMP. Pada tutorial kali ini kita akan membuat sebuah fitur yang hampir mirip “Tip of The Day” tapi berisi kata-kata bijak yang dalam bahasa kerennya wise word. “Kata-kata bijak hari ini” nantinya akan tampil saat anda memasuki GNOME.

Sama seperti sebelumnya kita tetap menggunakan shell script untuk membuat aplikasi mini ini. Kita juga memanfaatkan satu aplikasi kecil untuk keperluan ini yaitu zenity. zenity sudah include secara default pada distribusi GNOME di ubuntu.

Berikut ini adalah kodenya:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
#
 
# buat array untuk daftar kata-kata bijak
kata[0]="Takut akan kegagalan seharusnya tidak menjadi alasan untuk tidak mencoba sesuatu.\n\nKepemimpinan adalah Anda sendiri dan apa yang Anda lakukan."
kata[1]="Kejujuran adalah batu penjuru dari segala kesuksesan, Pengakuan adalah motivasi terkuat.\n\nBahkan kritik dapat membangun rasa percaya diri saat \"disisipkan\" diantara pujian."
kata[2]="Jika Anda dapat memimpikannya, Anda dapat melakukannnya.\n\nIngatlah, semua ini diawali dengan seekor tikus, Tanpa inspirasi.... kita akan binasa."
kata[3]="Uang merupakan hamba yang sangat baik, tetapi tuan yang sangat buruk."
kata[4]="Sumber kekuatan baru bukanlah uang yang berada dalam genggaman tangan beberapa orang, namun informasi ditangan orang banyak."
kata[5]="Jenius adalah 1 % inspirasi dan 99 % keringat. Tidak ada yang dapat menggantikan kerja keras.\n\nKeberuntungan adalah sesuatu yang terjadi ketika kesempatan bertemu dengan kesiapan."
kata[6]="Ketika satu pintu tertutup, pintu lain terbuka, namun terkadang kita melihat dan menyesali pintu tertutup tersebut terlalu lama hingga kita tidak melihat pintu lain yang telah terbuka."
 
lastword=
 
# cek apakah file tempat konfigurasi ada atau tidak
ls $HOME/.wiseword > /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
   # jika tidak ada maka tulis 0 sebagai angka awal
   echo 0 > $HOME/.wiseword 
fi
 
lastword=`cat $HOME/.wiseword`
 
zenity --info --text="<b>Kata Bijak Hari Ini</b>\n\n<i>${kata[$lastword]}</i>" 
 
# hitung panjang array
num_kata=${#kata[@]}
 
if [ `expr $lastword + 1` -ge $num_kata ]; then
   echo 0 > $HOME/.wiseword
else
   echo `expr $lastword + 1` > $HOME/.wiseword
fi

File ini saya simpan di $HOME/autorun/katabijak.sh. Setelah selesai menyimpan jangan lupa untuk memberikan permission execute pada file katabijak.sh.

$ chmod +x katabijak.sh

Sekarang saatnya memasukkan script kita pada session start-up GNOME. Carannya klik System > Preferences > Sessions. Lihat gambar berikut untuk lebih jelas.

gnome sessions

Untuk mengetesnya silahkan log out dari GNOME lalu login kembali. Dibawah ini adalah salah satu contoh output dari “Kata Bijak Hari Ini”.

kata bijak hari ini

Lumayan memberikan spirit ketika kita membaca kata-kata bijak tersebut. Bagi anda yang mengelola lab komputer yang menggunakan Sisem Operasi Linux anda dapat menggunakan teknik ini. Itu yang saya lakukan :).

Sumber kata bijak:
http://www.geocities.com/s_tato/wiseword.html
http://simriv.blogspot.com/2007/11/kata-kata-bijak-dari-ceo-kelas-dunia.html

bookmark bookmark bookmark bookmark bookmark bookmark

Bahasa pemrograman apa saja yang sudah pernah anda gunakan? C, C++, PHP, Perl, Java, VB, atau yang lain? Apa kesamaan bahasa-bahasa pemrograman tersebut? Tentu kesemua bahasa pemrogrman tersebut menggunakan syntax dalam bahasa Inggris. Pada artikel ini saya akan coba menunjukkan kepada anda bagaimana membuat bahasa pemrograman yang menggunakan syntax bahasa Indonesia, meski sebenarnya ini hanyalah teknik “goblok-goblokan” saja :).

Jadi nantinya kita dapat menuliskan 'jika [ kondisi true ] maka blablabla…’ daripada 'if [ kondisi true ] then blablabla…’. Tertarik?

Bahasa pemrograman yang akan kita buat sebenarnya merupakan sebuah shell script. Pada shell script terdapat sebuah tool yang sangat berguna yaitu alias. Dengan program alias kita dapat memberikan nama lain untuk sebuah perintah. Dan tahukah anda bahwa perintah ls juga sebenarnya adalah alias dari perintah ls --color=auto.

Nah, karena shell script juga memiliki struktur percabangan dan perulangan maka kita dapat membuat sebuah program menggunakan shell script. Perintah alias kita gunakan untuk memberi nama lain pada syntax shell script yang berhubungan dengan pembuatan program seperti echo, if, then, dan lain-lain. Berikut ini adalah alias yang saya gunakan untuk meng-Indonesiakan shell.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
#
# file alias untuk meng-"indonesia"-kan shell script
#
 
alias jika='if'
alias maka='then'
alias seltu-jika='elif'
alias selain-itu-jika='elif'
alias selain-itu='else'
alias seltu='else'
alias kaji='fi'
alias akhir-jika='fi'
 
alias kasus='case'
alias dalam='in'  # in tidak dapat diganti :(
alias suska='esac'
alias akhir-kasus='esac'
 
alias lakukan='do'
alias selesai='done'
 
alias selama='while'
alias untuk='for'
 
alias fungsi='function'
 
alias cetak='echo'
alias baca='read'
 
alias kembalikan='return'
alias hentikan='break'
alias keluar='exit'

Dalam komputer saya file ini saya letakkan pada direktori $HOME/shellscript/indoalias.sh. Jadi setiap script yang ingin menggunakan bahasa Indonesia harus meng-include file tersebut. Berikut ini adalah sebuah shell script sederhana untuk mengetes bahasa pemrograman baru kita :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# include alias
. $HOME/shellscript/indoalias.sh
 
# contoh percabangan sederhana
cetak "---- CONTOH PERCABANGAN -----"
username=""
password=""
 
cetak -n "Masukkan username: "
baca username
cetak -n "Masukkan password: "
baca -ers password
 
cetak ""
 
jika [ "$username" == "rio" -a "$password" == "astamal" ] ; maka
   cetak "LOGIN BERHASIL"
selain-itu
   cetak "LOGIN GAGAL"
kaji
 
# contoh looping sederhana
cetak -e "\n-------- CONTOH PERULANGAN ---------"
untuk (( i=1; i<=5; i++ ))
lakukan
   cetak -n "$i "
selesai
 
cetak ""
 
jawaban=0
jawaban_user=-1
selama [ $jawaban -ne $jawaban_user ]; lakukan
   angka1=$[ $RANDOM % 200 ]
   angka2=$[ $RANDOM % 500 ]
   jawaban=`expr $angka1 + $angka2`
 
   cetak -n "Hasil dari $angka1 + $angka2 adalah: "
   baca jawaban_user
 
   cetak ""
   jika [ $jawaban -ne $jawaban_user ]; maka
      cetak "Jawaban SALAH, yang benar adalah $jawaban"
   akhir-jika
selesai
 
cetak "Jawaban Benar..."

Dan berikut ini adalah outputnya:

astadev@astadev-laptop:/tmp$ sh tes.sh 
---- CONTOH PERCABANGAN -----
Masukkan username: rio
Masukkan password: 
LOGIN BERHASIL
 
-------- CONTOH PERULANGAN ---------
1 2 3 4 5 
Hasil dari 158 + 408 adalah: 444
 
Jawaban SALAH, yang benar adalah 566
Hasil dari 71 + 151 adalah: 121
 
Jawaban SALAH, yang benar adalah 222
Hasil dari 72 + 415 adalah: 45
 
Jawaban SALAH, yang benar adalah 487
Hasil dari 151 + 187 adalah: 338
 
Jawaban Benar...
astadev@astadev-laptop:/tmp$

Bagaimana lumayan keren kan?? saya gunakan ini untuk mengajari keponakan saya yang masih duduk di kelas 5 SD dia jadi suka sama komputer :). Selamat mencoba…

bookmark bookmark bookmark bookmark bookmark bookmark

Tutorial: Mengambil Screenshot GDM

Posted by rio On July - 5 - 2008

Anda tentu sering mendengar kata screenshot, bagi yang belum mengetahui apa screenshot tersebut, pengertian screenshot adalah suatu gambar yang diambil dari apa yang terlihat di layar komputer kita baik itu seluruh layar, window tertentu, atau bagian tertentu (geometri) dari layar. Semua sistem operasi secara default menyediakan fungsi ini. Cara paling mudah dan sederhana untuk mengambil screenshot adalah dengan menekan tombol PrtSc SysRq pada keyboard laku paste ke program pengolah gambar seperti MS Paint(Windows) atau GIMP(Linux).

Pada tutorial kali ini saya akan membahas bagaimana mengambil screenshot pada sistem operasi Linux(Ubuntu 8.04) lebih tepatnya screen login Gnome (GDM). Jika kita ingin mengambil screenshot setelah kita login pada Gnome itu hal mudah, tinggal tekan tombol PrtSc SysRq lalu paste di GIMP, beres. Masalahnya baru muncul ketika kita ingin mengambil screenshot dari screen login itu sendiri, kita tidak bisa langsung menekan tombol lalu paste begitu saja, hal ini karena kita belum login jadi mana mungkin kita dapat membuka program semacam GIMP. Terus bagaimana caranya? dari hasil googling terdapat dua metode untuk meng-capture screen GDM, yaitu:

  1. Menggunakan program gdmthemetester
  2. Menggunakan shell script untuk otomatisasi pengambilan screenshot

Cara yang akan saya tunjukkan adalah cara yang kedua yaitu menggunakan shell script. Berikut adalah langkah-langkahnya:

  1. Buat sebuah file baru menggunakan teks editor misal, takeshot.sh
  2. Ketik kode dibawah ini:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
#
# Simple shell script to take screenshot
# By Rio Astamal : 05-Jul-2008
#
 
executor=`whoami`
timestamp=`date +%s` # UNIX timestamp
defname="/tmp/scshot${timestamp}.png"
myuname="astadev"  # CHANGE this with your own username
delay=3  # delay before screenshot taken (in second)
if [ "$executor" != "root" ]; then
   echo 'You MUST run this script as root!.'
   exit 2
fi
 
function usage() {
   echo "Usage: $0 [file_name]"
   echo "Example: "
   echo "$0 /tmp/scshot.png"
   return
}
 
if [ $# -gt 0 ]; then
   if [ "$1" == "--help" ]; then
      usage ; exit 2
   else
      defname=$1
   fi
fi
 
ls $defname 1>/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
   # file is exists make a copy of it
   newfile=${defname}.bak.$timestamp
   cp $defname $newfile
   echo "Old file was copied to $newfile."
fi
 
chvt 7      # more info see man chvt
sleep $delay
XAUTHORITY=/var/lib/gdm/:0.Xauth DISPLAY=:0.0 import -window root $defname
 
if [ $? -eq 0 ]; then
   chown ${myuname}:${myuname} $defname 2>/dev/null
   echo "DONE: Screenshot saved to ${defname}."
else
   echo "ERROR: Make sure you have write permission on that directory."
fi
 
# EOF
  1. Log out dari session sekarang
  2. Ketika muncul screen login tekan kombinasi Ctrl-Alt-F2
  3. Login dengan username dan password anda
  4. Jalankan script dengan menggunakan perintah:
    • sudo sh takeshot.sh, atau
    • sudo sh takeshot.sh /tmp/myscreenshot.png

Dari script di atas baris yang paling penting adalah baris nomor 42. Pada baris tersebut terdapat perintah import -window root $defname, perintah inilah yang kita gunakan untuk mengcapture screen. Program import merupakan salah satu program yang ada pada paket ImageMagick.

Kebanyakan user yang mengambil screenshot dari GDM adalah para GDM theme creator. Nah karena saya bukan theme creator, saya mengambil screen GDM karena saya membuat halaman My Desktop pada blog ini yang menampilkan tampilan Desktop Ubuntu saya :). Ini contoh hasilnya:

My GDM

Referensi:
http://ubuntuforums.org/archive/index.php/t-239810.html
http://bbs.archlinux.org/viewtopic.php?pid=294833
http://forums.fedoraforum.org/showthread.php?t=122058

bookmark bookmark bookmark bookmark bookmark bookmark