Keywords

*.cod (1) .NET (3) .rb (1) 3110c (1) Algorithm (1) Amazon Cloud Drive (1) amkette (1) Android (1) Apex (6) apex:dynamic (1) API (1) API version (1) Application Development Contest (2) Artificial Intelligence (2) Atricore (1) b2g (1) Binary Search Tree (1) Blackberry Application Development (1) Blackberry Java Development Environment (1) Blender Game Engine (1) bluetooth (2) Boot2Gecko (1) bug fix (1) C (1) C++ (2) Cloud computing (1) Cloud Storage (1) Code Blocks (1) Code for a Cause (2) codejam (1) Coding (1) const_cast (1) Custom Help (1) Dancing With the Googlers (1) Data Structures (1) desktop environment (5) Doubly Linked List (1) Dropbox (1) dynamic visualforce component (1) dynamic_cast (1) Enterprise WSDL (1) Execution Context (1) fedora 14 (1) fedora 17 (5) Firefox OS (1) Flashing Nokia 3110c handset (1) Force.com (7) Gaia (1) Game Developement (1) GCC (2) GDG (2) Goank (1) Google (4) Google Developer Group (2) Google Drive (1) GTK+ (5) HACK2012 (2) Hall of Mirrors (1) help for this page (1) HTML5 (2) HTTP Web Server (1) IDE (1) Identity Provider (1) install (1) Intelligent Systems (1) Java (1) JDE (1) JOSSO (1) location based social network (1) machine learning (1) me.social (1) MinGW (1) Natural Language Processing (1) Natural Language Toolkit (1) neckphone (1) NLKT (1) Nokia Pheonix (1) Notebook (1) Numeric XML Tags (1) OAuth2.0 (1) OLPC (7) OLPC-XO-1 (7) One Laptop per Child (5) Override custom help (1) Paas (1) Partner WSDL (1) Polymorphism (1) programming contest (1) PyGTK (4) Python (11) Recycled Numbers (1) reinterpret_cast (1) Research (1) REST (1) RM-237 (1) Robotics (1) Ruby (1) Saas (2) Salesforce.com (7) scikit-learn (1) SDK (1) Service Provider (1) Single sign on (1) sklearn (1) SOAP (3) Speaking in Tongues (1) SSO Agent (1) SSO Gateway (1) static_const (1) sugar (7) sugar activity (4) sugarlabs (7) SVG (2) Symbiotic AI (1) Tabbed container (1) TCP/IP (1) TCP/IP stack (1) Typecasting (1) typeid (1) ubuntu 13.10 (1) UDP (1) Upgrade Assembly (1) Visualforce (2) Web Server (1) Web Services (3) Web2.0 (1) wikipedia (1) wikipediaHI (1) WSDL (1) XML tags (1)

Saturday, June 14, 2014

scikit-learn on OS X Mavericks

After facing a lot of trouble setting up scikit-learn on MacBook Air with OS X Mavericks, I finally managed to install and use it. I want to share the easiest and best approach to set up scikit-learn without any trouble.

Steps to install scikit-learn on MacBook(OS X Mavericks):
  1. Get the source from https://pypi.python.org/pypi/scikit-learn/0.14.1#downloads
  2. Extract and install from directory using python setup.py install
  3. Now if you try to run python from source directory of scikit-learn and try to import sklearn module using import sklearn you will get error. So change your current directory and then try to import sklearn. It will work !
Hope this post helps !

Saturday, April 12, 2014

Ruby Magic with Code Blocks

This week I have started learning Ruby language. I came to know that those who have are from Python background find it easy to learn as compared to those from other languages. This motivates me and pushes me to explore Ruby.

So far I have been going through Ruby Documentation. This post is specifically dedicated towards Ruby code blocks. This is a nice feature that I see unique as compared to other languages.

Ruby code blocks gives us ability to pass a block of code to be passed as a argument to a method. :)
Looks Strange.. isn't it ? I also reacted the same way !

Let's look how it works:

Consider a method:

And let's say we have single line code block as {puts "in the block"}. We can pass this single line block as a parameter to the method the same way we do it for method parameters. In order to consume the Ruby code block the method can use the "yield" method to invoke it. The beauty is that a Ruby code block can be invoked in the same way as methods are invoked.

