Friday, March 11, 2011

 

contributing to codeplex .... my 2 cents

Finally got a chance to update my blog, last year been very hectic. This new year (2011), decided to share some of my code ideas ... the first two is out in codeplex

1. GrammaerIntelliForJS - A simple grammar based intellisense for Html/Javascript. Useful for web pages that wants user to type according to some grammar. First cut of the solution is a simple one, I'm not building the parsed AST .. instead kept it a simple associative array.

2. LSystem fractal curves - was always fascinated by L-fractal curves, wrote a wpf application implementing the algorithms that Lindenmayer talks about in his book "the algorithmic beauty of plants" - a classic.

planning to submit two more projects to codeplex .... will write about it.









Friday, September 24, 2010

 

FlipThroughMovies - our Yahoo HackDay work

Sometime back, myself and 3 other Intuit colleagues attended Yahoo OpenHack Bangalore. It was a fun event and we enjoyed it thoroughly. We could make good progress in 24 hours of straight coding. Pleased with what we created, we decided to publish our hack as a site. This site is now live at http://www.flipthroughmovies.com We had a ton of learning (the solution is deployed on Amazon S3, with edge caching using Amazon CloudFront).

Also published a youtube video at
http://www.youtube.com/watch?v=fy6nR1naxOY

Since the solution works against a huge data-set of movies, the first time load may be little slow, especially if your internet speed is less than 1 mbps.

Wednesday, April 14, 2010

 

what i liked @ COMPUTE 2010 (acm)

Recently I attended the ACM India launch & the COMPUTE 2010 events.
An ACM summit is worth attending, especially never miss a chance to hear the Turing Award winners. It was amazing hearing Prof. Barbara Liskov talk on 'The Power of Abstraction' and  C.A.R. Hoare on automatic software verification.

Thursday, November 5, 2009

 

XSD to Class generation in .Net

Visual Studio comes with a very handy tool called XSD.Exe. It helps to generate a C# class from a XML Schema (xsd). Once you have the class its very easy to serialize / de-serialize XML instances. Personally I find two thing very annoying in the code generated by xsd:

1. For collection types Xsd.exe generates an array definition instead of List generic.

2. By default it marks the code generated as “not Debuggable” !!!, you’ll be surprised that you cannot step-in the generated class by default.

After having faced this two problem 4-5 times, I decided to write some helper tool to solve these. Took the simple path of writing two macros in visual studio. One for removing the “not Debuggable” [aka System.Diagnostics.DebuggerStepThroughAttribute()] and other to convert every field/property of array type to List.

The macro code is available at my Aha e-Assets page.


Monday, October 19, 2009

 

Simple Grammar for Arithmetic over English

Technorati Tags: ,

 

These days writing a  parser has become very easy, there are MANY free compiler-compiler available … and all of them does pretty decent job of code generation. Gold Parser is one such compiler-compiler. The good thing about Gold parser is that it generates C# parser code for your Grammar, combined with the Calitha Engine you get a pretty robust infrastructure to write your own language parser.

Sometime back, I wrote a simple grammar for basic arithmetic over English. The idea is simple, use English phrases as equivalent to mathematical operators. Example: the grammar allows you to say “sum of x and y” instead of “x + y”. As with mathematical operators, you can “pump” the output of one operator into another, example “subtract 10 from sum of 200 and 50”.

Here’s the Grammar:

ArithEnglish-Grammar

Another aspect of this parser library is that it also allows “variables”. The object model as seen by the calling code is shown below:

ArithEnglish-Model 

 

The complete code along with a sample client and a demo recording is shared at  my Aha World!  .

Note:

1.  The code to handle the interest rate rules is not yet done :(.
2,  The video works with Windows media player, didn’t work with VLC :(. … may be some missing driver issue.


Wednesday, September 30, 2009

 

String Search & IntelliSense/Suggestion in .Net/C#

Problem: Given a set of keywords (or key phrases), provide a mechanism to suggest to user whether s/he is typing a valid word or phrase (i.e. word or phrase from the given list).

Example: Suppose, you wanted to maintain a list of commonly used English words like :

brake, boiling, driving, error, even, event

Then if user :
Types “e”   --> System should suggest –> even, event
Types “br” --> System should suggest –> brake

I had this problem with an additional caveat – the list of words/phrases were actually description of features & with every suggestion i wanted to maintain the association with the feature object. It was close to a generic dictionary in C# only that the key-search was based on “starts with” instead of an exact key match.

So, here’s a simple solution that worked for me. The idea similar to a Definite Finite Automata, only that I’ve  exploited the dictionary generics of C# to maintain the transitions. Here’s how the main classes look like:

smartStoreCD

The generic type T represents the type of the object to be associated with every keyword. A the library and a sample client is shared in my Aha World site. The project is called the SmartTextStore.

Here’s a snap of the sample client with a list of about 850 English words (the word list is included in the solution zip).

TestClient

The solution was developed in Visual Studio 2008 as that’s what i had in my machine. However, the underlying principle for SmartTextStore is simple enough to be ported in Visual Studio 2005 or lesser as long as there is support for generics.


Wednesday, August 26, 2009

 

Modeling a Diff tool…

Ok, here's the problem:
"Given two array of characters (in real world situations, one would be modified version of the other), determine the set of substrings that are "additions", or "changes" or "deletes" w.r.t the first array".
Example: If the first array is “To understand the solution you must understand the Prototype” and the second one “To really understand the solution, you should see the prototype”. The analysis result of the second array w.r.t first would be (for simplicity, I’ve taken a word break view) :
To                     - Common
really                 - Addition 
understand         - Common
the                    - Common 
solution,            - Update (comma) 
you                   - Common
should               - Update (Previously: must)
see                   - Update (Previously: understand) 
the                    - Common
prototype           - Update (first letter casing changed) 

The problem is very well known in the computer algorithm world & there are algorithms that solves it in linear time [ O(n) ]. You could use these algorithms in making "Diff" tools (example - WinMerge ). 
ClassDiagram1
What you see above is a very simple model for the Diff operation. For any client (web, desktop or otherwise … as long as they can talk to an implementation of above model) the starting point is the DiffTool class. Set the Base and Target. One can easily map a string , file content, serialized objects or memory segments to a byte array representation. I had another reason to choose byte array over stream, the reason being I had to expose the DiffTool as a web-service, hence clients would be remote to this service. Rest of the design of this model is pretty straightforward … client calls the Process method & gets DiffResult instance which has collection instance for commons, additions, deletes and updates. The All collection in the DiffResult contains the ordered (top-down) list of all Diffs as they appear.





This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]