Tuesday, May 28, 2013

Writing good code

Here I'm listing out some principles that I've picked up so far after writing code and getting them reviewed by some peers or other sites etc.
1. No repeatation
2. Try to make it as readable as possible, like try to make it look like plain English as much as possible.



Here are some links to help on that case:
1. [ http://net.tutsplus.com/tutorials/html-css-techniques/top-15-best-practices-for-writing-super-readable-code/ ]

Sunday, May 26, 2013

[PHP] Turn multiple input fields / selections into a single array

While trying to design a form so that it takes multiple inputs from text fields and multiselect selection menus, I was facing problem because even though I could handle a fixed number of fields in my script internally, what for multiple selections in a selection list?? The rescuer [] :)
Yes, just use it after the name of you input field, this way.
<select multiple class="input-medium search-query" id="autolist-filter-select" name="filter_str[]">
<input id="autolist-filter-text1" type="text" name="filter_str[]"/> <input id="autolist-filter-text2" type="text" name="filter_str[]"/>

Friday, April 05, 2013

Friday, March 29, 2013

#HACKATH0N [2.5]: Meet up of the Backbenchers

Mark this day, an example of destiny. Only the backbenchers of the BD-LFS group met up today. Somehow the good boys didn't show up. Robin Bhai had leg pain due to dancing rehearsals. Kabir Bhai had set foot for the meet up only to find himself hurt in the leg and returning home. We almost thought today should be announced "Leg Injury Day" but didn't do so because Tapan bhai didn't show up without reporting any leg injury. All in all we just had one mentor #R!NE to lead us to the same level as the regular good guys.


We ended up doing the things that #Hackathon-2 had left us with. Me and RINE were not present in that due to personal issues. So, I just made the best use of this day to improve my knowledge and sync up with the rest of the group.

Initially we had problems regarding VM setup which was almost dragging us towards failure. But somehow, by the hand of God we recovered from that state after me, Rahid Bhai and Mamun Bhai managed to build the systems up. We ended up creating the LFS system's base camp for compilation and tool sets. It was fun and in between Rine was helping us understand the concepts that were in play with what we were doing.

We shared a lot about our experiences with different OS setups. I liked the way we shared knowledge about shells. Came to know about some of those from Mamun bhai.

Particularly, the venue this time was Sphinx Corporations. Shihan Bhai's new software company. We had a great venue indeed since the sitting arrangements allowed us to really enjoy the mash up. The lunch was fun too since there was great gossip and knowledge sharing. All in all it was awesome, for the Backbenchers ;p

Participants:
1. Tafhim (Me)
2. Rine (Rine Toufique Anam)
3. Mamun bhai (Abdullah al Mamun)
4. Rahid bhai (Rahid Hasan)
5. Aman bhai (Md. Aman Ullah)

Topics covered:
1. Preparing LFS Partition
2. Setting up LFS usergroup and account
3. Compiled BinUtils (First phase)
4. Compiled GCC (First phase)

Issues:
1. VBox machine setup [20 GB Partition, 2 GB swap, 8 GB Host OS, 10 GB LFS Partition
2. Dependency resolving issue during G++, GAWK, BISON installation. Fixed by choosing an Australia based server. Even though using "Choose the best server" solved the slow download issue but it doesn't always choose a repo that can resolve all dependencies. We tried different repos and had zero dependency issues of packages using Australian servers.
3. In case of slow download speed of packages you should change your repo and choose a good one using Synaptic
4. We primarily came to a unified decision to arrange the next Hackathon atleast 1 and 1/2 months from today so that all of us can complete the LFS book before that.


Target of the next Hackathon (3): Start [B/C]LFS

Friday, February 15, 2013

[UVa] 10926 - How many dependencies

#include <cstdio>
#include <iostream>

using namespace std;

#define init(n) { for (int i=0 ; i<=n ; i++) { visit[i] = false; for (int j=0 ; j<=n ; j++) adj[i][j] = adj[j][i] = false; } }

int n, dep[200], root[200], adj[200][200];
bool visit[200];

int dfs_visit(int s, int src) {

    root[s] = src;
    dep[s] = 0;
    for (int i=1 ; i<=n ; i++) {
        if (!visit[i] && adj[s][i]) {
            visit[i] = true;
            dep[s] += (dfs_visit(i,src)+1);
        }
    }
    return dep[s];
}

void dfs() {

    for (int i=1 ; i<=n ; i++) {
        for (int j=0 ; j<=n ; j++) visit[j] = false;
        dfs_visit(i,i);
    }

}

int main( void ) {

    int t, x, maxdepi, maxdep;

    while (scanf("%d",&n)==1 && n) {

        init(n);

        for (int i=1 ; i<=n ; i++) {
            scanf("%d",&t);
            for (int j=0 ; j<t ; j++) {
                scanf("%d",&x);
                adj[i][x] = true;
            }
        }


        dfs();

        maxdep = -1000;

        for (int i=1 ; i<=n ; i++) {


            if (dep[i]>maxdep) {
                maxdep = dep[i];
                maxdepi = i;

            }
        }

        printf("%d\n",maxdepi);

    }


    return 0;
}


Friday, February 01, 2013

XEN Hypervisor

This is something that I want to do in future with my system. Currently can't do it cuz I don't have the Hardware :S But I will :) [ http://forums.linuxmint.com/viewtopic.php?f=42&t=112013 ] [ http://blog.xen.org/ ]

How to Uninstall Linux / Remove GRUB / Go back to hell

Many users, mostly pretentious Linux enthusiasts come to me and ask "How to uninstall Linux". Apart from trying my best to hide my disgust (personal reasons, no offense), most of the time I answer like "It's hard to make you understand the process". Today when I was browsing the "How to" section of my favorite distro, I stumbled upon a collection of methods to do this. Here's the link:
[ http://forums.linuxmint.com/viewtopic.php?f=42&t=98051 ]
Directly quoting them in case the link becomes inactive when the info is needed. Method 1: Let me begin by saying I think Mint 12 is a terrific OS, which I am using on several computers. But I have computers on which I use Music Bee in Windows 7 for my music files and want direct boot to Windows without any disk space devoted to Mint. I spent several days looking at complicated instructions for removing Grub and finally accidentally discovered a simple solution, which is as follows: In Windows, download Partition Wizard at http://download.cnet.com/MiniTool-Partition-Wizard-Home-Edition/3000-2094_4-10962200.html. Install. Partitioning will be blocked by Grub. But on your left hit Rebuild MBR. This will take only a few seconds. Reboot, and Windows 7 will boot. Then you can go into Partition Wizard and eliminate the Ubuntu partitions and expand your Windows data partition to take up the freed up space.
Method 2: 1. Boot-Repair iso burnt into a CD will boot and, if you opt for fix mbr, then only windows will boot, provied Windows is on the first partition, of course. Partitions are not deleted.

Download site:
https://help.ubuntu.com/community/Boot-Repair

2. Another way, from Windows itself, run the free windows utility called mbrfix.

I used both, and both work great.
Method 3: Much easier way: Remove Grub bootloader using LILO.

1. Open terminal and run commands

sudo apt-get update
sudo apt-get install lilo
sudo lilo -M /dev/sda mbr # assuming that grub is installed to disk sda

A video about removing: http://www.youtube.com/watch?v=oB8NVzkgdEA&feature=plcp
Note: This method might need a Live Boot

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...