Feb 1, 2012

Setup The Ultimate Development Environment: Emacs, Clojure, Leiningen and Git

Clojure is a wonderful language.  And Emacs is an unbelievably powerful editor beast which you can easily get addicted to after you have tamed it.
However it's not easy for a newbie to customise Emacs to her needs.  I'll show you how to setup a full development environment for Clojure in Emacs with Git integration, Javadoc lookup and Leiningen powerful build tool for Clojure.  My examples will be for Ubuntu family (Ubuntu, Xubuntu, Kubuntu, Lubuntu) but you can easily use the idea for the Linux distro you use.

  1.  Install Emacs
Piece of cake! Fire up the terminal and issue the following:
$ sudo apt-get install emacs23
  2.  Install Leiningen
For a complete guide please see Leiningen on Github.
Download Leiningen installer script and put it in a directory.  I personally, have a Programs directory in my home; so I put the script in /home/bahman/Programs/Leiningen.  Change the permissions of the script to be executable either using your favourite file manager or using command line as below:
$ chmod +x DIRECTORY_YOU_HAVE_PUT_THE_SCRIPT_IN/lein
 Now at the command line, cd to the directory you have put the script in and run
$ ./lein self-install
and wait a short while for Leiningen to download the needed JAR files.

   3.  Install Slime
Now it's time to download SlimeRemember that you cannot use the version shipped with your distro.  Only a specific version of Slime works with Leiningen.

At a command prompt run
$ git clone https://github.com/technomancy/slime/
and then copy the slime directory which git just created to the desired place.  Again, I put it under /home/bahman/Programs .

