Soulmate Rails

One of the most common things to do in any standard rails web applications is auto-completion. One interesting solution to this is by using redis’ (which is blazing fast) sorted sets, storing key value pairs for partial matches. For example, if we wish to index the word ‘Dhruva Sagar’ (my name), you can simply create key -> value pairs of ‘d’ -> ‘Dhruva Sagar’, ‘dh’ -> ‘Dhruva Sagar’, ‘dhr’ -> ‘Dhruva Sagar’ and so on. Since hash lookups are of constant time complexity O(1), they’re very fast and hence the completions are too! Combine this with using sorted sets of redis to easily order / sort information on a specific criteria and you have a blazing fast solution. Of course the actual implementation can be further optimized by means of caching query results and make the system perform even further.

Soulmate is a cool gem by the guys at SeatGeek that provides a pretty cool implementation of the same. However it’s implementation wasn’t quite a good fit for my case since I wanted to work with a rails application and didn’t want to either host a separate server or mount the provided sinatra app inside of rails. I came across this nice post by Pat Shaughnessy – Finding your soulmate: autocomplete with Redis in Rails 3.1 which showcases how one can use the Soulmate gem and use it’s API to roll out your own auto-completion engine within your rails 3.1 application very easily.

This inspired me to fork Soulmate and extend it to build a Soulmate Rails gem over the weekend which provides a clean and intuitive API to do this from within Rails. Please do check it out, star it, fork it and use it to your hearts content :) . I’ve released it in alpha phase right now but it is fully usable with a reasonable test coverage. I’ll be contributing a lot to this, hopefully you find it useful too.

UPDATE : I released the first stable version 0.2.1, it should be usable as is without any issues.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Tmux Powerline Special Characters Issue

tmux is a terminal multiplexer like screen on steroids. It is faster, slicker and much more easily extendable than screen. For why you might want to try tmux over screen checkout

Tmux Powerline is an extension to tmux’s statusline which makes it look incredibly cool. Look at this screenshot.

Screenshot from 2013-02-23 12:21:31
Read More →

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Ubuntu on Macbook Pro

As I have mentioned before (Magician Chrome makes RAM disappear), I had been facing several issues with Mac OSX. I use vim extensively, and so I had installed (after great difficulty) MacVim on my Macbook Pro, but recently while trying out a new plugin I found there was something amiss between MacVim & Python on my system and as a result I was unable to use the plugin. In my attempt at trying to repair MacVim, I ended up uninstalling it.
Read More →

VN:F [1.9.22_1171]
Rating: 4.3/5 (4 votes cast)
VN:F [1.9.22_1171]
Rating: +2 (from 2 votes)

Magician Chrome makes RAM disappear

Recently I have been experiencing a very weird issue on my Macbook Pro, I have Lion v10.7.4, with a decent configuration – 2.8 GHz Intel Core i7 processor, 8GB Ram with a 750GB sata hard disk. But over a reasonably prolonged period of usage, of around 4-6 hours, I notice from time to time that Mac OSX runs completely out of RAM! The Activity Monitor reports mere MBs of Free Memory, sometimes even less than 10MB. Needless to say this makes the Macbook loose it’s mind, it would freeze up on random, seemingly basic tasks, even switching to a window can freeze the macbook for minutes, if not hours. Which is understandable, though, given how low memory it is left with.
Read More →

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

VIM in my muscle memory

I have been an ardent VIM user for almost 4 years now, and it’s been a while since I have been wanting to write this Blog. My motivation is not to showoff or to start any flame war against any other popular text editors that may or may not be better ;), but to simply showcase the things I like and have come to appreciate in VIM, and show why you should seriously consider it when deciding which programming editor you should use. Hopefully I will be able to do justice to VIM – the Ultimate Programmer’s Editor.

The beauty about using VIM is that it converts the task of text editing / manipulation into a programmable activity. It provides you with a framework to work with your text in a way which allows you to think of it in terms of simple patterns, patterns which you can repeat, store (macros), copy & even combine together. This also makes the process of learning VIM interesting & fun! Add to that the fact that you can easily extend your VIM with a wide variety of plugins & themes contributed and shared openly by a vibrant community is just icing on the cake!

