Trying To Understand The Need For Morphine (DI Framework For Ruby)

For a long time now, I had an open tab in my browser with Morphine‘s project page on GitHub. From first look at it, it wasn’t clear to me why would you need such a library in Ruby. I mean, I understand the need for Dependency Injection (DI) in any language (including Ruby). What I didn’t understand was, why would you need a library to do DI in Ruby?

To try and understand better, I decided to rewrite the example shown on the library page with regular class methods. Here’s the result (first file: with Morphine, second file: without Morphine):

After writing this example, it was more clear to me — the Morphine based code is more compact and clean. But on the other hand, it requires the reader of the code to get familiar with another library, where the class methods based example is straight forward to any Ruby developer.

What do you think? Would you use Morphine or go with class methods?

How To Write Class Methods in CoffeScript

I recently started writing my client side code in CoffeeScript. While CoffeeScript (and migrating to it) deservers a post of its own, I wanted to share something quick and simple I learned today, which is how to write class methods:

In this example, stripTags is class method of the Utils class.
It took me some googling to find it, so I thought it’s worth sharing.

Using the terminal often? You need Terminitor

Terminitor is a Ruby gem that automates your development workflow setup. Basically, it allows you to easily set different environments in your terminal. Defining which tabs to open and which commands to run in each.

Installation is as easy as:
gem install terminitor
terminitor init

(assuming you already have Ruby and Ruby gems installed)

Then you create your terminitor setups with terminitor edit [name]. Defining terminitor setup is very is. Here is mine for one of my projects:

No more keeping all those servers running in the background, just because I’m lazy to open them again. Now restarting my working environment is just a single command.

How To Protect Your Program Against Piracy

This is another way to protect your software - just ask politely. (Photo by penner42 on Flickr)

This is another way to protect your software - just ask politely. (Photo by penner42 on Flickr)

A friend of mine sent me this question by email today:

I have  a software written in visual C++ which is compiled into an .exe file and I wish to distribute (sell) it in a “secure” (anti pirated) way.  How can I “lock it” so it will be able to run on only one computer (the one of the person who purchased the software)?  Is there a software to turn .exe files into protected ones, or good tutorials on what to do from the coding side?

I thought that for the general good and in order to get more views on the topic, I will post my answer to him here:

I can think of mainly four ways to protect your software -

  1. Some serial number authentication mechanism – this is the most traditional way and it fails big time. All of the documented techniques to protect yourself in such a way are already broken, and if you’re not in the field of software security you probably won’t find anything better. This might be a good way if you know that your target market is non-technical people who probably won’t bother breaking your authentication mechanism themselves and usually don’t know someone who can do it for them.
  2. Serial number authentication and online check – this is what Babylon do. When their application connects to their server it verifies the serial number it has with their database, if they see some misuse they either lock your application or just stop providing you answers. Microsoft use similar technique with XBox Live accounts – whenever you connect to XBox Live they check if the games you run are legal – if not they take actions against you. In recent check they disabled 1 million pirated accounts. But not only they disabled their access to XBox Live, they also disabled the hard drive in their console. This is quite good method as long as your software requires constant communication with your server. If not there are ways to override this protections (like disabling access to the Internet from your application).
  3. Good target market – like in mentioned in (1) a lot depends on your target audience. If you create a truly great product and price it in reasonable and achievable price, most people are likely to pay (unless your target solely to the Israeli market…).
  4. Online service – if you convert your software into an online service (like the 37Signals products, ZoHo, GitHub and many more), you are fully protected up to the extent that people will use stolen credit cards or hack your system in some way. But this actions are considered as “real crimes” by most people and they will less likely use them or spread the knowledge about them.

This are the four ways I can think of. If you ask me what would I do, I would go with option #4 – all other ways (besides #3) require you to invest unreasonable time and money in protecting your software instead of improving it. While it can be a nice mouse&cat game, it highly unproductive.

That’s what I think, I’m not sure if it really helps my friend, but maybe one of the readers will offer some better insights & tips on the topic.

Arik

How To Create a Teapot with PHP

Saw on @toolmantim‘s blog that he turned his blog into a tea pot. He even made a Rack middleware that can turn any Rake app into a teapot. “Cool! it can be cool addition to Topify, too”, I thought to myself. The problem? Topify is PHP and not Ruby. The solution? 6 lines of PHP code:

And now you can do :

