Archive for the 'open source' Category

MySQL Query Browser in Ubuntu 12.04

I going to outright say it: MySQL Workbench completely sucks. It is a convoluted, complicated, steaming pile of bloated nonsense. It is hard to perform a simple query. Worse, the damn thing keeps crashing. I missed the simplicity of MySQL Query Browser. Yet, Oracle deprecated it a while back and Canonical removed the package in Ubuntu 12.04.

After some searching, I found that Tyler Wagner maintains an APT repository containing MySQL Query Browser ported from Oneiric.

I summarize the installation here:

sudo apt-add-repository 'deb precise main'
wget -q -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install mysql-query-browser

So, a big shout out to Tyler for doing this work!

Edit: You do need to execute sudo apt-get update before install. Thanks, Steve!

String Similarity Library

Today, I submitted a new open source project onto Google Code. It is a Java port of a string similarity library that I wrote years ago. The API is a service that calculates a distance or similarity score between two strings. A score of 0.0 means that the two strings are absolutely dissimilar, and 1.0 means that absolutely similar (or equal). Anything in between is a metric on how similar each the two strings are.

Here is a simple example, using the Jaro-Winkler algorithm strategy:

SimilarityStrategy strategy = new JaroWinklerStrategy();
String target = "McDonalds";
String source = "MacMahons";
StringSimilarityService service = new StringSimilarityServiceImpl(strategy);
double score = service.score(source, target); // Score is 0.90

The next step for this project will be documentation and figure out where to host binary releases.

Chromium Tricks for the Lazy Programmer

One of the cool time-saving features in Chromium (better known as Google Chrome) is the custom search engines. It’s not a new concept. Mozilla Firefox has similar capabilities, but it feels like a hassle sometimes. You have to physically select the custom search engine in a separate combo box, then enter your search terms. That takes up extra time with all that mouse action, especially for a lazy programmer like me. Chromium goes on step further. The address box has a secondary function as a search box. If you were to enter anything but a URL or a domain name in the box, Chromium treats it as a search term and uses the default search engine. Google is default on mine, but any search engine that uses HTTP GET query parameters can be used.

If I was not a programmer, I may use my default search engine to do general searching. But, when I want to search programming language documentation, I would normally have to add the programming language name as a search term.  Given that a lot of programming languages have fairly common words as their names (python, ruby, lisp), you may waste some brain cycles filtering.  Again, for a lazy programmer, I want my information correct as well as fast.

So Chromium allows me to create a custom search engine to query a specific web site. In my example, I will be using lispdoc to search Common Lisp documentation. First, you need to go to the site and examine how a query is done. For lispdoc, the query is very similar to Google. However, there is another time-saving feature in Chromium. If you performed a search on the target site, there is a good chance that Chromium has already added a custom search engine for you:

Manage Search Engines

Wicked awesome! For lispdoc, the Chromium recognized that I searched on that site and added an entry for me. I don’t think there was anything special the site did, but you can add a search engine on your own if Chromium did not detect it for some reason.  The only issue that I have with it is the keyword property that Chromium selected. It put the domain name as the keyword, but why is that important?

The keyword is how you tell Chromium that you want to use a custom search engine instead of the default. It’s almost like what you would do if you went to the search engine directly with one important difference. If I entered the keyword (currently “”) in the address box, space bar, then tab key, Chromium selects the custom search engine matching that keyword:

Using custom search

Then, I can enter more search terms. Unlike Firefox, I do not need to stop typing to tell Chromium what I want. The mouse is not even involved. Perfect for the lazy programmer? Not just yet. Since the keyword defaulted to the domain name (“”), it has two usability problems.  Since I visited, the URL shows up in my browsing history and will probably be the first selection. So, a chance a mistake can occur.  The second problem is that the name is too long for a lazy programmer.

The solution to both problems is quite simple: change the keyword to something else.  For entry, I would change the keyword to “cl” for “Common Lisp”, which makes it less characters, no ambiguity, and easy to remember. Now, I can search documentation very quickly now. I have specific searches for other popular sites and assign them to shorter keywords, also. Here are some examples:

Try it out and let me know what you think!

