Thursday, October 7, 2010

Basic Template with Ingredients for a Technical Blog

A good Technical Blog Post follows the Law Of Retention: repetition helps Retention

Some Questions on your Blog Post:
  • Is your blog a frequently used resource for yourself and your readers? 
  • Does it grow as you learn more - addressing different levels of questions?
  • Is it short and informative while being complete and self-contained? 
Is your blog addressing The Readers Perspective?
  1. What's in it for a Reader?
  2. Tell 'em what you're going to Tell 'em.
  3. Tell 'em.
  4. Tell 'em what you just told 'em.
  5. Further info.

Wednesday, October 6, 2010

Understand Source Code by Reading Code and Refactoring for Maintaining Large Projects

This list consists of one-liner tips to be used for easy lookup and reference.

Rewriting Code for Better Understanding (Coding Horror)

  • What I cannot create, I do not understand. [Richard Feynman]
  • "What I do not create, I do not understand."[Chris]
  • "It's easier to understand 600 tables than 100,000 lines of code." [PaulC on comp.databases.theory/2005]
  • Create a new project with blocks of code copied from old code. Refactor to reduce "old code smell"
  • Start refactoring by adding small tests to better understand code and act as regression tests.
  • Just scan through huge amounts of code till it starts making sense - "understand by constant exposure".
  • Create a text file to capture your understanding - briefly describe how the component works, realtions to other components, what it persists, its states, and source browsing/debugging tips you found useful.
  • Manually reformat a copy of the code - white space, and indented as per your personal style.
References:
  1. Working Effectively with Legacy Code
  2. Object Oriented Reengineering Patterns
  3. Refactoring: Improving the Design of Existing Code

Howto Start a Blog, Get Useful Blogging Ideas, Add Good Content, Reduce Effort with Tools and Keep Blogging


Avoid Bloggers-Block:
After the initial burst you can't think of what to say - so the blog languishes.
A blog is short form for web-log i.e. a kind of "A log entry in your Personal Diary".
It is not meant to be a book which you publish after many many rewrites and deep thought.
Some people even have one-liners or even other peoples blogs as blog-entries.
Find an Idea/Topic:
Your idea becomes self sustaining if it's useful or matters to you or your friends.
You can organise your self-learning or teaching notes as blogs. Collect questions from people around you or from forum newbies.  This way you create more knowledge for yourself and write excellent blog-posts that are useful to others.
Publish or Perish:
Publish as soon as you have a line of text on your blogs.
Drafts are the best way to kill blogs.
Use them only when you require to do some basic tidying before posting.
Even this can be done later followed by a republish.
Blog Incrementally:
Paste your current state into the blog (like saving a session of your mind a.k.a. brain-dump).
Every time some find some new useful information you just paste that into your blog-post.
Use a multiple clips clipboard manager to copy all the info you need.
The post should be written in logical manner with least gaps in the reasoning or steps
Any good links that you open in Firefox tabs can be saved for:
    a) Further investigation
    b) Future use
Reduce Blogging Effort:
Ideally follow 80-20% rule.
Spend 80% time spent on gathering material.
Spend 20% time spent on filling in gaps and reordering/rewriting post.
See Tools section for more details
Tools:
Currently I'm trying to reduce editing/formatting effort/time by using the following tools:
Blog Upload: Evaluating desktop client s/w's for editing and posting to blog (like ScribeFire, Windows Live Writer, SeMagic)
        I've used 2-3 good desktop blogging clients:
      
1) ScribeFire to handle blog-editing, upload and managing of multiple accounts/blogs.
           Looks to be the best option for now.
        2) Kompozer is good for a basic HTML whysiwyg editor.
        3) Windows Live Writer - not really used it but looks good enough for basic blog maintainence.
Blog Composing: Kompozer, CSS Stylesheets (TODO)
MindMaps: XMind with Freemind (for mindmaps and concept maps with collaboration respectively)
Pictures: Paintbrush Digicam for Photos, MediaWiki Free Photos
Video: InstantDemo, Jing ScreenCapture software for Demonstration Videos.
        Diagrams: Diagramming s/w (To-Do)
Uploading: To-Do
See Also:Basic Format  for a Technical Blog

Tuesday, October 5, 2010

Howto Improve your Blog's design


