January 28, 2009

WTF?

...Perl, Some internal DSLs, Python, Java, Lisp, Groovy, Ruby, Lisp, Clojure

I read/write almost all of these everyday..WTF!

January 27, 2009

BOJUG Meet: January 2009

We are meeting this Saturday, 31st January for our monthly meet. Details here at http://bojug.in/blog/?p=37

NetBeans needs more love?

I am not looking to open a can of worms here. But this discussion  here set me thinking: Does the world need more NetBeans love?

How often do we see that a Eclipse plugin is the way to go for most products, and we don't have the same for NetBeans? Why is Eclipse preferred over NetBeans when a choice needs to be made. The little that I understand of this business of FLOSS, NetBeans is as much a FLOSS product as is Eclipse.

What are the reasons- technical, political or cult?

Just to set the record straight: I am a completely NetBeans Guy- community member, committer and associated with the project for over a year now.

Sun Folks on the loose: Go Grab Them

Unfortunately, I lost a lot of my Sun colleagues whom I knew directly or indirectly in last week's lay-off. The least I can do possibly is let the world know that great folks are available for hiring. Here's one:  David Van Couvering (Ted's blog post about him).


Related post by Ted: http://www.sauria.com/blog/2009/01/22/suns-loss-your-gain/

January 26, 2009

Registers in VIM and other cool stuff

In the VIM world, clipboards where your copied/cut text are stored are called registers. And, there can be multiple registers (which you can choose to name), where your text can be stored after you have performed a copy/yank on them. (See the section: Using multiple clipboards at http://jmcpherson.org/editing.html ).

Let's try this. Type in a couple of lines in VIM:









Now, select the lines and copy them to register 'r' using, "ry (in command mode).

Now type in the following VIM command: :echo @r. You should see the text that you have copied earlier:








This means that using '@r' you can use the contents of the register in your VIM scripts or plugins. We could also do some cool stuff, such as passing it to a GNU screen session, as you can see here. If you don't code in Lisp, no problem. You can use the script to setup your Python or Ruby or any other similar development needs, without any change.

January 23, 2009

Not working on 'odf4j'

I have left working on the ODF Toolkit for Java: odf4j project 8 months back. I finally kicked myself to tell this here since I see a lot of visits to my blog with the label 'odf4j'.

Hence, please go ahead to http://odftoolkit.openoffice.org/ for all your queries.
Sorry for the late notice.

January 22, 2009

NetBeans IDE + virtualenv= Your Python experimental bed

virtualenv is a tool to build sandbox(ed) or isolated Python environments. Using it you can create multiple isolated Python development environments each with their own isolated 'site-packages', which basically means giving yourself a playground which you might as well need during all the hacking. The page here http://pypi.python.org/pypi/virtualenv has a lot of details on how you can go about installing it and then creating your own sand boxes.

Here is what you would do on a Ubuntu box, if you have setuptools installed:

Installation:

$sudo easy_install virtualenv

Searching for virtualenv
Reading http://pypi.python.org/simple/virtualenv/
Best match: virtualenv 1.3.2
Downloading http://pypi.python.org/packages/2.5/v/virtualenv/virtualenv-1.3.2-py2.5.egg#md5=f2cd2b10b8be8b57e74cb1830fc0b504
Processing virtualenv-1.3.2-py2.5.egg
creating /home/amit/virtualenv-local/lib/python2.5/site-packages/virtualenv-1.3.2-py2.5.egg
Extracting virtualenv-1.3.2-py2.5.egg to /home/amit/virtualenv-local/lib/python2.5/site-packages
Adding virtualenv 1.3.2 to easy-install.pth file
Installing virtualenv script to /home/amit/virtualenv-local/bin

Installed /home/amit/virtualenv-local/lib/python2.5/site-packages/virtualenv-1.3.2-py2.5.egg
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv

Creating a isolated Python environment:

$ virtualenv --no-site-packages virtual-env-1
virtualenv --no-site-packages virtual-env-1
New python executable in virtual-env-1/bin/python
Installing setuptools............done.

The above command creates a new Python virtualenv with the name 'virtual-env-1' under your pwd. Couple of things to note:
  • --no-site-packages: This option makes sure that when you are using the Python interpreter, it will *not* look into the global site-packages for third party packages (See this discussion for more on this topic)
  • setuptools is installed automatically, so that you can start doing a easy_install (and more) in your Python environment just created
Okay, so your sandbox is ready. Let us see, what is in there:
.
|-- bin
| |-- activate
| |-- activate_this.py
| |-- easy_install
| |-- easy_install-2.5
| `-- python
|-- include
| `-- python2.5 -> /usr/include/python2.5
`-- lib
`-- python2.5
|-- UserDict.py -> /usr/lib/python2.5/UserDict.py
|-- UserDict.pyc -> /usr/lib/python2.5/UserDict.pyc
|-- codecs.py -> /usr/lib/python2.5/codecs.py
|-- codecs.pyc -> /usr/lib/python2.5/codecs.pyc
|-- config -> /usr/lib/python2.5/config
|-- copy_reg.py -> /usr/lib/python2.5/copy_reg.py
|-- copy_reg.pyc -> /usr/lib/python2.5/copy_reg.pyc
|-- distutils
| |-- __init__.py
| |-- __init__.pyc
| `-- distutils.cfg
|-- encodings -> /usr/lib/python2.5/encodings
|-- fnmatch.py -> /usr/lib/python2.5/fnmatch.py
|-- fnmatch.pyc -> /usr/lib/python2.5/fnmatch.pyc
|-- lib-dynload -> /usr/lib/python2.5/lib-dynload
|-- locale.py -> /usr/lib/python2.5/locale.py
|-- locale.pyc -> /usr/lib/python2.5/locale.pyc
|-- no-global-site-packages.txt
|-- ntpath.py -> /usr/lib/python2.5/ntpath.py
|-- ntpath.pyc -> /usr/lib/python2.5/ntpath.pyc
|-- orig-prefix.txt
|-- os.py -> /usr/lib/python2.5/os.py
|-- os.pyc -> /usr/lib/python2.5/os.pyc
|-- posixpath.py -> /usr/lib/python2.5/posixpath.py
|-- posixpath.pyc -> /usr/lib/python2.5/posixpath.pyc
|-- re.py -> /usr/lib/python2.5/re.py
|-- re.pyc -> /usr/lib/python2.5/re.pyc
|-- site-packages
| |-- easy-install.pth
| |-- setuptools-0.6c9-py2.5.egg
| `-- setuptools.pth
|-- site.py
|-- site.pyc
|-- sre.py -> /usr/lib/python2.5/sre.py
|-- sre.pyc -> /usr/lib/python2.5/sre.pyc
|-- sre_compile.py -> /usr/lib/python2.5/sre_compile.py
|-- sre_compile.pyc -> /usr/lib/python2.5/sre_compile.pyc
|-- sre_constants.py -> /usr/lib/python2.5/sre_constants.py
|-- sre_constants.pyc -> /usr/lib/python2.5/sre_constants.pyc
|-- sre_parse.py -> /usr/lib/python2.5/sre_parse.py
|-- sre_parse.pyc -> /usr/lib/python2.5/sre_parse.pyc
|-- stat.py -> /usr/lib/python2.5/stat.py
|-- stat.pyc -> /usr/lib/python2.5/stat.pyc
|-- types.py -> /usr/lib/python2.5/types.py
`-- types.pyc -> /usr/lib/python2.5/types.pyc

10 directories, 45 files
The directory tree is pretty straight forward and spend some time looking at it. Now you can do two things:
  • Make this the default Python interpreter, using 'activate_this.py'
  • or, simply refer to it using the full pathname, such as : ~/virtual-env-1/bin/python

Using 'virtualenv' on NetBeans IDE for Python:

Coming to the main focus of this post, you can use your newly created virtualenv with the NetBeans IDE for Python. Just add a new platform using Tools > Python Platforms > New:















Once added, you can verify the Python Path:















Now, you can either make it the default platform or make your use of this platform for your selected experimental projects!

Your Python test bed is ready!

January 21, 2009

DTrace + NetBeans IDE + Python

The DTrace plugin for NetBeans brings the DTrace Toolkit and DTrace Chime to NetBeans on OpenSolaris. The DTrace toolkit ships with some utility scripts to talk with the Python DTrace providers.

Once you have installed the DTrace plugin, open Window > DTrace and in the Toolkit tab, choose Python:


You can see the various D scripts there. Let us take the script, 'py_calltime.d', which will collect and display the time in us taken by each function call for a particular running Python process, whose PID you can supply during the run of the script, or start a Python process.

Here is a sample output:


With the ever developing Python support for NetBeans, you can start having some fun with Python, NetBeans and DTrace.

January 20, 2009

Disco + NetBeans IDE

Disco is a Open-Source implementation of the Map-Reduce framework, written in Erlang. Where as the framework is written in Erlang, Python is used to write the jobs (See glossary) for the framework. That is the link between NetBeans and Disco- Python. Agreed, there is another link, (http://wiki.netbeans.org/Erlang), but I will take the first.

After you have got your setup ready,  (which is pretty damn simple), fire up NetBeans IDE with the Python bits installed:

  • Create a New Python Project, say PyDisco. Name the main file as 'wc-py.py
  • Right-Click on the project > Properties > Sources, and add the pydisco, directory which you can find in the Disco tarball ('pydisco' is the Python package in which the Python API for Disco is defined)

  • Now, in the file 'wc-py.py', copy the contents of the file 'count_words.py' from http://discoproject.org/doc/start/install.html
  • Right-Click on the project > Properties > Run and in the Application Argument box, type in http://localhost:7000
  • Now, Run the Project
In the output window, you should see this message:

Starting Disco job..
Go to http://localhost:7000 to see status of the job.

When you open the browser, you will see something like this:


Of course, this was just a way to show you how you can use NetBeans IDE for your development using Disco.

January 17, 2009

Hatching Python Eggs from NetBeans

Support for building Python eggs  (IZ #150283) from NetBeans IDE is now available in the repository. (Refer this link to see how you can clone the repository and build the Python bits). Please try it and file bugs and suggestions here

Now, I would like to talk a bit of Python Eggs and how to use the NetBeans IDE to build Eggs for your Python packages.

A Python Egg is to Python as JAR is to Java or a 'gem' is to Ruby. It comprises of your code, resources and all important metadata- version, dependency information, etc. All the gory details are here at http://peak.telecommunity.com/DevCenter/PythonEggs


Use case in NetBeans
  • Right-click on the Python project name and select 'Build Egg'
  • If you already have a setup.py file (Please refer the 'assumptions' section below) , and a do a 'Build Egg' it uses that. (Do a 'Clean & Build Egg' to create a default setup.py file. If you don't have a setup.py, one is created for you
  • The process can be tracked in the 'Output' Tab
  • Once the build process is over, you will see the the 'egg' has been deposited in the 'dist' directory (accessible in the 'Files' View)

It is not viewable from the 'Projects' view as it unnecessarily clutters the view.

Egg Formats

As you can see from the above view, there is also a file, EggDemo.egg-info, which is another format for Python Eggs as mentioned in http://peak.telecommunity.com/DevCenter/EggFormats

The wiki page has some more information.

Assumptions

These have to assumed, because that is the way it has to be:

  1. You have setuptools installed
  2. Your setup.py file lives in the top level directory- src or your existing sources' root directory
  3. Your packages or sub-packages (those containing __init.py__) are actually in the sub-(sub)-directories under your top-level directory, in which setup.py lives

January 16, 2009

Congratulations NetBeans

...for the Developer.com 2009 awards

Go Figure!

This is a line of CL and its o/p:
(format nil "~r" 5666666666666666656556)

"five sextillion six hundred sixty-six quintillion six hundred sixty-six quadrillion six hundred sixty-six
trillion six hundred sixty-six billion six hundred sixty-six million six hundred
fifty-six thousand five hundred fifty-six"

Uber cool ! I came across the -R directive while reading Chapter 3 of Practical Common Lisp

PS: If you want to learn CL, the best place to start would be Practical Common Lisp

January 15, 2009

Mid-air collision

...Mid-air collision detected! Someone else has made changes to this issue at the same time you were trying to...

Anyone of you NetBean'er ever got this?  Try to reproduce..Fun!

January 12, 2009

Book Review: Programming Erlang, Software for a Concurrent World

To quote Joe Armstrong, author of the book Programming Erlang:

" The World is Parallel.

If we want to write programs that behave as other objects behave in the real world, then these programs will have a concurrent structure.

....

Erlang programs model how we think and interact "

This, in addition to all the buzz about Erlang, the CouchDB project and my interests in Concurrency and Distributed programming motivated me to pick up the lone copy of the book (available at my current den for book hunting) and add it to my growing library. I will be reading this book, over a period of time (Just as I am doing with Practical Common Lisp). Here you can find the chapter wise reviews of this book.

Let's begin.

Chapter 1: Begin

This chapter is, what you would call the pitch for the book and the introduction to the rest of the book. So, why should you bother to learn yet another programming language? You should, if (here are some of them):
  • You want to write programs which run faster when you run them on a multi-core computer
  • You want to write fault-tolerant applications that may be modified on the go without disrupting its execution (A bit of look-ahead into the chapter reveals that in Section 16.1: The Road to the Generic Server, the author talks about techniques of writing such an application)
  • You want to learn and see Functional Programming in real-world action
Here are some notes from the rest of the chapter:
  • Erlang is all about Concurrency-oriented programming. Concurrency is built into the language, rather than depending on the native operating system.
  • Erlang is all about modelling concurrency and mapping those models onto computer programs
  • In the Erlang world, there are parallel processes, which interact by pure message passing- no shared memory, and hence no shared memory corruption- no locks, no mutexes
The chapter ends with acknowledgements from the author.

Chapter 2:Getting Started
The chapter starts off with a short roadmap for learning Erlang. Next couple of pages in the chapter are dedicated to getting your Erlang development environment ready by installing the Erlang compilers and libraries.

The author, then starts of some Erlang programming with the Erlang command interpreter- Erlang shell:
Erlang (BEAM) emulator version 5.6.5 [source] [smp:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.5 (abort with ^G)

After some play, two very important Erlang concepts are introduced:
  1. Erlang has variables that do not vary

  2. '=' is not an assignment operator. That is, 'X=6' does not assign 6 to X. It is in fact pattern matching. A expression like 'X=6' is actually checking if RHS=LHS. When Erlang encounters such an operation with X for the first time, it binds 6 to X. X is now bound. Now any further attempt to bind X to another value will result in an error like this (You may get a different error message; see errata: http://www.pragprog.com/titles/jaerlang/errata) :** exception error: no match of right hand side value 6

Here is a simple Erlang session to better illustrate Erlang's variable binding/pattern matching:

Erlang (BEAM) emulator version 5.6.5 [source] [smp:2] [async-threads:0] [hipe] [kernel-poll:false]
re>r
Eshell V5.6.5 (abort with ^G)
1> X = 10.
10
2> X = 6.
** exception error: no match of right hand side value 6
3> X = Y.
* 1: variable 'Y' is unbound
4> X = 6.
** exception error: no match of right hand side value 6
5> Y = 10.
10
6> Y = 11.
** exception error: no match of right hand side value 11
7> X = X=1.
** exception error: no match of right hand side value 1
8> X = X + 1.
** exception error: no match of right hand side value 11
9> X = Y.
10

Next, data structures/types like atoms, tuples, lists and Strings are introduced. Unification- extracting variables using pattern matching is discussed.

Strings in Erlang:

10> [97, 99, 122].
"acz"
11> [97, 99, 123].
"ac{"
12> [98, 99, 123].
"bc{"
13> [90, 99, 123].
"Zc{"
14> [1, 99, 123].
[1,99,123]

The chapter ends with a tabular recap of pattern matching and using it for unification.

Chapter 3: Coming up

January 9, 2009

Book Review: A Byte of Vim

A Byte of Vim is a freely available, immensely useful and well written book on Vim which has made me more confident of using only the keyboard with Vi(m). I am not getting into a detailed review of the book, rather I will simply refer to the best (IMO) portions of the book.

The Introduction begins in a way, a thrilling flick would, by showing you the best of the ammo that you can get to watch during the rest of the movie.

The next few chapters talk about installation of Vim, the Vim modes and basic moving around tips.

Editing basics and More Editing talk heavily about yanking and more in Vim.

Multiplicity talks about tabs and a lot more in Vim. Reading this chapter will help you in working with multiple files in a single Vim instance.

Scripting and Plugins shows you how you could increase your productivity with Vim.

How can you set up your programming environment with Vim ? Programmer''s Editor helps you in that quest. Vim as an IDE?

More points some great resources to Vim scripts and resources.

This book definitely has increased by knowledge and confidence about Vim. It's well worth your bookshelf (in your room or your computer)

January 8, 2009

Poor man's Hash table

Property lists or plists in Lisp is the poor man's hash table, and allows you to associate values with properties, like:
(list :black 0 :white 1) , which associates 'black' with value '0' and 'white' with 1.

Values can now be retrieved from the plist using 'getf':
CL-USER> (getf (list :black 0 :white 1) :black)<br />0<br />CL-USER> (getf (list :black 0 :white 1) :white)<br />1<br />
If you have more than one value associated with a property, the value which is at the left most is returned:

CL-USER> (getf (list :a 5 :a 1 :a 4 :b 3) :a)
5

plists are introduced in the third chapter of Practical Common Lisp which I am currently reading. (Review)


Do you really want to wear underwear that's in perpetual beta? Ouch!

...so says a comment on the story http://tech.slashdot.org/article.pl?sid=09/01/07/1844239 at ./

January 6, 2009

Getting my feet wet

I have been getting my feet wet working with the Python support in NetBeans for sometime now. After a couple of commits on my behalf by Tor and Jean-Yves, I did the first push myself after I got access to the 'main' repository. Woohoo!

Tor's quick Mercurial tip IS a life saver: http://blogs.sun.com/tor/entry/mercurial_tip_checking_in_regularly

I am all set to get drenched.