Public Email (Random Ideas)

July 30, 2010

Email are a strange beast. They try to mimic normal snail mail, but we Email are way different from snail mail. You have multiple sender, you can carbon copies, you can have blank carbon copies, you forward them. Any time you have an operation on an Emaul the operation happens on the copy of the email. At least that what the perception is given to the normal user.

Different Email clients have made it possible to see Emails in totally different ways. For example Gmail let you see a thread of conversion group together. Although it is one of those features which either someone absolutely loves to absolutely hates it.

I have trying to think about Email or Variation of Email system with out any particular problem in mind. So basically i am trying to think of variation of Email and then trying to find how it can be used. Agree this might not be a optimal way to solve anything useful, but it is a fun excersise.

So lately I have been thinking about a Public Email system. A inbox shared by everyone or an inbox anyone has access. Think of a mail box in the middle of a town with an address and people can send mail to it and anyone can read it. Once some reads it the mail is gone. So first come first server principle applies here. Further more the person who read it can then forward/reply like a normal email.

What will be a system like that useful for?

My take on Facebook Privacy: Lets get rid of Facebook

May 8, 2010

I have been trying to come up with a design for a Open Social Network. Something you can host yourself or use from a “trusted” third party with the ability to seamlessly connect with each other.

The idea is:

  1. You take your data where you want
  2. You control you privacy
  3. Seamless integration with different installation running all around the world.
  4. Open Source (So it can be peer reviewed)
  5. Tools for migrating from facebook and other Social Networks
  6. Dead simple and user friendly UI. Built for people who can not differentiate between facebook and readwriteweb

I will like to publish the design and start working on the basic implementation. If anyone interested in joining the project or has similar idea i will love to talk about it.

How to kill an unresponsive ssh session

April 27, 2010

This is a Life saver! via http://www.laszlo.nu/post/553591402/how-to-kill-an-unresponsive-ssh-session

I often find myself in the somewhat cumbersome situation that a currently running ssh session stops responding, often due to a lost connection. The normal ctrl+c of course doesn’t work, the ssh client catches all the usual commands, which is very handy while you are still connected to the host but not very handy at all in this case.

My usual approach has been to switch to another terminal window or shell and then killing the process in question. Today I happened to be skimming through the ssh client’s man page and I found a section about escape characters. Suddenly I gazed upon the glory of the disconnect key sequence: a newline followed by ~.. It works like a charm. As always, I thought I should share.

And even more interesting suggestion in the comments:

Also interesting: You can press ~C and receive an ssh> prompt, where you can press ? for help. This prompt lets you enter additional -L or -R forwards you may have forgotten when starting the session. Very handy if you don’t want to log out and back in.

Missing libstdc++.so.5 in Ubuntu 9.10 (Karmic)

November 25, 2009

I you end up seeing following error or something similar while running a non-ubuntu app:

error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory

Well the reason is libstdc++.so.5 was removed in Ubuntu Karmic. Fear no follow the following simple steps to get your old application running again.

cd /tmp

wget http://security.ubuntu.com/ubuntu/pool/universe/i/ia32-libs/ia32-libs_2.7ubuntu6.1_amd64.deb

dpkg-deb -x ia32-libs_2.7ubuntu6.1_amd64.deb ia32-libs

sudo cp ia32-libs/usr/lib32/libstdc++.so.5.0.7 /usr/lib32/

cd /usr/lib32

sudo ln -s libstdc++.so.5.0.7 libstdc++.so.5

~TH

Every language evolves into Java or COBOL

October 21, 2009

[Python-ideas] Proposal: Moratorium on Python language changes

This proves my dictum “Every language evolves into Java or COBOL”.

For the sake of backward compatibility a hip language stop innovating. Then comes a new language and with feature this language has not implemented for a while for the sake of backward compatibility.

The new language claims that the hip language is dead and become the new hip language.

and the cycle goes on …

python selection from a list

May 18, 2008