arikfr:~ arik$ curl -i -X BREW http://topify.com/
HTTP/1.1 418 I’m a teapot
Date: Wed, 13 May 2009 08:51:07 GMT
Server: Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2
X-Powered-By: PHP/5.2.6
Content-Length: 29
Content-Type: text/html

We do serve ICE Tea, though.

It’s not as elegant as Ruby code or Ruby gem, but it does the work.

If you use this on your own server, please ping me. I would love to hear :)

Gravatars to Google Contacts Importer

I really like avatars and therefore I’m a big fan of Gravatar. When Google first released their Contacts API, the first thing I though of was creating a small application to sync my friend’s Gravatars to my Google Contacts addressbook. The problem was that the first version of the API didn’t have an option to manage the photos of the contacts. Few months later, Google updated the API to include the option to update the contact’s photos. I played a bit with the new API, but never had the time to write the appliaction.

Yesterday  (October 11 2008), the guys from Automattic/Gravatar wrote a post the summarizes their last year. This reminded me of this small project that I always wanted to code. I’ve decidced to code a first release of the application and put the code on Google Code for other to contribute.

Gravatars to Google Contacts Importer 

I’v decided to make it a .NET application and not a Python script, to address more people (I guess that more people are comfortable with running application than Python scripts). The reason that this isn’t a webapp, is because it takes a whole lot of time to process each contact list. If there was an option to question the Gravatar API for existence of a Gravatar for each email, it would make everything a bit quicker.

It’s .NET 2.0, so I guess there shouldn’t be a problem to run it on Linux using Mono, although I didn’t try that. The code is very simple, so if someone wants to translate it to other languages it’s possible and shouldn’t take too much time.

This is an alpha version, therefore don’t be scared if a nasty exception jumps at you :-) There are a lot of things to imporve, like adding threads to speed up things, time left counter and more. When I will have some more free time, I might add all this.

This is my first opensource project and your comments are mostly appreciated. 

Arik

How To Send SMS Message From Python Via Skype

In case you didn’t know, Skype offers an extensive API for their application. This API can be used via Java library, COM module or a Python library. The Java library, COM Module and Python library all share similar features and I decided to try out the Python library. What I wanted to do is to write a simple Python script that uses the Skype API to send SMS message from Skype. After going through their API documention, I was ready to go and the outcome was this short script: 

I think that the code is pretty straightforward and doesn’t require additional explaining. Feel free to ask questions at the comments.
Arik

ASP.NET MVC extension as a sign of change at Microsoft

The new ASP.NET MVC extension seems to be a sign of change at Microsoft. This extension is born from the requests of the community, being released with full source-code and integrates with not only Microsoft’s unit testing solution, but also with the alternatives.

And from what it seems, it really brings the fun to developing Web applications with ASP.NET.

Is Microsoft really changing?

Just wanted to share this thought. And if ASP.NET MVC interests you, I recommend following ScottHa‘s and ScottGu‘s blogs and watching this excellent screencasts by ScottHa.

Arik

A look into the new Android SDK

After seeing all this videos of prototype Android devices from 3GSM at Barcelona, it’s time for some more good news – as I reported earlier on twitter, Google has finally released the new Android SDK. As Dan Morill mentioned on the Code Day, the new SDK introduces a new UI (although Google promised that it still work in progress), new Eclipse plugin and some very interesting API changes -

  • New user interface – As I mentioned when we introduced the m3 version of the Android SDK, we’re continuing to refine the UI that’s available for Android. m5-rc14 replaces the previous placeholder with a new UI, but as before, work on it is still in-progress.
  • Layout animations – Developers can now create layout animations for their applications using the capabilities introduced in the android.view.animation package. Check out the LayoutAnimation*.java files in the APIDemos sample code for examples of how this works.
  • Geo-codingandroid.location.Geocoder enables developers to forward and reverse geo-code (i.e. translate an address into a coordinate and vice-versa), and also search for businesses.
  • New media codecs – The MediaPlayer class has added support for the OGG Vorbis, MIDI, XMF, iMelody, RTTL/RTX, and OTA audio file formats.
  • Updated Eclipse plug-in – A new version of ADT is available and provides improvements to the Android developer experience. In particular, check out the new Android Manifest editor.

As for the UI change, you can watch the following videos (origin) from 3GSM Barcelona :

You can see a more complete list of the major changes here (you can also find a complete difference report here). So what are you waiting for? Go upgrade :-)