Now open ~/.emacs in your favourite editor and add this at the end of the file:
(add-to-list 'load-path "PATH_TO_SLIME/")
(add-to-list 'load-path "PATH_TO_SLIME/contrib/")
(require 'slime)
(slime-setup '(slime-fancy))
(slime-setup '(slime-repl))

  4.  Install Elpa (Emacs package manager)
For a more complete guide see Elpa installation guide.
Run Emacs.  In the *scratch* buffer type this
  (let ((buffer (url-retrieve-synchronously
        "http://tromey.com/elpa/package-install.el")))
  (save-excursion
    (set-buffer buffer)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (eval-region (point) (point-max))
    (kill-buffer (current-buffer))))
then press ALT+x and type eval-buffer.



Close Emacs.  Open ~/.emacs.d/init.el in your favourite text editor (create the file if it doesn't exist yet) and  paste this in the file to add Marmalade package repository to Emacs.
(require 'package)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
Open ~/.emacs too and add this at the end and save it.
(when
    (load
     (expand-file-name "~/.emacs.d/elpa/package.el"))
 (package-initialize))
Run Emacs.  Press ALT+x and type package-list-packages and hit ENTER.  A list of packages that can be installed is shown.  Navigate to a package named clojure-mode and press i followed by x.  Voila!  It's done!

  5.  Test Your Installation
At a command prompt (assuming you have added ~/.lein to your $PATH and have cd'ed to the desired directory) run $ lein new myproject.  Run Emacs.  Press ALT+x followed by cd.  Now enter the directory of the project you just created with Leiningen and hit ENTER.  Now type ALT+x again followed by clojure-jack-in.  If you get a warning about Slime version (just ignore it), this means that you have setup everything correctly so far.




  6.  Git Integration
If you haven't installed Git yet, run this at the command prompt to do so
$ sudo apt-get install git
 We'll use Egg for integration of Emacs and Git.  Clone the Egg repository like this
$ git clone https://github.com/bogolisk/egg.git
and copy the egg directory to ~/.emacs.d


Open ~/.emacs in your favourite editor and add this to the end of it
(add-to-list 'load-path (expand-file-name "~/.emacs.d/egg"))
(require 'egg)
Restart Emacs and it's all done.

  7. Javadoc Lookup
This is a real handy and neat feature: browsing Javadocs inside Emacs!

Fire up Emacs, press ALT+x and type package-list-packages followed by ENTER.  In the packages list, navigate to the package named javadoc-help.  Type x followed by i.  After the package is installed.  Open ~/.emacs in your favourite text editor and add this to the end of it to enable javadoc-help.
(require 'javadoc-help)

By default, javadoc-help opens the documentation pages in the default desktop Browser which is probably the almighty Firefox.  But it's better to read and navigate the docs inside Emacs itself.  To do so, you need to install a console-based browser named w3m and its Emacs interface.
$ sudo apt-get install w3m w3m-el-snapshot

Now let's configure Emacs to use w3m for browsing.  In Emacs, press ALT+x and type customize-variable followed by ENTER.  Then type browse-url-browser-function followed by ENTER. In the customisation buffer that just opened change the value of the "Value Menu" drop-down to "Your own function".  Then in the box in front of it type w3m-browse-url.  Then press both "Set for current session" and "Set for future sessions" buttons (make sure they are pressed!) and then press "Exit".






By default javadoc-help loads documentations from the internet but if you're on a slow connection like me, that's not an option.  To tell javadoc-help to load them from your hard drive, in Emacs press ALT+x and type javadoc-help followed by ENTER.  In the javadoc-help buffer press f and type the path to the local javadocs "api" directory and then press CTRL+g.

That's it!  From now on, anytime you need to check the documentation for a class just press ALT+x and type javadoc-lookup.

  8.  Final Word
You just setup your Emacs to become a powerful Clojure development environment.  But that's not all.  Emacs has many many more features which you can start to get your hands on by reading its comprehensive help pages.  But first start by reading Emacs Tutorial from the Help menu :-)

  9.  Stay Tuned!
I will share some of my useful customisations of Emacs, in a different post soon.

Apr 25, 2011

What is ERP?

No matter if you're an excutive office, IT consultant, software developer or a business manager, you've heard people talk about ERP in meetings and sessions.  And probably a half-dozen of ERP providers have already come knocking at your office door to present their products.

No doubt that you have spent hours searching the internet on what exactly is an ERP and how can it help an organisation.  But if you're still in doubt, this writing may help you.  I'll try to explain the golden characterisitics of an ERP in a simple language; so please bear with me.

The Definition
ERP is an integrated, business process oriented and best practice based information system that helps managers better understand the situation of their organisations.

So a software that is called an ERP is:
  1. Intergrated
  2. Business process oriented
  3. Best practice based
and its ultimate goal is to help managers make more efficient decisions.

Integrated (Data)
In an integrated software, what one user does in a organisation can be immediately seen in another organisation by another user.

For instance, in a trade firm, as soon as a purchase invoice is entered and approved, it may immediately effect the product cost and accounts payable and change the P/L.  In such a system, when receiving a customer payment, the finance user can instantly check for which invoice this payment is happening and what are the payment terms.  Upon entering and approving the payment, the customer's receivables decreases and at the same time the sales staff may be notified.
Figure 1: Sample Integrated Information System (note that there is only one place to store/retrieve data)

The subtle point is that those series of events take place without requiring an administrator.  In other words, it is easily and flawlessly possible because all the software data resides in a single logical place and there is no clutter.

Business Process Oriented
From ERP point of view, the performance of your organisation is the result of execution of several business processes each of which covering a slice of your organisation and involving different layers of that slice to do the job; just like a slice of cake which cuts through different layers of the cake.

For example, in a trade firm, the sales business process involves sales, finance and procurement (if needed) departments and in each of them one or more users or organisation roles play a key role in performing the process.  Look at figure 2:

Figure 2: An exampe of business process oriented view of organisational perforamnce
As you can clearly see, sales business process involves the whole organisation in worst case.  If we look closely, we can understand how being integrated helps; for example a requisition is created based on sales order, a purchase order is created based on the requisition and purchase invoice is issued as a consequence of a sales order and all the links of this chain of actions are stored in one logical place, meaning that there is no need for any extra action from the staff; they just need to do their job which is running the process.

Now look at figure 3:

Figure 3: Information back-link in ERP

As a result of data integration and mapping organisational performance to business process execution we have a consistent chain of documents which enable us to accurately find out the reason/root of any organisation acitivity at any given time.

Best Practice Based
It is possible that a software taking advantage of a good design reach the above characteristics.  But in that case, still there is something missing to enable the software to help managers in the best possible way: best practice knowledge.

What distinguishes ERP from myriad of softwares claiming the same achievements, is extensive amount of best practice used in its design and configuration; meaning that ERP offers you the most efficient strategies -which have been tested in real life by prominent firms- to manage your organisation.  In fact, from this point of view, ERP is the medium to transfer the optimum management strategies/techniques from successful and well-known firms to others.

This characteristic is vital to an ERP as the only idea behind an ERP is to help managers, manage their organisations better and that is not possible without using optimum strategies.

Helping with Optimum Management
You may wonder why a software company would bother spend considerable amout of money, take a lot of risks and create a software with all the above characteristics?  And why a business manager would think of implementing such an expensive and giant software?

There is a simple rationale:  approaching optimum organisational management.

After a successful implementation, a manager is able to analyse her organisation's performance and accurately find out its weaknesses and strengths and decided how to imporove or use them.  And that is what a manager should do: making decisions.

By handling all the complexity of an integrated data flow, simplifying access to organisational performance information and offering the manager with accurate and up-to-date information, it enables the manager to concentrate on analysing and decision making without wasting her own and her staff's precious time dealing with technical details and report preparation headache.

Consequences
Let's suppose you have successfully implemented ERP in your organisation and it's running smoothly.  What are the benefits for you (as a top-level manager)?

  1. ERP integrated data model makes activities more transparent and enables users to access their required information at any time in a real-time manner.  The sales officer doesn't need to call finance dept. by phone to know the open amount of a customer:  ERP gives her what she needs right on time.  As a result, work hours are used more efficiently and personnel do their job based on accurate and real-time information.  This means more accurate and efficient performance for your organisation.
  2. Business process based analysis of your organisation provided by ERP, helps you discover the bottlenecks faster and more accurate.  For example, a drop in sales does not always mean the sales staff are incompetent; it may be because of the delay in procurement which eventually leads to late delivery and customer unhappiness.  With ERP you look at your organisation from above as a collection of (usually) inter-connected business processes not as a handful of separate departments.
  3. Using best practices in every day business is a key factor to your organisation success!  Now, thanks to ERP you can simply adopt the most efficient strategies taken from sucessful companies.  For example if you are the manager of an automotive business firm, you can enjoy the best practices applied by Mercedes Benz and that is a 100% win -unless you're the Benz's manager herslef :-)
Conclusion
ERP is an information system which is integrated, business process oriented and based on best practices and its main audience/beneficiaries are top-level managers. Successful use of ERP makes your organisation operate faster and more accurate and considerably improves your understanding of the performance of  your organisation.  ERP makes space for you to do your job: making decisions.

Apr 12, 2011

Persian Utils

I'll do this in a telegraphic manner since it's too late and my eyes are burning with sleep.

I've created a repository on GitHub named persianutils.  The goal is to put the solution to the Persian locale specific problems I encounter out there so it might help others from searching the net for hours.

Currently there's a module calendar.py which implements date conversion from Persian to Gregorian calendar and vice versa.

Mar 30, 2011

Good vs. Bad & Ugly: Comprehensive vs. General Design

Let's assume a simple categorisation of business into trade and manufacturing.
Most of the companies that are active in a category, arrange and manage their processes - despite different fields of business- inspired by a similar and close to optimal pattern.  For example all trade companies share the same processes and concepts such as sales region, sales commission, petty cash and etc.  The pattern is called "best practice".


Good
Now, imagine that you have designed and implemented information software for 25 trade companies so far; naturally resulting in your extensive knowledge of trade firms' processes and requirements -put simply, best practice.  In other words, you do know what the customer wants and needs.

What happens if you decide to design a comprehensive information system for trade firms? As you know their requirements and best practices, supported by the trade business knowledge and understanding which you have already earned during last 25 implementations, you design a model that, with minimum complexity and maximum clarity, covers most of the a typical trade firm' processes. Not only your model but also your user interface are efficient and understandable by the customer.

This is what I call a "Comprehensive Design".

Obviously the model doesn't cover all processes in all trade firms but, those non-covered are a small fraction compared to what the model already covers.  In fact, your model embraces about 80 to 85% of a typical trade firm's processes which leaves you 15 to 20% customisation during an implementation.  The percentages I just mentioned are very famous in ERP world. 

Bad & Ugly
Now, imagine a totally different situation: you have designed and implemented information systems for 2 trade companies so far and all of a sudden you decide to design an information systems for trade firms in general. Let's see how your design is.

Clearly, the knowledge of a typical trade firm requirements and best practices which you've acquired during your 2 implementations -even if both were successful- is not extensive. So when designing you have take care of all the possible requirements -which you're not aware of yet- by designing facilities to easily change the behaviour of the model. This is the key characteristic of your design, happening all over your model since you don't know the real world's requirements and need to prepare for meeting them.

Actually, your model is a "General Design".

It doesn't have a skeleton -the extract of your experience and knowledge- rather it has lots of lots of features that help users customise all the aspects of it and all because you don't know what you'll be facing in a typical trade firm.
There is a design principle stating that "The design and usage complexity of a software is proportional to how much the software is generalised." In other words, the more general your design the more difficult its development and usage.

Because it is complex and doesn't have a real structure, the result is not a software that has a shape but such a flexible set of -sometimes inconsistent- customisation features that it hardly has any shape. Practically, you have to create a new software out of all the customisation features, In every implementation using the general design. 


Conclusion

  • Comprehensive design is based on business knowledge, understanding the target market requirements and best practices and experience.
  • Comprehensive design is easily grasped by users and it is easy to use.
  • General design is based on a considerable technical knowledge, little business knowledge and incomplete understanding of the target market requirements and best practices.
  • General design is complicated and not friendly from the user's perspective.
The following statement is a concise and precise summary:

"Do not generalise.  Generalisations are generally wrong." -Butler Lampson


Amailyser - The E-mail Analyser

Recently Ed Daniel (a friend of mine) needed to produce a time analysis report out of his e-mails and asked if I can help him.  Well, obviously I said yes.


I thought to myself, he needs charts and graphs and data querying from many aspects that I may not know.  So to me the best option is to load his e-mail important fields into an RDBMS (such as SQLite or PostgreSQL).  Later he can do whatever he wants with the data using reporting tools such as JasperReports and produce nice charts and graphs as he requires.


That was the motivation to write Amailyser (on GitHub).

  • The language is Python 2.x; I could have done it in Perl but I'm learning Python and it seems like a wonderful practice to me. 
  • For DB interaction I used SQLAlchemy a nice ORM mapper for Python.
  • To read the e-mail messages I used Python standard library mailbox.
After downloading and extracting, you can run the Amailyzer (after you have modified config.py to suite your needs)  in a terminal:

$ cd amailyser/src

$ python main.py


The big picture is to read mailboxes, load each message, extract important fields and persist them in the database.


Below is the structure of the source:
Amailyser source tree
  • config.py: This is where you can change the behaviour of Amailyser like which mailboxes to process and type of each of them.
  • model.py: This is the model of database described in SQLAlchemy.
  • workhorse.py: Contains two calsses MailBox and MailMessage.  MailBox opens a mailbox in mbox or maildir formats and processes each message inside using MailMessage which (optionaly) persists them to the database.
  • main.py: Actually as a main is supposed to be, it doesn't anything special.  Just calls model setup routines and iteraties over items in the list of mail boxes, passing each one to MailBox.
To install SQLAlchemy please visit the tutorial on its website.

Nov 12, 2008

Talks at foss.ir: How to Promote Open Source In Iran and Role of ADempiere


T
oday I was at a meeting at foss.ir office. It was my first time and I was kind of surprised when I met the head, Mr. Ebadi; I was expecting a somehow old know-it-all guy but he was young. Later on I realised that it's an advantage that he's young: he's active! No offence to the older ones but it's just the norm, you know!

Before starting the talk another member joined us: Mr. Maddahi; another young motivated person.

It was almost a long meeting; we talked about 3 hours and the main topic was how to promote open source in Iran. They have alreay been active for about 4 years but mainly concentrating on the open source backbone software specially Linux.

So let's go to the summary:


Promoting open source software requires both enough enthusiasts to work on open source projects and enough jobs for them to make their ends meet. So it's a two-way movement: grasping and motivating enthusiasts while convincing and motivating the entrepreneurs to use open source software.

Fortunately there's little problem in finding enough enthusiasts in Iran as the talented young generation always attempts to seek new ways to explore the underlying mechanism of amasing softwares and what would be better for them than the open source world.

But about the entrepreneurs: here -and I think everywhere- they are mostly businessmen or business owners usually with little technical knowledge -they know how to run a business not how to run PostgreSQL on FreeBSD for example- and since the open source movement in Iran is young there's a broad mis-perception about open source for businessmen. When you talk about open source, what comes to their minds is a software with mysterious terminals and lots of weird commands with telegraphic outputs. Thus the first step to motivate them is to correct that wrong perception and that can be carried out by showing them how open source may come to their help and how they can reduce their costs using it: by showing them open source business software.

When it comes to business software, one of the most expensive and most fundamental softwares enterprises need is ERP. Here, each year thousands of USD are spent to just buy the license of a commercial ERP still less implementation and supprt services which are mostly banned by vendors because of the sanctions.

But there's an alternative to commercial ERP: open source ERP. It will be amasing for entrepreneurs if they know that they can reduce their costs and not worry about future customisations, features -specially regarding some weird business processes specific to Iran- and upgrades by using an open source ERP and having local experts for implementation and support contracts.

In order to show them that open source is the way to go, an Iranian community will be formed around the most active open source ERP in the galaxy: ADempiere! This community will work as normal in ADempiere SF and collaborate with others in forums and SVN while trying to concentrate on localisation for local business. By the time, through conferences, meetings and seminars entrepreneurs will know about how advantageous open source will be to their business and start to think about using ADempiere as their ERP of choice and that will be the time when serious open source job opportunities -besides existing Linux administrator ones- will emerge. At that point, entrepreneurs will understand that open source is not only terminals and command lines but an endless ocean of opportunities for business.

But how to do that? It starts by writing some conceptual and introductory articles about ERP and open source alternatives. Then when there is enough understanding about the topic, ADempiere will be introduced. Some workshops and demo sessions will be held to speed up enthusiasts getting familiar with the software. After that there'll be periodic workshops and small conferences to direct the efforts and make collaboration easier. After some progress in localisation, demo sessions to entrepreneurs will start and ...


It's a long way, isn't it? But we have to start walking, right now!

Thanks to nice foss.ir guys it was really a productive talk.

Will update upon any further events.











IFEM OSADempiere

SourceForge.net Logo

SourceForge.net Logo