Python has various Functional Programming Tools including:

While working on my *super secret* application for Google App Engine. I realized i was using an operation over and over again which can not be efficiently performed by above tools(or at least i am not that expert in python yet!)

The operation is:

“select from a sequence, the first element that satisfy a certain condition”

Well i roll out my own function to perform such operation

def select(test, list):
  """
  Select the first element from a sequence that
  satisfy the given test function
  - compare The test function should have following
  signature def test(item): and must return a boolean
  - list The List from which element need to be selected
  """
  selected = None
  for item in list:
    if test(item) == True:
       selected = item
       break;
  return selected

For example if we want to select the first number from a sequence that is divisible by 2 we have to write some code like this:
>>> list = [1,7,6,9,21,34]
>>> select(lambda x: x % 2 == 0, list)
6

What are the other elegant ways of doing this in python or in your favorite language?

~TH

Prefix searching with Radix Tree

January 24, 2008

Recently I have to implement prefix searching for a project. The searching need to be scalable and the result are to be returned as quickly as possible. The front end for this search was a Ajax suggestion like search. The screen shot below shows the prefix searching in action.

Ajax prefix search

Ok this pretty simple Ajax stuff, nothing fancy and nothing new. What I am going to discuss is the backend not the frontend for such a prefix searching component.

One of the most common implementation used for prefix searching is:

select * from some_table where some_field like ‘prefix%’

In other word put all the words to be searched in a table and use the like clause. This works and has reasonable performance too for small number of queries. But if you have continuous deletion and insertion of new search words then this solution does not scale well for large number of users.

So let put these words in memory for faster response time. How do we search prefixes if we have all the words in the memory?

Put them in a list and do a sequential search? Ok you guess that too slow….. Put them in a hash table? What key we are going to search in the hash table we have only part of the key (prefix)!!

You must agree prefix searching is a specialized problem which requires a special data structure that is geared toward prefix searching. You have read the title so you know the name of that data structure. Yes Radix tree is one of such data structure that is suitable for prefix searching. A radix tree, Patricia trie/tree, or crit bit tree is a specialized set data structure based on the trie that is used to store a set of strings.

Trie is a multi-way tree structure useful for storing strings over an alphabet. The idea is that all strings sharing a common stem or prefix hang off a common node. The elements in a string can be recovered in a scan from the root to the leaf that ends a string. All strings in the trie can be recovered by a depth-first scan of the tree.

Below is a trie for keys “to”, “tea”, “ten”, “i”, “in”, and “inn”.

Trie

You can consider a Radix tree a condense form of Trie, in which intermediate nodes are merged together to save space. Below is shown the insertion process in a Radix tree.

Radix tree

I wrote a simple Java implementation for radix tree for the prefix search application mentioned above. You can find the code at http://code.google.com/p/radixtree/

I like tree structures because of their recursive nature, looks really natural to me ;) Most of the operation on Radix tree like insert, delete, find, etc can be easily implemented a recursive manner. Apart from the insert method another interesting method in implementation is visit() method it is there to help with other operation like delete, find and contains

    /**
     * recursively visit the tree based on the supplied "key". calls the Visitor
     * for the node those key metches the given prefix
     *
     * @param prefix
     *            The key o prefix to search in the tree
     * @param visitor
     *            The Visitor that will be called if a node with "key" as its
     *            key is found
     * @param node
     *            The Node from where onward to search
     */
    private void visit(String prefix, Visitor visitor,
            RadixTreeNode parent, RadixTreeNode node) {
        int i = 0;
        int keylen = prefix.length();
        int nodelen = node.getKey().length();

        // match the prefix with node key
        while (i < keylen && i < nodelen) {
            if (prefix.charAt(i) != node.getKey().charAt(i)) {
                break;
            }
            i++;
        }

        // if the node key and prefix match, we found a match!
        if (i == keylen && i == nodelen) {
            visitor.visit(prefix, parent, node);
        } else if (node.getKey().equals("") == true // either we are at the
                // root
                || (i = nodelen)) { // OR we need to
            // traverse the childern
            String newText = prefix.substring(i, keylen);
            for (RadixTreeNode child : node.getChildern()) {
                // recursively search the child nodes
                if (child.getKey().startsWith(newText.charAt(0) + "")) {
                    visit(newText, visitor, node, child);
                    break;
                }
            }
        }
    }