Initially when you start out with VIM it feels quite alien and ancient to say the least, also because the default configurations in VIM aren’t that optimal, so it might take a few days to get a hang of things, but once you do, it will motivate you to do things faster. The more you do, the more you obsess on doing things faster and with fewer and fewer keystrokes as possible (you might want to have a look at http://vimgolf.com for a bit of fun in that respect :)), the more you discover what VIM has to offer.

Over a prolonged period of usage, slowly and steadily VIM commands creep into your muscle memory and the vastness of the abilities and features of VIM which overwhelm you in the beginning, come to you as second nature. This is my attempt to describe various elements of VIM that are now in my muscle memory and use them on a daily basis.
Read More →

VN:F [1.9.22_1171]
Rating: 4.8/5 (16 votes cast)
VN:F [1.9.22_1171]
Rating: +10 (from 10 votes)

Artificially Intelligent Spyware

There has been tremendous advancement in the domain of Artificial Intelligence (AI) and Machine Learning (ML) in the recent years. Although people often like to take a shot at the state of AI on the grounds of the fact that several of the early claims on AI that it will soon become almost as real as humans haven’t really materialized, there still has been an incredible amount of growth in this domain.

Today AI is a bigger part of our daily lives than we realize. For instance every time I search for something on google, google remembers what I searched for and makes informed, calculated decisions in the future based on my search history. Often when searching for the same search pattern, it is likely that the search results I receive might be marginally different than yours because of google’s AI / ML algorithms, who try to understand my search queries in the context of my search history, and decide what I might be more interested in, usually based on things that I search most often about, things I like more based on search results that I clicked on, etc.

I have often been rather vary of the implications of such a system and find myself going to incognito window to search when I wish to search for things that I don’t want to be associated with, a prime example of this would be when I am trying to validate some viral news.

Now given that I am generally always online on google, and given the understanding of how AI’s might work and evolve, I was thinking about a side effect that might be possible to tap into by modern spyware. A spyware could simply just sit on my system and make google searches in the background with specific keywords. It could make 1000s, 10s of 1000s of searches in the background on my behalf and hence gradually, so to speak, train google’s AI / ML algorithms into believing that I am really interested in something that I really am not.

Google’s case is just one of many such services who make use of AI & ML, most recommendation systems make use of AI & ML to learn about my choices and recommend things that I might like, advertising platforms also make use of a similar approach to target users with ads of things they might be interested in and so on.

This could very well be a reality today, it is quite possible a similar approach is already being used by several Spyware to manipulate such artificially intelligent systems by feeding them wrong information and hence indirectly influencing their decision making. The disturbing point to note about such an approach is the fact that it is virtually impossible to undo the damage that has already been done.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Getting started with Ruby – TOC

Hi,

I have written a series of articles (in several parts) in an attempt to guide beginners to get comfortable with Ruby. This article is my attempt to build a TOC (Table of Contents) for it to act as an index for people to get a brief idea regarding what each article is about and help them get to the sections they are interested in.

  • Getting started with Ruby – Part 1 : In this article I begin with an introduction to myself and my motivation behind writing these articles. I give an introduction to Ruby, about how to get started with building your development environment and introduce a few tools that ship along with Ruby which will make your life that much better.
  • Getting started with Ruby – Part 2 : In this article I introduce Ruby in slightly more detail and I get started with describing different data types in Ruby. I cover Strings and Numbers in this article.
  • Getting started with Ruby – Part 3 : In this article I continue from my previous article describing data types in Ruby and cover Ranges and Arrays.
  • Getting started with Ruby – Part 4 : In this article I continue further and cover Hashes, one of the most commonly used data types in Ruby. I also introduce blocks and about using blocks with functions.
  • Getting started with Ruby – Part 5 : In this article I move onto describing various looping constructs in Ruby, and also various flow control modifiers in Ruby. After that I introduce Variables, Symbols, Constants, Methods and Global Variables in Ruby.
  • Getting started with Ruby – Part 6 : After having covered basics of various constructs in Ruby, I considered it better to take a problem statement and solve it in Ruby to bring most of what we’ve discussed into use. I chose Google Codejam 2009′s qualification round problem – Alien Language

I tried to be clear, precise and specific. My intention was write more code than to waste time in trying to explain and so I’ve used code comments to help people understand what each part of the code is meant to do. I have plans on going further and go onto describing classes & modules, sometime soon, even though I expected more people to read and give their feedback, but owing to a lot of work and hence a lack of time, I haven’t been able to do much justice to the same, but hopefully I will be able to do so very soon. I hope it helps people appreciate Ruby and motivate them to learn and understand it.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

MongoMapper Plugin – Versionable

There was a requirement at one of our projects here at Artha42 Innovations Private Limited that our Mongo Mapper documents have inherent versioning so as to be able to track the changes being made and also if required revert the changes to a previous state. Since we’re using MongoMapper, I set out to create a simple plugin for the same to add the required functionality.

Initially, from the initial research I did, I found Shapado had an implementation of exactly what I wanted, however when I studied and understood their implementation in detail, I realized that it doesn’t really work that well in most scenarios, especially the ones we were tackling in our project. Shapado’s versionable allows you to define a set of keys for a document, whose changes would trigger creation of new versions. However in our project we needed to track changes at the complete document level, i.e. even for changes in the associations. Also the versions were embedded within the document itself, which implied that the document would grow in size very rapidly, even though our changes in each iteration could be minor, since each version would literally be a snapshot of the complete document itself.

So we made quite a few design changes in the same, externalized the versions, changed the way one would enable versioning since in our case we wouldn’t be keeping track of changes only in specific keys. Even here, we found that there were certain bottlenecks in the case if there were a whole lot of versions, for which we introduced the :limit feature which allows us to define how many of versions would need to be loaded instead of loading all of them at once.

The result of it was mm-versionable.

If you have any comments, suggestions, requests, queries or feedback, please do let us know in the comments section below.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Calculating Hashes

Showcasing how to calculate hashes in Java, C# and Ruby!
Read More →

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Getting started with Ruby – Part 6

After having covered most of the basics of Ruby, lets get started on an actual problem, just like I had promised in my previous article – Getting started with Ruby – Part 5

I am taking a relatively simple problem that came in Google Codejam 2009 qualification round. Here is the direct link to the problem – Alient Language
Read More →

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)