Sunday, March 13, 2011

The Fallible Maker

Beseech in belief and I grant you your soul.
Ever pondered how much a The Maker had laid his faith on The Believer. He created The Believer with so much of faith that he didn’t even leave a trace back on The Believers body. We, The Believer, never got to know that He, The Maker, created us with his own hands. Never in this life he came in to say that I created you, be gratified to me. He was so selfless that he was busy creating different forms of us while we were busy naming ourselves Ram, Rahim, Jhon or maybe Malcovich. He was so mesmerized with his own work that recognition was not required. But err is human, and since he created us, infallibility didn’t abscond from him. He did as grave mistake as could do, he believed that once created we will obviously praise him for his work which, while construction never got into him. But now he was lurking for the insatiable fame that he wants to be bestowed upon him for creating us. But instead he got nothing, zilch. So he started on what next big mistake he could do, messiah!. He started sending Messiah, this time he named them Jesus, Mohammed or Krishna, with much enthusiasm and fanfare he sent them in un-usual ways sometimes without fornication even some were airborne. We realized that greater forces play in this world than we know, later as they grew they told about him, The Maker. But mistake done is done and any correction can’t mend it completely, and repeated mistake is always punished, and so was The Maker. His fault this time was simple he created too many of them, all of them worked but with different prophecy and principal, results were varied and devastating. Instead of the Maker, we mistook messiah as our creator, further bifurcated was the ways of worship, like some being human sacrifice, which sometimes even the Maker never dreamed of. His errors were far more stretched with our actions crusades and wars, devastating and producing carnage of his own work. He’s still brooding over what can be done but as his created time ticks, his researched created sculptors are pinned to mother earth day by day. Was he so difficult to comprehend ?? or is some force greater than him has other notion for him. He still ponders on how to be perfect.
(Amen | Allah | Jai Sri Krishna)
If you can find out a solution for this mail him at maker.falliable@goddam.it.

(well this is from one old mail when i didn't think of blogging :) )

Thursday, July 22, 2010

Radix Sort

Here's a sample implementation of Radix sort, which internally implements count sort to store intermediate results. It sorts the data in O(n), yeah a linear sorting method. Amortized values will be O(kn) where k is the average length of typename. Sorting uses LSD -> MSB movement;
Also sample implementation is in C++ and works only for unsigned int. It can be typcased to work for int, long, float and even string.

http://code.google.com/p/samcoder/source/browse/trunk/codebase/src/RadixSort.h
http://code.google.com/p/samcoder/source/browse/trunk/codebase/test/RadixSortLSD.cpp

Radix Sort wiki -> http://en.wikipedia.org/wiki/Radix_sort

Happy Coding!

Tuesday, July 20, 2010

Listed Algorithms

Well in continuation of my effort to understand Algorithm. Here's a simple approach.
I gonna dump all my new codes in this opensource project and anyone is free to browse/use the source code. Well mostly they are copy cat from Introduction to Algorithm. But many a times it will vary. Most of the code is tested but i cant gaurentee accuracy. :)

http://code.google.com/p/samcoder/

BTW: QuickSort is checked.
http://code.google.com/p/samcoder/source/browse/trunk/codebase/src/QuickSort.h

EnjoY!

Thursday, July 15, 2010

Linked List (C++)

Here's a trivial linked list that i developed few hours back, use it for pedantic purpose. Obvious to say i don't bother what you do with the code.


#include <iostream>
namespace stdds
{
template <typename T>
class Node {
public:
T mData;
Node<T> *mNext;
Node(T pData):mData(pData),mNext(NULL){}
Node(T pData,Node<T>* pNextNode):mData(pData),mNext(pNextNode){}
};

template <typename T>
class LinkedList{
public:
Node<T> *mHead;
LinkedList(){mHead=NULL;}

bool InsertAt(T pData,int pSequence) {
}

bool PushBack(T pData) {
Node<T> *tTempNode;
if(mHead==NULL) {
tTempNode = new Node<T>(pData);
mHead = tTempNode;
return true;
} else {
tTempNode = mHead;
while(tTempNode->mNext!=NULL)
tTempNode = tTempNode->mNext;
tTempNode->mNext = new Node<T>(pData);
return true;
}
}

bool PopFront() {
if(mHead!=NULL) {
Node<T>* tTemp = mHead->mNext;
delete(mHead);
mHead=tTemp;
}
}

bool Insert(T pData,int pPosition) {
Node<T> *tPrevious = NULL;
Node<T> *tCurrent = mHead;
if(pPosition) {
int iCount=0;
while(tCurrent!=NULL) {
if(pPosition==iCount) {
tPrevious->mNext=new Node<T>(pData,tCurrent);
break;
}
tPrevious=tCurrent;
tCurrent=tCurrent->mNext;
iCount++;
}
} else {
mHead = new Node<T>(pData);
mHead->mNext=tCurrent;
}
}

int Find(T pData) {
int iCount=0;
Node<T>* tTemp=mHead;
while(tTemp) {
if(tTemp->mData==pData)
return iCount;
tTemp=tTemp->mNext;
iCount++;
}
return -1;
}

void RemoveAt(int pPos) {
int iCount=0;
Node<T>* tCurr=mHead;
Node<T>* tPrev=NULL;
if(pPos) {
while(tCurr!=NULL) {
if(iCount==pPos) {
tPrev->mNext=tCurr->mNext;
delete(tCurr);
break;
}
tPrev=tCurr;
tCurr=tCurr->mNext;
iCount++;
}
} else {
mHead=tCurr->mNext;
delete(tCurr);
}
}

void Remove(T pData) {
RemoveAt(Find(pData));
}

bool Print() {
if(mHead!=NULL) {
Node<T> *tTempNode = mHead;
while(tTempNode!=NULL) {
std::cout<<tTempNode<<" "<<tTempNode->mNext<<" ["<<tTempNode->mData<<"]"<<std::endl;
tTempNode=tTempNode->mNext;
}
}
}
};
}

Thursday, December 10, 2009

FreeBSD - enable su for users.

While tinkering with freeBSD it convinced of its abilities qualifing as development box. Well at home FreeBSD runs over Fedora (in VirtualBox - Bridged Networking mode) and i can ssh to it both from desktop and laptop. But its really a wonder that FreeBSD denies root access remotely (aka. ssh). One easy and rather non-acceptable way is to allow root to login ( enter PermitRootLogin in /etc/ssh/sshd_config ), but it breaks the whole secure feature of FreeBSD.
The optimim way is to add a user to do 'su' which later can be used to remote login.

Steps to add user to root group (wheel).
# pw user mod -G wheel
# groups

For new users just add it to wheel along with default group while doing adduser.


Next you can allow su for all users.
Follow these steps.
# vi /etc/pam.d/su

and look for
'auth requisite pam_wheel.so no_warn auth_as_self noroot_ok exempt_if_empty' and comment it.

Happy sshing. "_"

Friday, March 6, 2009

TCP Header.

Learn this for if you are into networking.


0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |U|A|P|R|S|F| |
| Offset| Reserved |R|C|S|S|Y|I| Window |
| | |G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

TCP Header Format

Note that one tick mark represents one bit position.

Details http://tools.ietf.org/html/rfc793#section-3.1