Let's have a look on how we go about it:
In the above shown code I have added "puts" and "print" for tracking. In line #5 you can observe that we are calling "yield" with no parameters at all. This will simply call the Ruby code block that it received as parameter. In line #6 you can observe that we are calling "yield" with 10 as parameter. In this case greet method will invoke Ruby code block with 10 as one of the parameter.

Single line code blocks

Now when we pass single line Ruby code block as parameter to greet as in line #11 having simple "puts" statement we get such output:
You can observe two "in the block" statement in output. The reason behind is that we invoked yield twice within greet method. Once without parameter and once with 10 as parameter.


Multi line code blocks

Now consider when we pass multiline Ruby code block as parameter to greet as in line #13 having print statement with block parameter "x" picked dynamically from yield statement in greet method. In line #14 I have used interpolation feature of Ruby that puts the result of an expression within string literal. So this will produce such output:
You can observe the two "in the block with x=" statements with different x value. The reason behind is that we invoked yield twice within greet method. Once without parameter and once with 10 as parameter. And we used interpolation to print the value of parameter.

Capturing the response from Ruby code blocks

We can capture the response from code block in the same way we do for Ruby methods.
Lets dive for one example:
I have defined a Ruby method that captures response from yield( execution of ruby code block) into a variable named "result". We have a multiline code block at line #32. As we know Ruby methods return value in last line as return value by-default. The same funda applies to Ruby code blocks. So the value that gets returned by this code block is "2" since we mentioned it in line #34 (last line of code block). And here's the output:


No block passed within a method having yield statement

What happens if we pass no code block to a method that have a yield statement. Yes, you guessed it right ! It gives an error: LocalJumpError. Here is the small snippet showing how:

How to handle "no block given" error: We can use "block_given?" method to check whether a block is passed as param and then only invoke "yield" method. Here is the small snippet showing how:


Hope you enjoyed my first post on Ruby. Stay tuned to get more magic with Ruby !
Cheers!

Sunday, February 23, 2014

Algorithm Magic: Binary Search Tree to Doubly Linked List

Hi friends,

This post gives solution to a famous data structures problem: Converting a Binary Search Tree to Doubly Linked List. I am assuming you are well aware of what there data structures are and their behavior.

Lets jump into algorithm to convert this.

  • Since each subtree in a binary tree is a binary tree itself, we can use recursion for achieving this. We start by root node and reach leaf nodes. 
  • While traversing, we see if node does not have any left or right child, the node itself is returned. If it has non empty child nodes, then we create doubly linked list with 3 nodes( current node, left child node and parent node). 
  • Now here is the magic, the left child is not exactly its direct left child. Since our aim is to convert it into a sorted doubly linked list, we need to get the maximum value node which is less than current node value in left subtree as as left child for current node. Similarly, the node with least value in right subtree as right child of current node. 
  • That's it, apply this logic and solve it.
The class used to represent the node in binary tree and doubly linked list*:
*left will indicate previous node in doubly linked list and right will indicate the next node in doubly linked list.

function to insert node in BST:


function to convert BST to DLL:


function to show doubly linked list:




Here is the implementation of this algorithm: Download here.

Hope this helps you learn how to convert BST into DLL.
Cheers!

Tuesday, January 21, 2014

Fix for Bluetooth Indicator bug in Ubuntu 13.10

Hi Guys,

I was facing the issue with Bluetooth in Ubuntu 13.10. I was able to connect my bluetooth headset but wasn't able to see it in my sound settings. Thus was unable to use it. To resolve it, I found a fix for this and here it follows:

1. Install the pre-requisites :

sudo apt-get install bzr build-essential

2. And install the dependencies:

sudo apt-get build-dep indicator-bluetooth

3. Branch the fork from Launchpad:

bzr branch lp:~robert-ancell/indicator-bluetooth/dont-hide-on-rfkill

4. Jump to the directory:

cd dont-hide-on-rfkill

5. Now run following command to build debian package:
dpkg-buildpackage