Accessibility: Does the title grab the attention of your intended audience?
  1. Does the title have keywords used by the audience while searching google?
  2. Does google index your blog regularly?
  3. Push your blog updates to blog broadcastors like weblogs.com
  4. Does your blog load up fast? Use the "Jump/Read More" feature and Optimize load time.

    Retention: Is it easy for a casual browser to remember your blog and info you pain-stakingly put in?

    Tuesday, September 28, 2010

    mmap() is not the territory!! Part 2

    Final code at end of debugging:

    bool testFileCopyWithSharedMem(const string &srcFileName, const string &destFileName)
    {
        bool isCopyOk = false;
        string diffCmd = "diff " + srcFileName + " " + destFileName;
        int retval = system(diffCmd.c_str());
        cout << "system(" << diffCmd << ") returned: " << retval << endl;
        if( retval == 0 )
        {
            isCopyOk = true;
        }
        return isCopyOk;
    }

    int doFileCopyWithSharedMem(const string &srcFileName, const string &destFileName, size_t sharedMemSize)
    {
        //int retval = 0;

        //Map SourceFile
        errno = 0;
        int srcfd = open(srcFileName.c_str(), O_RDONLY);
        if (srcfd < 0) {
            const char * causeOfError = strerror(errno);
            cout << "open() returned:" << causeOfError << " at:" << __LINE__ << " in:" <<__FUNCTION__ << endl;
            cout << "open(" << srcFileName << ") returned: " << srcfd << endl;
            return -1;
        }
        struct stat sb;
        fstat(srcfd,&sb);
        long pageSize;
        //pageSize = sb.st_size;
        pageSize = sysconf(_SC_PAGESIZE);
        errno = 0;
        char *srcFilePtr = 0;
        srcFilePtr = (char *) mmap(0, pageSize, PROT_READ, MAP_SHARED, srcfd, 0);
        if (srcFilePtr == MAP_FAILED)
        {
            const char * causeOfError = strerror(errno);
            cout << "mmap() returned:" << causeOfError << " at:" << __LINE__ << " in:" <<__FUNCTION__ << endl;
            return -1;
        }

        //Map Dest File
        errno = 0;
        int destfd = open(destFileName.c_str(), O_RDWR|O_CREAT|O_TRUNC, 0600 );
        if (destfd < 0) {
            const char * causeOfError = strerror(errno);
            cout << "creat() returned:" << causeOfError << " at:" << __LINE__ << " in:" <<__FUNCTION__ << endl;
            cout << "creat(" << destFileName << ") returned: " << destfd << endl;
            return -1;
        }
        errno = 0;
        char *destFilePtr = 0;
        destFilePtr = (char *) mmap(0, pageSize, PROT_WRITE|PROT_READ, MAP_SHARED, destfd, 0);
        if (destFilePtr == MAP_FAILED) {
            const char * causeOfError = strerror(errno);
            cout << "mmap() returned:" << causeOfError << " at:" << __LINE__ << " in:" <<__FUNCTION__ << endl;
            return -1;
        }

        ftruncate(destfd, sb.st_size);
        cout<< "PID:" << getpid() <
        //cout << srcFilePtr << destFilePtr <
        system("cat /proc/self/maps");

        memcpy(destFilePtr, srcFilePtr, sb.st_size);
        //msync(destFilePtr, pageSize,MS_SYNC);

        munmap(srcFilePtr, pageSize);
        munmap(destFilePtr, pageSize);
        close(srcfd);
        close(destfd);
        return 0;
    }
     
    ----------------------------------------------------------------------------
    Time required:  
    Debugging 1 AM to 5:40 AM. 
    20 Minutes to note down these points in the blog. 
    2 hrs to massage it into shape.

    Interesting Links:
    DevShed : development tutorials: http://www.devshed.com/
    Gentoo Bug Reporting Guide: http://www.gentoo.org/doc/en/bugzilla-howto.xml 
    C sample source on Gnu/Linux : http://www.c.happycodings.com/Gnu-Linux/index.html
    Mmap() security bug with Null Pointers: http://blog.ksplice.com/2010/03/null-pointers-part-i/
    Wiki on Chromium multi-process debugging with gdb: http://code.google.com/p/chromium/wiki/LinuxDebugging
    BugReport: http://www.mail-archive.com/ubuntu-bugs@lists.ubuntu.com/msg2333427.html 


    mmap is not the territory Part 1 : http://techtalkies.blogspot.com/2010/09/mmap-is-not-territory-or-mapfail-sigbus.html