Installed Kubuntu Today

For the longest time, I have always had a goal to be Windows-free. Many people I work with feel that it is pure apostasy, because I have worked in Microsoft shops in the past 10 years or so. But frankly, I am particularly sick of Windows as a whole. If I can still continue doing my work without having Windows on on my HP Pavillion dv9008nr laptop, then I think I am set.

So, I installed Kubuntu 9.04 (Juanty Jackalope) today. It was the most painless installation of Linux that I had… ever. It was even less painful that my initial installation of Ubuntu 8.10 (Intepid Ibex) on the family desktop (recently auto-updated to Jaunty).

My laptop wireless has the ever painful Broadcom chipset, which historically has been a problem on both 32-bit and 64-bit systems. But I found out that they got off their butts and started to provide drivers for Linux. So, after enabling the closed source drivers, my wireless just worked period. There was no manual configuration that I had to do, no driver to look for, and no searching through outdated documentation for clues on configuring everything.  Do you have any idea how refreshing that is?

Here are other refreshing things:

  • The NVidia chipset for graphics acceleration worked with zero configuration.
  • All of my external devices worked.
  • Even though I like the GNOME interface in Ubuntu, I absolutely love the KDE interface in Kubuntu.  I am ecstatic that I went in that direction.
  • BZFlag looks / feels much better on Linux that on Windows.
  • The best system for tools I already use on Windows: Pidgin, GNU Emacs, Steel Bank Common Lisp, Mozilla Firefox, and others.
  • Even Adobe Flash has decent performance, even though there is no 64-bit native version for Linux. Most YouTube videos do work, even in full screen mode. So, I can deal with it for now.  (Adobe is now the new Broadcom, IMO).
  • The default Remote Desktop (RDP) client allows me to connect to my Windows desktop at work, basically completing my minimum requirements for total conversion.

So, I look forward to writing more about my experiences on Kubuntu.

Decorators in Python

A few days ago, I mentioned that I was going to start coding Python again. So, I was looking at Python 2.5 and one of the cooler features that I discovered first were decorators. From what I understand, a decorator wraps behavior of a function or method. It sort of reminds me of auxiliary methods in Common Lisp. A Python function or method can be decorated.

So, I created I quick example that creates a decorator. The simplest decorator is a regular function that accepts a single argument, the function that is being decorated. The decorator returns another function that accepts an argument set and an environment. This is basically a lexical closure. In my decorator, logged, the inner function wrapper is enclosed and wrapper just prints out a message:

def logged(f):
  def wrapper(*args, **kw):
    print "calling %s with args %s." % (f.func_name, args)
      return f(*args, **kw)
      print "done calling %s" % (f.func_name)
  return wrapper

The interesting thing is that wrapper ends up calling the function object passed into the decorator. In this case, the function object is the decorated function add():

def add(n1, n2):
  return n1 + n2
print add(2, 1)
print add(4, -2)

My simple adder is decorated by the @logged syntax. The Python runtime will execute the decorator and call the closure, passing the arguments from the original function call. When I execute my test program:

$ python
calling add with args (2, 1).
done calling add
calling add with args (4, -2).
done calling add

Awesome! Now, there is more to decorators than meets the eye, and I need to gain more experience using decorators. So, it looks like I am off to a great start.

Starting Python Again

After almost a three year break, I am starting to write some Python code again. I am experimenting on developing a RESTful part catalog web service. I last used Python when it was in version 1.5.2. I think that there have been many changes, because the page holding version 1.5.2 states quite frankly:

Do yourself a favor and get a more recent version!

Fair enough. I picked up version 2.5.1 for Windows. The install was quite painless. The most improved thing that I noticed was the revamped web site. There is a lot more information now. I find this quite refreshing. I should have no trouble picking it up again.