Off course you can have better look at the implementation by visiting the online code repository at http://radixtree.googlecode.com/svn/trunk/RadixTree/

Update: I have remove the link to the old download distribution, Please download the latest code from http://code.google.com/p/radixtree/ As there are some bug fixes and improvements.

Custom Javascript toggle button

September 29, 2007

Just as i was coding on my “personal project”, i need a javascript customizable toggle button (replacement for traditional Checkbox). As being strongly in favor of code reuse i first tried the “Google exposed world”. But this time Google disappointed me, i could not find a decent toggle button script that i can simple drop in my project.

So i decided to roll up my own. As i was writing it i decided to make it a blog post too!

I decided to write a toggle button i such a way that i do not have to insert javascript code all over my pages. So i start with a ToggleButton class.

toggle.js

/**
* A Custom toggle/checkbox component
*
* div - The div that will be converted to toggle button
* check - the intial state of the toggle button (possible values ture/false)
* val - the value ssociated with this toggle button. This value is passed to the call back method.
* this way you can store any sort of infromation with the toggle button.
* callbk - the call back method that will be called when a toggle action is performed
* (method signature callback(val, check))
*/
function ToggleButton(div, check, val, callbk)
{
this.checked = check;
this.value = val;
this.callback = callbk;

// store the old inner text
var text = div.innerHTML;
div.innerHTML = "";

// create a element
var a = document.createElement("a");
a.href="";

// bind the current object to the mouse event
a.onmouseover = this.over.bind(this);
a.onmouseout = this.out.bind(this);
a.onclick = this.click.bind(this);

// create a element
var img = document.createElement("img");
if (check)
{
img.src = ToggleButton.IMAGE_NAMES[1];
}
else
{
img.src = ToggleButton.IMAGE_NAMES[0];
}

img.border = "0";
img.hspace = "0";
img.vspace = "0";
img.align = "absmiddle";
a.appendChild(img);

// create a Text node (for toggle button title)
var title = document.createTextNode(text);
a.appendChild(title);
div.appendChild(a);

// store the image withe toggle button

// because we need to later change(toggle) it on different events
this.image = img;
}

ToggleButton.prototype.over = function ()
{
this.image.src = ToggleButton.IMAGE_NAMES[this.checked + 2];
}

ToggleButton.prototype.out = function ()
{
this.image.src = ToggleButton.IMAGE_NAMES[this.checked * 1];
}

ToggleButton.prototype.click = function ()
{
this.checked = !this.checked;
this.image.src = ToggleButton.IMAGE_NAMES[this.checked * 1];

if(this.callback == Function)
{
this.callback(this.value, this.checked);
}
else
{
var code = this.callback + '(' + this.value + ',' + this.checked + ')';
eval(code);
}
return false;
}

// the default images for the toggle button
ToggleButton.IMAGE_NAMES = new Array();
ToggleButton.IMAGE_NAMES[0] = "images/togglebutton0.gif";
ToggleButton.IMAGE_NAMES[1] = "images/togglebutton1.gif";
ToggleButton.IMAGE_NAMES[2] = "images/togglebutton2.gif";
ToggleButton.IMAGE_NAMES[3] = "images/togglebutton3.gif";
And here is how we use it…

test.html

<!doctype html public "-//w3c//dtd html 3.2 final//en">
<html>
<head>
<title>Cutsom Toggle Button</title>

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="toggle.js"></script>

