Observer and Ducks
If you have implemented Observer pattern in any statically typed language, you know that you need an explicit Observer class/interface for the pattern, which will be extended by the actual concrete classes and some ‘update’ kind of method should be overridden in order to propagate the observations.Basically taking advantage of inheritance.
Here comes a duck type language like Ruby, as there are no types to be declared you can pass in any object to the observable and let it call the update method, you don’t need any parent Observer class. If the method is available in the object it will be called and the observation will be accomplished.
Now we can extend this more, The observable object will call any method it wants and ruby’s method_missing will take care of the methods that the individual observers don’t want to define. Cool eh? Check out this simple example:
So I quote this again “If it walks like a duck and quacks like a duck, it must be a duck.”
QR Code!
Game of life in Ruby
Here is the code, I think this needs to be written in more stylish way. If you have any suggestions please comment.
Drupal 7 + mod_sec
While developing one of my friend’s website in Drupal 7(this was the first time I have installed Drupal 7 on shared host), My IP Address was being continuously blocked by Mod_Security. So I asked for the logs and found that some rule in Mod_Security (id=950004) is blocking jquery.cookie.js. I googled it and found that many people are having the same issue.
So here is the solution that worked for me(Use this if you don’t want to waste your time fighting with your shared webhost.) :
- Rename your jquery.cookie.js to something like jquery-c.js.
- You will also need to change the mapping in system.module - find “jquery.cookie” and replace with “jquery-c”.
Hope that will help.
Your new Remote Control : NaradMuni
Hello all,
Its been a hectic month for me, many things happened, good and bad(especially about home loan, I am going to write a blog post about that in Vartool.). One of the good things that happened is that I met few Ruby enthusiasts and I have decided to write some cool Ruby program again! So without wasting anymore time, lets go…
Scenario : I am working on my computer(A) and my teammate is working on a shared computer(B), Now i have some urgent work on computer B, lets say i have to read some code i have written yesterday. Now I can’t go to the machine and copy that code(because the machine is remotely located .. geographically) and i can’t remotely access it through remote desktop because i don’t want to disturb him. What should I do?
Well don’t worry, NaradMuni is here.
What is NaradMuni : NaradMuni is very small (tiny) ruby application which will let you run a terminal command on another machine from your machine.
How : Using DRb. Well, I have written a DRb server and client, you run the server on the shared machine(Computer B from the scenario) and client on your machine. The client will accept the commands you want to run on the server and send it to the server using DRb. Server then runs the command using IO.popen and return the result to the client. Simple!
Here is an output, Server is running on my machine(pdandwate) and client on another(kalea, thanks to Kale for letting me use his machine ;) ) :
Start to End : Twitter client in Shoes
Prerequisites :
- I hope you have Shoes installed on your machine, operating system does not matter :)
- oauth gem (gem install oauth will do the trick or sudo if you have to!)
- json gem as well(to parse the response) (gem install json)
Let’s start :
Step 1 : Register your application at Twitter (HERE), give some cool name like “Rubydubee”(not this x-( ).
Step 2 : Lets first write our own library(ehh? don’t worry you can just copy the code here :) ), But you can try to understand that… very small & simple if you know the OAuth protocol.(the oauth gem does all the magic.)
Step 3 : Let’s write our Application
The code is intuitive! isn’t it? if you need any help plz comment!
After you run this “shoes main.rb” it will look somewhat like this :
Thanks for reading this post!
Next post will bring following points :
- Error handling
- Sophisticated architectural design and UI
- More features
Keep reading!!! :)