So, why did I pick Python? Well, it was a tough decision. For the most part, Python was the right tool for this job. It was a written in a language that I am somewhat familiar with, it is portable, and gave the flexibility that I needed. I love other languages, but I found that the others did not quite fit the mold. For example:

  • I rejected Java right away because Java would take a lot more time that C/C++ in my case. The language is certainly as good as C#, but I am not as familiar with it as Python or C/C++. Additionally, the core framework is significantly larger than I remember. Like Python, Java has added features since inception. I have not touched Java in about eight years, so my learning curve will be very high. Today, there seems to be a lot better tools and frameworks to have ease the development pains, but it is not enough for me to give Java consideration.
  • I use C# and ASP.NET for my day job, so why did I not pick them? Frankly, it is damn tough to make a truly RESTful web service in ASP.NET. ASP.NET likes SOAP web services. Forcing ASP.NET to do a RESTful web service is like fitting a square peg in a round hole while having a root canal. In retrospect, it’s a blessing in disguise to me, because I prefer to use open source tools anyway. I do not want to give the impression of bias. I honestly did try to make it happen fairly recently. It was just not meant to be. Again, the tool was not right for this job.
  • C/C++ requires more investment in time. I have been programming in C family for years. I love it for it’s speed of execution and it is right against the metal. If I was creating Unix tools where execution speed is critical, C/C++ will be my absolute first choice. However, the compile cycles and the debugging become a deal killer for a web prototype. When I am rapid prototyping, I have a need for development speed, rather than saving a few cycles. Like many other high-level languages, Python still gives me many options to integrate and optimize using C/C++. So, if I need it, I will use this feature.
  • What about Lisp? I’ve coded a lot of Lisp for other applications and experiments. I have been writing a lot about Lisp in this blog. It was my second language that I learned.  So, it would be natural for me to just use Lisp, right? Well, not in this case.  Most likely, the code for this experiment will be sent to other developers.  They are more likely to be receptive to Python than Lisp.  There I said it.  I still believe that Lisp is the best language out there. But, being the best language is not the only reason to use it. Sometimes, you need to give in for the greater good.
  • Ruby and it’s poster child framework, Ruby on Rails, came a very close second. I said that my choice in Python was a tough decision. I like the Rails framework.  Rails is very RESTful.  I was blown away when I first encountered it.  The framework make development easy.  So, why did Python win?  Again, I am more familiar with Python than Ruby…and that is it. Python has a similar framework to Rails, called TurboGears. I give props to the Ruby clan to developing a great framework. It is so innovative that many languages have came up with clones.  So, it boils down to language familiarity.  Python won by a nose.

So, there you have it.  I picked Python for this project.  Hopefully, it won’t let me down. I’ll try to keep regular updates for everyone who is interested.

An Emacs-like Editor for .NET?

Douglas Purdy recently mentioned on his blog that his team was hiring testers for a project within Microsoft informally described as Emacs.NET. I am going to take a step back and think about that for a second. In this stage, why would Microsoft invest in such a project? Microsoft products did have some basic capabilities before, like Emacs-style key bindings in Visual Studio to named commands and such. There must be something more.

Could be that Emacs is the most versatile editor out there? Emacs users know all too well how flexible Emacs is. Many hack their favorite programming language in Emacs, some like to use Emacs as an application interface, while the elite execute shells that make them never have to leave Emacs. Users can customize their key mappings, customize the look, or even code their own custom commands. There are hundreds of different modes out there that help users create and edit even the most arcane file types. It is available for Unix, Windows and MacOS X and most modes and extensions are very portable.

The absolutely coolest aspect of Emacs is the interactive programmable environment. Emacs the only editor that I know at this time that allows you to create extensions for editor from within the editor itself and apply them immediately the current session. This flexibility within Emacs is made possible it’s powerful, built-in Lisp execution environment. Here is a quick example that I hacked up in a minute. In the scratch buffer in Emacs, I create a simple function:

(defun my-hello (msg)
"Prints hello message"
(interactive "sDestination:")
(message "Hello %s" msg))

then I select the region containing the function and execute M-x eval-region. The function my-hello is now applied and I can now execute it using M-x my-hello.

My big question: would a .NET version do the same thing? I doubt that there any Lisp involved, but interactively applying extensions in .NET seem to be tricky to me. So, I would imagine that extensions will be compiled to IL assemblies. If Emacs.NET contains an interactive compiler, things in the Windows world could get very interesting.