<script>
function initToggleButtons()
{
$$('div').each(function(item)
{
if(item.readAttribute('togglebutton') != null)
{
new ToggleButton(item, item.readAttribute('togglebutton') == 'true' ? true : false, item.readAttribute('togglevalue'), callme)
}
});

}

function callme(value, check)
{
$('value').innerHTML = "togglevalue=" + value + " :: checked=" + check;
}

window.onload = initToggleButtons;
</script>

</head>

<body>

<div togglebutton="true" togglevalue="11111">Hell of day</div>
<div togglebutton="false" togglevalue="22222">Bad bad!</div>
<div togglebutton="true" togglevalue="33333">not sure</div>
<div togglebutton="false" togglevalue="44444">what ever</div>

<div id="value"><div>

</body>
</html>
All the magic happens in the initToggleButtons. What it does is that it simply convert all div with togglebutton attribute into check boxes. I have used prototype.js to make this task a bit easy. There is also a method callme it is a callback and gets called when ever a toggle button is clicked. The value mention in the div and toggle status is provided to it. You can do a AJAX call here or what ever you want to do.

Oh and here is a screenshot
toggle.jpg

Flex 2 mxmlc batch compilation using ANT

July 11, 2007

(Warning: I am not a big fan of Flex 2 or Flash in particular)

I was working on a small demo for a client. This demo was requested to be built with Flex 2. So i downloaded the SDK and starting hacking around.

When i end up with quit a few mxml file, compiling them start to become a headache. Because for the stupidest reason mxmlc does not compile multiple mxml files at once. Unfortunately i had to use a Windows based machine for creating particular demo.

As the application back end was in Java, so ANT was my automatic choice for build. But the problem was how to compile multiple files with mxmlc

It was simple task if i was on Linux box as i am quiet familiar with bash scripts. At this point i started to look at how to write advance script in windows bat files. More specifically i was looking for a some sort of loop structure that can iterate over all the files in a directory. In the end i end up with following bat file:

batch-mxlc.bat

for %%m in (%1\*.mxml) do call "%FLEX_HOME%bin\mxmlc.exe" -output "%2\%%~nm.swf" %%m

This bat file takes two arguments, first one is the input directory where your mxml files are present. The second parameter is the path to the output directory where you want your swf files to be generated.

The ANT script is simple and easy it just uses the exec task

<target name="help">
<exec executable="cmd">
<arg value="/c"/>
<arg value="batch-mxmlc.bat"/>
<arg value="${input.dir}"/>
<arg value="${output.dir}"/>
</exec>
</target>

The Save Icon

May 23, 2007

Save Icon Smaller Save Icon Smaller Save Icon

Did you recognize what these icons are used for?

I bet majority of us must have recognize it. It is the so-called “Save Operation” icon. (always wonder what they save us from :) )

But what this image actually represents?

Yes the image represents a Floppy Disk. And the reason is that long a go floppy disk was the most commonly used visible storage media. That’s why it has become a standard image for save operation.

Wikipedia has a more detail entry.

For more than two decades, the floppy disk was the primary external writable storage device used. Also, in a non-network environment, floppies have been the primary means of transferring data between computers (sometimes jokingly referred to as Sneakernet or Frisbeenet). Floppy disks are also, unlike hard disks, handled and seen; even a novice user can identify a floppy disk (although this may change as they become less common). Because of all these factors, the image of the floppy disk has become a metaphor for saving data, and the floppy disk symbol is often seen in programs on buttons and other user interface elements related to saving files.

Although Dell still sell Floppy drives but Europe’s one of the largest computer store PC world store do not like floppies anymore.

But one thing is for sure Floppy drive does not represent the “primary external writable storage device” anymore.

So is not the time has come to change this Save icon image. Tango Desktop (help create a consistent graphical user interface experience for free and Open Source software) uses hard drive for the save action.

Tango Save Tango Save Smaller Tango Save Small

What you think should be the represented image for Save Action?

OR what other images you have seen for this action?

~TH


Follow

Get every new post delivered to your Inbox.