This gives an error that "Unmet build dependencies: libdbusmenu-gtk3-dev libgnome-bluetooth-dev libgtk-3-dev libido3-0.1-dev libindicator3-dev valac-0.18"

Lets go ahead these dependencies:

After installing these, lets try to run this again:
 dpkg-buildpackage 

as a result the debian package is created :

Lets go out to home directory and install the debian package:
go to home directory:
cd  
and then:
sudo dpkg -i indicator-bluetooth_0.0.6daily13.02.19-0ubuntu1_i386.deb 

and.. it works !! 

and then restart your system. Now the bluetooth icon remains even you turn it off and just gets grey when turned off.


Hope it helps !

Cheers!


Saturday, January 18, 2014

Machines+Symbiotic Artificial Intelligence=Humans

I feel extremely motivated by my dream to do research and create systems which enable machines and devices to act as full fledged human companion. So that devices observe humans, their activities, conversations and understand them to create knowledge. By augmenting such intelligent systems with information about the real world entities, their properties and such minutest details will empower them to assist humans in their day to day activities. I truly believe that there is a deep symbiotic relationship between Humans and Artificial Intelligent Systems. Just imagine time when we will be having small gadgets on our wrist, over our spectacles that would assist us in every action which needs precision and quality; Imagine system that could tell you what should be your next step based on knowledge acquired by such system by observation and knowledge from world through various sources including WWW. This will not only assure effectiveness of the task being done but also will gradually help symbiotic artificial intelligence systems to evolve rapidly. I want to build algorithms, models and systems that will enable us to leverage intelligent systems at every domain. This will definitely revolutionize the way things are accomplished by humans.

Sunday, May 12, 2013

Making Amkette TruBeats Bluetooth Neckphone work with Fedora 17(Beefy Miracle)

Hi,

I would like to share how I managed to get my Amkette TruBeats BT neckphone work with Fedora 17. Though the device gets paired with OS but the pulseaudio library crashes everytime I paired the device. This resulted in no device being showed up under System sound settings. Thus you can't listen to the music on your BT neckphone :(

There is a fix for this issue and here it goes:
1. Create audio.conf file under /etc directory.
2. Save the file with this content in it:
[General]
Disable=Media
Enable=Source,Sink,Gateway,Control,Socket
3. And finally reboot and its done :)

Now once you pair your device you will observe that pulseaudio is no more crashing !
Also you will be able to see your device under System sound settings:

I hope you find this post useful :)

Cheers!


Sunday, March 10, 2013

Guess whoami : RTTI

Hi guys,

This time we will explore the technique used to determine the type of objects at runtime using Run Time Type Identification(RTTI) in C++.

Basically there are two common ways to achieve this:
1. Use a virtual function in base class and override that method in derived class:
output:



And when you use base class pointer or reference to hold object you may use bptr->typeOf() to detemine the type of object at run time.

2. Another approach which is built into language library is to use typeid() method. This method returns const object of typeinfo type.
For example,


We can also use Explicit Typecasting in C++ using :
dynamic_cast:
 It is used to ensure that the object returned after cast is complete object of requested type. If its not so it returns bad_cast exception in case of references and returns null pointer in case of pointers.
Consider non-polymorphic base class and its derived class:
This will not even clear the compilation phase. It will give this error:
Lets convert base class to polymorphic by adding virtual keyword for hello method in base class and check again. This time it clears compilation and the type is checked at run time. This is purely based on RTTI support by compiler.
static_cast: 
In this cast operator it is not checked that object returned after casting is actually a type of requested object. It is not type safe. Thus it is upto developers to take care when dereferencing. This works for:
  • Implicit conversions
  • Narrowing conversions
  • Conversions from void *
  • base class pointer to derived class pointer 
  • derived class pointer to base class pointer
For example:
This will yield:
const_cast:
This cast is useful to convert const to non-const objects. This is used as another alternative to change const objects in a class without using mutable keyword.
For example,
output:
reinterpret_cast: 
This cast is used to convert any pointer type to any other pointer type, even for unrelated classes. It can also be used to convert int to pointer and other way round.
For example,
This will yield:
I hope this helps you understand basic typecasting mechanism present in C++. Stay tuned for more fun !