29 Sep 2009

Eclipse is not so great for Perl developers

Of course there is EPIC which is great - real IDE for writing in Perl, but when it comes to update whole IDE, all gets frustrating so what can I say: I really do not like the update system in Eclipse, for me is much faster to make:
rm -rf ~/projects/deps-eclipse/* ~projects/workspace-eclipse/.metadata/
Goto: http://www.eclipse.org/downloads/, download whole new source and install new version plus additional plugins (I use only SVN and EPIC). My problems are probably caused by high load on update server, which makes download of updates real slow, but this probably can be fixed in some way - for example adding some mirrors?

NetBeans support for Perl language is needed!

Dear NetBeans Team, please provide support for Perl (I really need only syntax highlighting, PerlCritic/PerlTidy, Error Reporting). This may gain some new users to IDE (last stuff about real alternative to Epic was from 2000, and it was commercial software. ARGH!) This is almost done in this plugin, but not all: http://netbeans.mojgorod.ru/perl.html. There was also other project (http://code.google.com/p/nbperl/) but it died even before starting.

Who cares about Perl6, new Parrot virtual machine if there is no real IDE support - think about it, Perl Developers. Or I should learn other scripting language which is supported by NetBeans IDE? Comments (in both Polish and English) are welcome.

28 Sep 2009

Images from space by NASA

If you are interested to see space (but not in Google Earth), you can download some pictures from space.com (thanks Elliot for posting URL). But if you are interested in images of Earth some high-resolution pictures can be found at http://visibleearth.nasa.gov/ (photos are REAL HUGE - resolution: 86400 x 43200) - Direct link to images.

Howto execute system commands in Perl and possible danger

There are various ways to run system subproces in Perl. I will mention only 7 - few native (exec(), system, qx{}/``) and few which use additional libraries (Open("|"), IPC::Open2, IPC::Open3, IPC::Cmd) which are in fact in standard Perl distribution so they can be used without worries.

Introduction

Most people think that running system command from Perl is only done by system() or exec(), but there are many ways to achieve this task - some are better some are worse. Each of them has different performance, even specific usage of function could increase/decrease performance. This post is written only to help programmer choose right solution for task (solution secure, flexible and with best performance).

Note: I am using in this article some (quite much) text which is copied from PerlDoc - it will be in tag: <cite>.

Executing system command - possible ways

  1. exec() - PerlDoc Page
  2. system() - PerlDoc Page
  3. qx{}/`` - PerlDoc Page
  4. Open(' |') - PerlDoc Page
  5. IPC::Open2 - PerlDoc Page
  6. IPC::Open3 - PerlDoc Page
  7. IPC::Cmd - PerlDoc Page
  8. IPC::Run - PerlDoc Page - not covered in this article (it's not part of standard Perl distribution) on Unix/Linux - AFAIK
If you don't want to scroll to summary or conclusion click hyperlink.

23 Sep 2009

Wget like progress bar in console

Some time ago I was writing about notifying user that our software does not hang out, today I will also write about this. It is easy to create progress bar, and there is a numerous modules done (Oreily.com). But creating a simple progress bar (which looks like progress bar in wget) is pretty straight forward.

Output with detailed progress

Warning: This is only example after each execution of progressBar "\n" is inserted!. In final code this will be one animating line!
johny@jambia:~$ perl pgbar.pl 
Starting Hello
[i] Hello |>                                                                     | 0 of 10 (  0%)
[i] Hello |======>                                                               | 1 of 10 ( 10%)
[i] Hello |=============>                                                        | 2 of 10 ( 20%)
[i] Hello |====================>                                                 | 3 of 10 ( 30%)
[i] Hello |===========================>                                          | 4 of 10 ( 40%)
[i] Hello |==================================>                                   | 5 of 10 ( 50%)
[i] Hello |=========================================>                            | 6 of 10 ( 60%)
[i] Hello |================================================>                     | 7 of 10 ( 70%)
[i] Hello |=======================================================>              | 8 of 10 ( 80%)
[i] Hello |==============================================================>       | 9 of 10 ( 90%)
[i] Hello |=====================================================================>|10 of 10 (100%)

Hello started

Output normal process bar

Warning: This is only example after each execution of progressBar "\n" is inserted!. In final code this will be one animating line!
johny@jambia:~$ perl pgbar.pl 
Starting Hello
[i] Hello |>                                                                             | (  0%)
[i] Hello |=======>                                                                      | ( 10%)
[i] Hello |===============>                                                              | ( 20%)
[i] Hello |=======================>                                                      | ( 30%)
[i] Hello |==============================>                                               | ( 40%)
[i] Hello |======================================>                                       | ( 50%)
[i] Hello |==============================================>                               | ( 60%)
[i] Hello |=====================================================>                        | ( 70%)
[i] Hello |=============================================================>                | ( 80%)
[i] Hello |=====================================================================>        | ( 90%)
[i] Hello |=============================================================================>| (100%)

Hello started

15 Sep 2009

Pomysł na projekt elektroniczny

Ostatnio natknąłem się na fajne urządzenie w sieci Królika Nabaztag, jak to zawsze jest z nowościami cena okazała się być strasznie wysoka ;). Ale wpadł mi do głowy pomysł, że można coś takiego zbudować samemu - jako, że nie lubię elektroniki daje tutaj tylko pomysł ;).

Funkcje

  • Informowanie o pogodzie
  • Informowanie o nowych mailach/twittach/blipach/rss-ach/aktywności znajomych na Facebook etc.
  • Możliwość puszczania muzyki
  • Możliwość odsłuchiwania wiadomości zostawionych przez znajomych
  • Pobieranie spotkań z Google Calendar i RTM - informowanie o nich

Hardware

  • Mikrofon - żeby działało mówienie 'Weather', 'Mails', etc. ;) - Taki self-made Nabaztag by informował na żądanie o wszystkim
  • RTC (Real Time Clock) - coś do liczenia czasu - żeby urządzenie nie hałasowało w nocy
  • Połączenie z internetem - WiFi/Etherent
  • 3/4 diody
  • 3/4 przyciski - power, mic enabled, mute, etc.
  • Głośniczek
  • Jakaś obudowa - najlepsza by była obudowa z Furbego
  • Arduino + WaveShield + ZigBee lub ARM 7 ;)

Software

  • Wysyłanie requestów HTTP - syntetyzator mowy - WebAPI Ivony
  • Wysyłanie requestów HTTP - RSS/Twitter/blip.pl/RTM/Google Calendar/Pogoda
  • Wysyłanie requestów IMAP/POP3 - poczta
  • Jakiś demon Cron by tym zarządzać
  • Odtwarzacz plików mp3 - by móc wykorzystać WebAPI Ivony

Refleksa

Czy taki zestaw ze zmodowanym Furby wyjdzie taniej niż Nabaztag? Zapewne nie, ale większość części będzie można użyć powtórnie do innych projektów jak to się znudzi :).

14 Sep 2009

On-line viewers for documents in various formats

Format: PDF/DOC/RTF/etc.

  • Google Online PDF Viewer - Example
    <iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" 
    style="width:600px; height:500px;" frameborder="0"></iframe>
  • Zoho Viewer - Example
    <iframe src="http://viewer.zoho.com/embed.jsp?f=mUMzg" frameborder="0" width="600" height="500"></iframe>
  • PDF Me Not - Example
    <script type="text/javascript" src="http://pdfmenot.com/embed/?url=http://infolab.stanford.edu/pub/papers/google.pdf&width=600&height=450"></script>
     
  • Scribid.com - embed a PDF/DOC/PPT and other using Flash
    <object 
      codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" 
      id="doc_429679487887851" name="doc_429679487887851" 
      classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 
      align="middle"
      height="500" width="100%">
        <param name="movie" 
          value="http://d1.scribdassets.com/ScribdViewer.swf?document_id=6266098&access_key=key-ox3gh562rcesp040675&page=1&version=1&viewMode=">
        <param name="quality" value="high">
        <param name="play" value="true">
        <param name="loop" value="true">  
        <param name="scale" value="showall">  
        <param name="wmode" value="opaque">   
        <param name="devicefont" value="false">
        <param name="bgcolor" value="#ffffff">
        <param name="menu" value="true">
        <param name="allowFullScreen" value="true">
        <param name="allowScriptAccess" value="always">
        <param name="salign" value="">
        <embed src="http://d1.scribdassets.com/ScribdViewer.swf?document_id=6266098&access_key=key-ox3gh562rcesp040675&page=1&version=1&viewMode=" 
          quality="high" 
          pluginspage="http://www.macromedia.com/go/getflashplayer" 
          play="true" 
          loop="true" 
          scale="showall" 
          wmode="opaque" 
          devicefont="false" 
          bgcolor="#ffffff" 
          name="doc_429679487887851_object" 
          menu="true" 
          allowfullscreen="true" 
          allowscriptaccess="always" 
          salign="" 
          type="application/x-shockwave-flash" 
          align="middle"  
          height="500" 
          width="100%">
      </embed>
    </object>

Books

Of course there is a way to embed a whole book in webpage. It can be done like this:
<script type="text/javascript" src="http://books.google.com/books/previewlib.js"></script>
<script type="text/javascript">
GBS_insertEmbeddedViewer('GkCpLIk7aisC',600,500);
</script>
There is an Google Book Search API and possibility to download books from Google Books Library Project using Google Book Downloader for Windows. But that is not all, everyone can publish own book at Google Books.

Presentations PPT/ODT/etc.

13 Sep 2009

Drzewo poszukiwań binarnych (BST) - implementacja w języku C

Uwaga: Artykuł ten pochodzi ze starej wersji mojego bloga - w chwili obecnej liczy on sobie już co najmniej 3 lata ;).

Czym są drzewa binarne

Drzewo binarne to jeden z rodzajów drzewa (struktury danych), w którym liczba synów każdego wierzchołka wynosi nie więcej niż dwa. Wyróżnia się wtedy lewego syna i prawego syna danego wierzchołka.

Do czego drzewa binarne są stosowane?

Drzewa ułatwiają i przyspieszają wyszukiwanie, a także pozwalają w łatwy sposób operować na posortowanych danych. Znaczenie tych struktur jest bardzo duże i ze względu na swoje własności drzewa są stosowane praktycznie w każdej dziedzinie informatyki (np. bazy danych, grafika komputerowa, przetwarzanie tekstu, telekomunikacja).

Drzewa składają się z wierzchołków (węzłów) oraz łączących je krawędzi. Jeśli drzewo nie jest puste, tzn. liczba wierzchołków jest większa od zera, jeden z nich jest wyróżniony i nazywany korzeniem drzewa.

Więcej o drzewach można przeczytać na stronach Polskiej Wikipedii, skąd w znacznej mierze pochodzi ten cytat.

Przykładowa reprezentacja drzewa poszukiwań binarnych

Tworzenie drzewa BST przebiega w następujący sposób:
  1. Jeśli drzewo BST jest puste to wstawiamy element jako korzeń (i omijamy następne punkty). Gdy drzewo nie jest puste to porównujemy wstawiany element z korzeniem.
  2. Jeżeli wartość elementu jest mniejsza od wartości porównywanego wierzchołka to przechodzimy do lewego syna, jeżeli zaś większa to do prawego syna (gdy równa to zależnie od tego jak sobie wybierzemy, byle konsekwentnie).
  3. Gdy tam gdzie "doszliśmy" nie ma żadnego wierzchołka to przechodzimy do następnego punktu. Jeżeli jednak znajduje się tam inny wierzchołek drzewa to musimy porównać go z wstawianym elementem i wrócić do punktu 2.
  4. Skoro doszliśmy do "wolnego miejsca" to właśnie tam wstawiamy nasz element. Oczywiście będzie om synem wierzchołka, z którego przyszliśmy (a czy lewym czy prawym to zależy od tego, w którą stronę poszliśmy z tamtego wierzchołka).
Drzewo dla liczb: [7, 11, 3, 10, 15, 1, 5, 4] wygląda w sposób następujący:

Getting system hardware and software info from Java

Sometimes there is a need to include in bug report information about user hardware/software, in Java it can be done using library SIGAR (System Information Gatherer And Reporter) or using informations provided by Runtime class and System.getProperty() method. Below is presented simple application (extreme simple - using only System.out.println()) created only to demonstrate which values can be pulled out from JRE.

6 Sep 2009

VMD Package Builder for Ubuntu and Debian

What is VMD?

VMD is designed for modeling, visualization, and analysis of biological systems such as proteins, nucleic acids, lipid bilayer assemblies, etc. It may be used to view more general molecules, as VMD can read standard Protein Data Bank (PDB) files and display the contained structure. VMD provides a wide variety of methods for rendering and coloring a molecule: simple points and lines, CPK spheres and cylinders, licorice bonds, backbone tubes and ribbons, cartoon drawings, and others. VMD can be used to animate and analyze the trajectory of a molecular dynamics (MD) simulation. In particular, VMD can act as a graphical front end for an external MD program by displaying and animating a molecule undergoing simulation on a remote computer.

Text above is copied from Official VMD Site

How build process of VMD Ubuntu package looks like?

$ bash vmd-package.sh vmd-1.8.7.src.tar.gz
Options chosen depends on this packages in Debian/Ubuntu

build-essential csh libstdc++5 libc6 libcc perl libglu1-mesa mesa-common-dev libgl1-mesa-dri libgl1-mesa-glx libglu1-mesa-dev xlibmesa-gl-dev fontconfig tk8.5-dev tk8.5 tcllib libfltk1.1 libfltk1.1-dev libxft2 libxft-dev python-netcdf python2.5 python2.5-dev libnetcdf-dev libnetcdf4 python-numpy

This script doesn't support resume!!!
If some packages are missing, you should run apt-get install command
Continue? [Y] - YES/ [N] - NO
y

#############################################################
12:51:34 Starting building process on vmd-1.8.7.src.tar.gz
#############################################################

12:51:35 Unpacking sources from vmd-1.8.7.src.tar.gz
12:52:13 Starting compilation of plugins. This may take a while ...
12:57:46 Compilation of plugins successful
         Copying plugins to /home/johny/Pulpit/vmd/vmd-deb/usr/local/lib/vmd/plugins/
12:57:53 Compilation of plugins completed successfully.
12:57:53 Starting build of VMD. This may take a while ...
         Running configure
         using configure.options: LINUX MESA TK TCL PTHREADS FLTK PYTHON NETCDF NUMPY
         Correcting Makefiles
         Starting compilation of main VMD program, this may take a while
         Compilation done.
         Starting copying of files to /home/johny/Pulpit/vmd/vmd-deb/
         Copying done.
13:03:33 Build process completed successfully

#############################################################
13:03:33 Starting build process of *.deb package
#############################################################

13:03:33 Creating and correcting misc stuff
         Patching files. (vmd)
         Creating VMD icon
         Making Debian Menu Entry
         Adding mime-support info
         Creating freedesktop.org desktop entry
         Adding freedesktop.org shared mime info entry
         Adding KDE MIME database entry
         Copying documentation ...
         Adding postinst and postrm scripts
         Generating control file
         Calculating MD5 sums
13:05:56 Building *.deb package
         13:06:44 Cleaning
13:07:11 Completed successfully. Package is ready to install.

To perform install run as root:
 dpkg -i vmd_*.deb

Where I can find Debian/Ubuntu vmd package builder?

Source can be obtained on my Google Code account.

How to use it?

  1. Download VMD sources from Official VMD page
  2. Download VMD package builder using command: wget http://0x1fff.googlecode.com/svn/trunk/public-projects/vmd-package-builder/vmd-package.sh
  3. Type in terminal: bash vmd-package.sh vmd-*.*.*.src.tar.gz
  4. Hit enter and read stuff on screen carefully

It's not working, what should I do?

  • Check if are dependencies are installed
  • Check version of VMD, and compare it with tested versions on begining of script
  • If there is a build problem with version lower than 1.8.7 it will not be probably fixed
  • Checkout "known bugs" and comments in this post
  • If you know how to fix it - just do it and send me path
  • If you do not know - write a comment below - bug report should be like this:
    Hello! :) I've found a bug in vmd-package.
    
    my Ubuntu/Debian version is: VERSION HERE
    my PC architecture is: ARCH HERE (if you don't know it's probably x86)
    my vmd-package version is: VERSION HERE
    my VMD version is: VMD VERSION HERE
    I'm trying to build VMD with these settings (compilation options): OPTIONS HERE
    I'm getting output like: OUTPUT HERE
    
    Here are compressed log directory: http://...URL.../
    
    Other informations, which you think might be helpful: FILL IT HERE
  • You should provide log directory (zipped or tarred) on some server - rapdishare.de, megaupload.com or other - because I might need it

Known bugs on Ubuntu/Debian package VMD builder

  1. Fails on other versions are probably due to paths in 1.8.7
  2. Correct it if you want - this won't be done in my release checkout function buildVMD() for more details and logs. (Probably it's something about include path to Python/NUMPY or TCL/TK in version 8.5 - try to use TCL/TK 8.4 or 8.3)
  3. VMD from this package is so sloow! It's true try to change parameter MESA to OpenGL (my laptop graphic card doesn't support OpenGL :()

Additional links about VMD