Monthly Archives: March 2012

Undirected Graph

The following small program illustrate how to implement a undirected graph with costs to neighbor nodes. #ifndef _GRAPH_HPP_#define _GRAPH_HPP_#include #include #include using namespace std;/* * Undirected graph class */class Graph {public: Graph(unsigned int id=0) { m_id = id; m_Ecount = … Continue reading

Posted in Uncategorized | Leave a comment

MIVO.TV Network Analysis

While my browser was playing the video streaming (tru flash-plugin) from mivo.tv,  a “netstat -t” revealed high traffic as below: tcp        0      0 192.168.0.29:56448          68.68.29.24.:macromedia-fcs ESTABLISHED After googling this “macromedia-fcs” I … Continue reading

Posted in Uncategorized | Leave a comment

Hash template in C++

#include #include #include using namespace std;struct eqstr { bool operator() (const char *s1, const char *s2) const { return (::strcmp(s1, s2) < 0 ? true : false); }};int main(){ // template map months; months[“january”] = 31; months[“february”] = 28; months[“march”] … Continue reading

Posted in Uncategorized | Leave a comment

ELF File Format

The C++ source code below: #include #include using namespace std;class CParent {public: CParent() { ref++; cout << "class CParent: constructor ref=" << ref << endl; Function(); }; virtual ~CParent() { ref–; cout << "class CParent: destructor ref=" << ref << … Continue reading

Posted in Uncategorized | Leave a comment

Google Interview (3)

Question:How would you reverse the image on an n by n matrix where each pixel is represented by a bit? Answer:I: n x n matrixI[0][0] represents 1 byte at the left-most, top-most corner (8 pixels). Just image it as columns … Continue reading

Posted in Uncategorized | Leave a comment

Google Interview (2)

Question:How many degrees are there in the angle between the hour and minute hands of a clock when the time is a quarter past three? Answer:The stupid and quick answer would be 0 degree. But, if we rethink again, it’s … Continue reading

Posted in Uncategorized | Leave a comment

A Google Interview

Question:If a person dials a sequence of numbers on the telephone, what possible words/strings can be formed from the letters associated with those numbers? Answer:Let’s analyze this. On a handset, there are keys with number ‘0’ to ‘9’.  Assume we … Continue reading

Posted in Uncategorized | Leave a comment

Fast Hashing of Variable-length text strings

The following Hash algorithm based on a research paper written by Peter Pearson (a scientist at Lawrence Livermore National Lab) has an ability to generate unique hash numbers for strings with lengths no longer than 256 bytes. That means, we … Continue reading

Posted in Uncategorized | 2 Comments

Print Canonical Addresses of a Site

This 2 lines of Python queries DNS and display the canonical names of a host.  It’s like a simple DNS lookup (nslookup). #!/usr/bin/pythonimport sysimport socketHOST=”PORT=80if (len(sys.argv) < 2): print sys.argv[0], ” ” sys.exit(0)HOST = sys.argv[1]for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, … Continue reading

Posted in Uncategorized | 1 Comment

Python GUI

This small Python script creates a window application and handles menu events as well as updating statusbar at the bottom. #!/usr/bin/pythonfrom Tkinter import *import tkMessageBoxclass StatusBar(Frame): def __init__(self, master): Frame.__init__(self, master) self.label = Label(self, text=””, bd=1, relief=SUNKEN, anchor=W) self.label.pack(side=BOTTOM, fill=X) … Continue reading

Posted in Uncategorized | Leave a comment