@abhishekdelta – on life, universe and everythinghttps://abhishekdelta.wordpress.com
Because somethings can only be blogged about..., for everything else there is Github.
Sat, 17 Nov 2018 23:58:00 +0000 en
hourly
1 http://wordpress.com/https://secure.gravatar.com/blavatar/7f88d29de5a40d65b32d7051b7c3e0fb?s=96&d=https%3A%2F%2Fs0.wp.com%2Fi%2Fbuttonw-com.png@abhishekdelta – on life, universe and everythinghttps://abhishekdelta.wordpress.com
Take Riskshttps://abhishekdelta.wordpress.com/2013/09/08/take-risks/
https://abhishekdelta.wordpress.com/2013/09/08/take-risks/#respondSun, 08 Sep 2013 18:29:33 +0000http://abhishekdelta.wordpress.com/?p=619Continue reading →]]>Most of the time, life does not talk to you. It just sort of pushes you around. Each push is life saying, `Wake up. There’s something I want you to learn.’

If you’re the kind of person who has no guts, you just give up every time life pushes you. If you’re that kind of person, you’ll live all your life playing it safe, doing the right things, saving yourself for some event that never happens. Then, you die a boring old man. You’ll have lots of friends who really like you because you were such a nice hard-working guy. You spent a life playing it safe, doing the right things. But the truth is, you let life push you into submission. Deep down you were terrified of taking risks.

You really wanted to win, but the fear of losing was greater than the excitement of winning. Deep inside, you and only you will know you didn’t go for it. You chose to play it safe.

-from the book “Rich Dad Poor Dad”

]]>https://abhishekdelta.wordpress.com/2013/09/08/take-risks/feed/0jeremeThe epic transitionhttps://abhishekdelta.wordpress.com/2012/06/11/the-epic-transition/
https://abhishekdelta.wordpress.com/2012/06/11/the-epic-transition/#respondSun, 10 Jun 2012 21:06:32 +0000http://abhishekdelta.wordpress.com/?p=558Continue reading →]]>Blogging after a very very long time. And the reason is what this blog post is going to be about. My life has been going through a complicated phase, its the phase I have decided to call ‘The Epic Transition’. Transition, because you enter into the real world, become an independent with added responsibilities and no more you are a college-going student with a free soul. And its Epic, because it turns out to be the hardest phase of your life. Something which you can bear at most once and which will change so much in you that you’ll forget who you were before, and looking back would laugh upon the things you used to say once with certainty. You’ll realize that the things you thought to be right then were so wrong, and the promises you made to yourself were so impossible to achieve. You’ll come out of the dream world and step into the real world. Its like how Neo was rescued from the Matrix in the 1st part of the Matrix series. And just like in the movie, although it was the hardest part, painstakingly difficult to endure, but it was also necessary and it turns out the sooner you go through it, the better it is. It marks the end of your life as you used to see it, and compels you to create a new path for yourself. But as always, “the hardest part of ending is starting on again” – an except from the lyrics of one of my favorite Linkin Park song “Waiting for the End”.

The thing is, suddenly, everything that used to be so important to you would become meaningless. You’ll no longer enjoy watching movies alone, you’ll get bored with hanging out in malls and eating at dominos, activities which used to be fun would become so boring. I can’t say for sure if everyone goes through this with the same intensity, it could be even worse. Because for heaven’s sake, I still have my passion towards computers and like writing code. Others, they even lose their passion and that marks the biggest failure of their lives.

I’m not complaining. I think this is a chapter of life which had to open one day. It teaches you the things which no one ever told you before. It makes you do things which you didn’t had the guts to do before. But its like another big bang in your life, a new creation and a new beginning but what you make out of it and how it ends up is not totally in your control. At this point of your life, you’ll realize that situations have more control over you than you yourself do. You’ll be fighting them most of the time. Life becomes a struggle even though for others it would appear you are living a happy life. But you would know that the real Life has just began.

Welcome to the real world, Neo.

Now there’s only one way to survive – adapt yourself to the new rules, the games and the scenarios. The laws of nature have changed. The truth has become false and all old promises are broken. Its time to be practical and rational and do things the right way without being in the dream world. Its nasty, bad, unfair and greatly disappointing at times, but in the end if you survive, it will have it perks. That seems like a fair assumption, doesn’t it?

Note to myself – “Remember your goal. Do not stray away or procrastinate. Do not give up.”

Blogging resumes. Everything would be back to normal, but I’ve changed and my posts would reflect the same. Lets play this game, the practical way.

]]>https://abhishekdelta.wordpress.com/2012/06/11/the-epic-transition/feed/0jeremesvnlogger v0.1https://abhishekdelta.wordpress.com/2011/06/24/svnlogger-v0-1/
https://abhishekdelta.wordpress.com/2011/06/24/svnlogger-v0-1/#respondFri, 24 Jun 2011 05:26:26 +0000http://abhishekdelta.wordpress.com/?p=367Continue reading →]]>This one is for the Unix freaks (that includes me !). Remember the textual “ChangeLog” files we used to see in a lot of open source softwares ? It used to have the list of changes made to the software along with revisions number, contributor’s name and timestamp. I always liked the format of a particular kind of ChangeLog which showed all the details in a compact manner without losing any, helps me keep track of ‘What’s new!’ in my next version of the software. Anyways, so how do I make it ? For those of you who have been thinking that they’re hand-written, you’re so wrong ! After all, how can you expect an open source freak to do something ‘manually’ when he can easily automate any task in his computer using cool scripts ?? Anyways, usually they have some kind of Version Tracking System like CVS, SVN or GIT. I happen to use SVN most of the time, actually always, and since I needed to maintain a ChangeLog as well, I found there was a nice command called “svn log” which would generate a textual log of all the commits along with all the information I needed to see. Well, everything was there, but not in a way I wanted it to be. ‘svn log’ is good enough for ‘grep’ but not so good in terms of direct readability. So I wrote this small shell script that is basically a wrapper around the svn log but it uses AWK to reformat the data in a way I like it !

Copy paste the code below into a file called ‘svnlogger.sh’ and then execute it like

> sh svnlogger.sh <path-to-svn-repo> <path-to-changelog>

If you don’t mention either of <path-to-svn-repo> or <path-to-changelog>, it would take the current directory as default. Here’s a sample of the ChangeLog generated :

]]>https://abhishekdelta.wordpress.com/2011/06/24/svnlogger-v0-1/feed/0jeremePerfect configuration for Conkyhttps://abhishekdelta.wordpress.com/2011/04/19/perfect-configuration-for-conky/
https://abhishekdelta.wordpress.com/2011/04/19/perfect-configuration-for-conky/#commentsMon, 18 Apr 2011 20:54:51 +0000http://abhishekdelta.wordpress.com/?p=452Continue reading →]]>Okay, this one’s about some eye candy. One thing I regretted while parting my ways with Ubuntu was the good looking themes and applets it had. But no more, as they say, ‘thou shall seek, thou shall find’ and I’ve found whatever I needed in Arch Linux. After configuring everything, from kernel modules to gnome, I finally came to peace with the last missing piece in my puzzle – the Conky system monitor. Configuring it to suit the looks of my desktop was a hell of a task but I finally succeeded thanks to numerous tutorials on the internet and needless to say, google. For starters, Conky is just a system monitor that can be configured to monitor everything from your CPU’s temperature to internet speed to processes and hard disk space. You can even configure it to monitor your email or some RSS feeds you like. And the best part, is the looks, okay, take a look :

You like it ? You can have it for yourself. If you’re in Arch Linux like me, just do

pacman -S conky

For any other distro, use the appropriate command. For Ubuntu,

sudo apt-get install conky

For Fedora,

sudo yum install conky

Finally, when you’ve done that. Its time to configure it. Below, I’m posting the perfect configuration which should run out-of-the-box in your system with no dependencies. Copy the below code to a file named “.conkyrc” and put it in your home folder. Final path should be : ~/.conkyrc

Hope you liked it and appreciated it. You’re free to change the above configuration to suit your needs and distribute it.

]]>https://abhishekdelta.wordpress.com/2011/04/19/perfect-configuration-for-conky/feed/3jeremeConkyUpgrading to PHP 5.3 in Ubuntuhttps://abhishekdelta.wordpress.com/2010/12/27/upgrading-to-php-5-3-in-ubuntu/
https://abhishekdelta.wordpress.com/2010/12/27/upgrading-to-php-5-3-in-ubuntu/#respondSun, 26 Dec 2010 20:37:15 +0000http://abhishekdelta.wordpress.com/?p=442Continue reading →]]>I’ve been using PHP 5.2 for a long time now. I’m not so apt towards change but PHP 5.3 has some cool features which I needed very much for my projects. So yesterday I decided to do that conversion. The process was not at all so simple and it took lots of googling and searching the forums, especially for removing the post-installation bugs. Finally, at Dec 27 12:45 AM I achieved 100% transformation to PHP 5.3. As my usual habit, I like documenting the stuff I do, so here it goes.

First thing before starting the process is to make sure that none of my existing projects would break. Because as the developers have said, PHP 5.3 is a major release with lots of changes. Many new features were added while many were removed or deprecated. And to avoid getting unnecessary warnings or notices, it was better to recheck my codes for compatibility with PHP 5.3. The PHP developers have written a good page in the PHP Manual which tells in detail about the things to take care of when migrating to 5.3 from 5.2. You can check it here : http://php.net/manual/en/migration53.php

So don’t forget to go through that page once, at the least the section which tells about the “removed and deprecated” features in PHP 5.3 and use the alternatives as suggested. Now you’re ready to upgrade. BUT, before that, you’ve to know that any software you use like phpMyAdmin or ldapPhpAdmin which uses PHP might broke. Well, you cannot do anything about it but you’ll have to reinstall them. Anyways, moving ahead, take a backup copy of your php.ini configuration file. You may need it for reconfiguring your PHP 5.3. If you’re using Apache 2, it can be found in /etc/php5/apache2/php.ini

It may ask what to do about the new php.ini file. Choose to use the packager’s version of it. If its asks about removing phpmyadmin and would you like to use db-common, select NO if you want to preserver your databases. Thats it.

You’re done! Congratulations. You can check the version number from the output of phpinfo(); or in your command prompt type php -v to assure yourself. But the game is not over yet for the post-installation bugs are still roaming everywhere in your PHP installation. The bugs may vary for you, as it depends on the exact installation specifications, but I’ll tell you about the bugs I faced and if you have something in common, you can use the solution that worked for me. Lets refer to Post-Installation Bug as “PIB“.

PIB 1 : phpMyAdmin got uninstalled during the process of upgrading ! And when trying to install using “sudo apt-get install phpmyadmin”, it failed as it required php-mcrypt module which it seems cannot be installed in PHP 5.3.

The extracted files and folders should be directly inside /var/www/phpMyAdmin folder and not inside some other folder within it like /var/www/phpMyAdmin/phpMyAdmin-3.*.*/.

Now you’ve to create a config folder inside it with world writable permissions. You can run the following commands :

cd phpMyAdmin
mkdir config
chmod o+rw config

Now, from your browser, goto location http://localhost/phpMyAdmin/setup and fill out the information. You’ll have to create new server entry and use the default settings only. Also in auth_user, and auth_password, leave as it is. Nowhere you should write any username and passwords. And auth_type should be cookie. Now click on SAVE button below and a config.inc.php file would be generated inside the config folder you just created. If its not for some reason, then you can click the DOWNLOAD button and download the file. Then move the file to phpMyAdmin folder and remove the world-writable permission. Here’s the code (assuming you’re inside the phpMyAdmin folder) :

The sourcecode of phpMyAdmin is right now inside your webserver’s folder. I didn’t like that and may be you too. It was supposed to be at location /usr/share/phpmyadmin. Well there’s a simple way to do it. Just copy the entire phpMyAdmin folder to /usr/share and rename it to ‘phpmyadmin’ (all small caps). Now, open an editor and copy the following code :

Save the file as phpmyadmin.conf and copy it to your apache’s configuration folder. In my case, its /etc/apache2/conf.d (You will require root permissions).

Then, just reload your apache :

sudo /etc/init.d/apache2 reload

Then goto http://localhost/phpmyadmin and it will work smoothly. I didn’t do anything about the mcrypt extension problem because I was only using it on my local computer. However, if you’re some corporate guy and doing this for some online application, then I won’t recommend the above method.

PIB 2 : PHP PECL Extensions not working properly.
Solution : Install them again. But as with phpmyadmin, it was not so easy.

Now after you’ve done this, do that process again and the PECL HTTP extension would get installed. Now you can install any other PECL extension using the command :

sudo pecl install pecl_

Also after you install the extension you’ve to add the following line in your php.ini file :

extension = .so

PIB 3 : Lots of warning generated wherever I used the date() function.

Solution : The default timezone is not set because your previous ini file was overwritten. So just add this line in your php.ini file :

date.timezone = Asia/Calcutta

or whatever your time-zone’s name is. Just restart apache again and you’re good to go.

These are the problems I faced and their solutions. You may face other problems, you can if you want, leave a comment telling about your problem and I’ll try to answer it. Anyways, hope it worked for you and welcome to PHP 5.3 !

]]>https://abhishekdelta.wordpress.com/2010/12/27/upgrading-to-php-5-3-in-ubuntu/feed/0jeremeD. E. Shaw placement experiencehttps://abhishekdelta.wordpress.com/2010/12/20/d-e-shaw-placement-experience/
https://abhishekdelta.wordpress.com/2010/12/20/d-e-shaw-placement-experience/#commentsMon, 20 Dec 2010 09:47:47 +0000http://abhishekdelta.wordpress.com/?p=438Continue reading →]]>Hello there, just 4 months ago I got a job in D.E. Shaw through campus placements in my college NIT Trichy. To help my juniors and students from other colleges as well, I finally decided to write about my overall experience with the recruitment process of D. E. Shaw. But before that, lets tell you in brief about the company.

D. E. Shaw is an investment banking company which basically deals with investing other people’s money into right places to make more money out of it. It invests in a lot of places like share market, start ups, capital of other companies, so called “hedge fund”, etc. So in short, its a money-making machine. David E. Shaw worked at Morgan Stanley before leaving that job and founding the world’s biggest hedge fund company with total assets estimated at $30 Billion, almost same as Morgan Stanley now. Anyways, that’s enough history for you to know.

D. E. Shaw is basically a New York based company but has its offices all over the world, including Hyderabad, Mumbai and Gurgaon in India, but if you’re being recruited from India for a software job, you are most likely to get placed in Hyderabad. They’re known for their tough recruitment process and high pay all over the world. Though almost all of their work is related to finance and market, they’re doing a lot in Computer Science research also. Amazon founder Jeff Bezos was a D. E. Shaw employee before he left and founded Amazon.com. In India, the D. E. Shaw’s main office is in Hyderabad and its fully related to Software Development and hence called “D. E. Shaw India Software Limited” (DESIS).

Now I will not bore you much and start with the process.

D. E. Shaw generally prefers computer science branch students but they’re not as strict as Amazon or Google. My branch is ECE (Electronics and Communications) and I still got through. But its quite difficult for non-CS students to even qualify for the process, leave alone the question of getting recuited. The reason being they put their CGPA cutoff for them as 8.5 ! while for CS students it was only 7.0 . Luckily, my CGPA was above the cutoff and I was allowed to sit for the process.

The recruitment process consisted of an online/written round followed by interview round. In their presentation before the process, they’ll scare the hell out of you by talking about their requirements and minimum skills but don’t get disheartened. In my case, they said they want students with – “Computer science background, Excellent coding skills, Excellent communication and soft skills, and knowledge of Compilers theory, Operating Systems, Networking, Automata, DBMS, Web technology, and god knows what ..”. Being a non-CS student, I never had a formal course in any of those subjects, but somehow owing to my interest I knew OS, Networking and Web technology. Still I was pretty scared after seeing their long list of requirements.

Anyways, the first round began. Initially they took an online round but due to some network problem, they had to scrap it. Next morning, they came up with a paper based round. There were 2 sections. One was aptitude and one was coding, both being objective type. The aptitude section was as lengthy as difficult. No one could have solved all 30 questions in 30 minutes time. Infact, I was only able to attempt 10. Next 40 minutes or so was reserved for the coding test. The questions they asked covered almost all the topics they mentioned in their pre-placement presentation. But the maximum number of questions were related to getting output or finding errors in C, C++ and JAVA codes. The questions they asked from theoretical subjects were more or less the basics and easy. Some questions were also for testing your understanding of pre-written codes. In those questions (which were quite a few in number), you will be given a huge chunk of code with some part missing and you have to identify which snippet among the options best fits in there. Sometimes its given what the code is supposed to do, but in some questions it was also your task to find out. So I think the differentiating factor is how well your actual coding skills are. And you need to know these 3 languages atleast – C, C++ and JAVA. Again, similar to aptitude section the coding section was also very lengthy with some programs extending upto 1 or more pages. I’d recommend to skip those programs initially and jump to other easy problems first. Then if you have time, you can come back and attempt them.

In the end of the coding round, they had one special subjective test in which they asked you to write the full code in any language for the give problem statement. In my case, the problem was : “Given a tree, find the depth of the largest binary search tree it contains.” I know it sounds simple enough but only until you start coding it. And while writing codes of such problems, make sure to display your data-structures and algorithmic skills and not your knowledge of STL libraries. Even if you’re not able to solve the problem and you used some complicated data structures (by using, I mean you created them from scratch without any help from STL libraries) and some good algorithms, then they are likely to appreciate your coding skills if not your problem-solving skills. And just a hint although I think you already know this – BST are the favourites of all software companies :). Overall, I sat for 2 companies including Amazon and both of them had a coding problem related to BST only.

And finally when submitting your answers, they may ask you to submit your resume along with your photo. A good CGPA, academic club memberships and enough number of projects are likely to get more of their attention than if you top the aptitude test. I think a good resume is a very important factor for D. E. Shaw people.

Based on all these factors – your CGPA, resume, first round marks, your coding skills, they’ll shortlist a few people for the interview. In my case, they selected 12 including few post-graduates. In the interview I had 3 rounds. Very unusual but true, I had my HR round first ! I think its because technical people were occupied with others. By the way, I was also the last candidate to get interviewed. Its not that they took interviews serially one-by-one, infact there were many parallel panels, but all others had atleast 1 round when I had none. So don’t think if you’re the last candidate you have less chance or so. Although its a common phenonmenon with many recruiters but not with this one I believe. Getting back to HR round, it was more of a stress round. For the first 5 minutes, the interviewer didn’t ask me anything and kept gazing at me with his hands on his chin, like he was watching a boring show on TV. I didn’t know what was happening and I kept murmuring something trying to start a conversation but he won’t even respond. Finally, I took the courage and gave him my resume asking “Would you like to take a look on my resume?”. This time he responded and started asking me questions seeing my resume. Well, to my utter surprise, he asked me “Why I did a project in IISC ?”. I never expected such a question, I just said that I was free during vacation and I didn’t get project from anywhere else and I had some contacts there so I got one. Later, I realized that I gave a perfect answer. The reason any company would ask that question is because IISC being a research institution of the country, any student who might do a project there might also go for higher studies instead of doing a job after graduation. And take my word, if any company gets even the slightest smell of inclination towards higher studies after looking at your projects, you’re out no matter how good you are ! Due to my statement I was saved. But after that, I immediately removed my IISC project from my job resume. Same I’d advise to all of you, to remove all of your research-based projects from your resume when you’re sitting for a company. But in case all your projects are like that, then rephrase the project title and description in your resume so that it looks more like a coding project and not a research project. If you need help, you can leave a comment and I’ll try to reply.

Anyways, then there were usual HR questions like your hobbies, interests, family background, history of my town, etc. He did ask me some technical questions also like on seeing the word ‘Hacking’ in my resume, we started discussing upon hacking, its types and laws related to it. Totally random you’d think but hey my friends had worse. One of my recently placed friend Prasad Khare who got placed in Atmel, was discussing the movies Inception, Hurtlocker and US government policies during his HR !!

HR went for about half an hour and then came my first technical round. They started off with puzzles, which were quite easy and common ones. Then only after 2 puzzles they started asking me about my favourite subject and language. I told them OS, Networks and C++. But instead they asked me all about Java ! I kept telling them I hadn’t revised Java but that didn’t help. They’ll ask some question and I’ll write the code in C++ and they would ask me to convert it to Java. They’d also ask the equivalents of C++ OOP concepts in Java. Its not that I know nothing of Java, I have actually done a lot of coding in it, but that day and time, I was totally unprepared. So I kept guessing a lot based on my poor memory and later to my surprise, I found I got many of them right .

They also asked some design questions in which they asked me to write the class and related functions (just the prototypes) for implementing a parking lot management system. Then there were questions on hacking and security. They also asked about the network problem they faced the previous day when the online round was going on, due to which they had to scrap it. They asked what could be the reason behind it and what could be the solution. Overall, again the majority of the questions were coding type with C++ concepts like virtual functions, JAVA OOP, and design problems. This round went on for 15-20 minutes past 1 hour or so.

Finally, after few hours I was called for my last interview round. It was more like a casual round in which the D.E.Shaw associate director was taking my interview. The first thing he said was “I just wanted to meet you once myself” and he asked a few HR questions again. He asked me if I had any higher studies plan, my strengths and 2 weaknesses, why their company, etc. It was a cool round with the atmosphere also easy and it went on for just 20 minutes or so.

Finally they took some time and announced my name and the only one to get recruited from my college. ! Whats even more wonderful I got a windcheater and a cool laptop bag on the spot The offer letter reached me after 2 months and I have to join just few days after my college ends. I’ve heard the work is quite hectic there but you can’t get a 7-digit salary by doing nothing. That’s all my friends. Have any questions, feel free to leave a comment. Hope this helps.

When you’re creating PHP files, you’ll start with <?php tags as usual, but DON’T end the file with ?> tags if its not your main index.php file. Its optional and ignoring it is not just safe but recommended. So always leave the <?php tags unclosed in files which you are going to include in your main file. Do close it properly in your main index.php file though.

Don’t use functions in FOR loop condition if the function returns the same result always e.g.

for($i=0; $i&lt;length(arr); $i++)

IS VERY VERY SLOW than

for($i=0, $N=length($arr); $i&lt;$N; $i++)

That’s because since the condition is checked on every iteration. The function is called again and again to check the lenght of the same array every time. Instead since you know the array length is the same, why not save it in $N so that it won’t have to calculate it again and again. Though if your array $arr may change in length, you can use that.

Initialize all variables before using, just like C++. Although PHP allows uninitialized variables, DO NOT use them. Don’t forget, this is one of the most important optimizations.

There are global variables in PHP which you access via : global $var; . But if you’re operating on global variables more than twice in the same function, then its better to copy them into a local variable and then do it and then update it again on the global variable. Operating directly on the global variables is quite slow.

By the way, try to avoid using global variables altogether. Don’t declare your variables global unless you really don’t have any other option left.

If you’re using boolean expressions, then use “true” instead of “TRUE” and “false” instead of “FALSE” (quotes for clarity). Although both behaves the same, but small lettered ones are faster (yes, I know, but its true!)

Just an optional optimization : Static methods are faster than non-static. If you think your method can be made static, make them. Though no compulsion in this particular case.

Although PHP will automatically destroy variables when their scope ends, still if you’ve created some big variable with huge amount of data, use unset($var) to free memory as soon as you no longer need that variable. Don’t wait for the scope to destroy it. Again, this is also optional and apply it only if you feel your variable can be that huge.

If you’re using include and require, give full paths instead of relative paths to avoid PHP wasting time in resolving OS Path.

Try to avoid regular expressions matching, they’re very slow. If you want to use simple validation, check out the ctype API. It can be found under section “Function Reference” > “Variable and Type Related Extensions” > “Ctype” in the PHP Manual. I hope you’ve downloaded PHP Manual. There’s no best way to learn PHP than from the Manual. It has lots and lots of examples.

Don’t suppress errors (if you intend to) using ‘@’ in front of functions. They’re very slow.

MORE optimization can be done by avoiding $hello variable and directly putting that in the return statement like

return " Hi $name, How are you? "

Use ‘foreach’ loops instead of ‘for’ loops wherever possible

Use ‘while’ loops instead of ‘for’ loops wherever possible and if you can’t even use ‘foreach’ loops there

Instead of concatenating strings during echo, use the echo comma operator e.g.

echo $hello.$name." You last logged in on $time". $bye;

use

echo $hello,$name,"You last logged in on $time",$bye;

echo is quite slow. So don’t echo many times. Instead as I mentioned in my last point, get all the variables and then pass them in a single echo command using the comma operator.

There are some pretty cool PHP extensions available out there. One of them is Memcache that will cache your PHP generated HTML pages and if there’s a HIT in the cache on a page request, your PHP code will not have to be reinterpreted. Caching can improve your code performance by 200 – 300 % ! There are other caching softwares also like PEAR Cache, Cache Lite, etc. Check it out under “Appendices” > “Extension Categorization” > “External Extensions” > “Memcache” in the PHP Manual.

Output buffering is another way to optimize transportation of HTML output to the user. You can use the ob_start() function in the beginning of the code and all the echo functions after that will not actually send the output to the client, but will send it to the output buffer. Once you’re echoing part is done, use ob_flush() to send the data to the client in one go. You won’t need this though if you apply the comma-separated echo trick properly. You can learn more about it under section “Function Reference” > “Affecting PHP’s Behaviour” > “Output Control” in the PHP Manual.

Another way is to compress your HTML code before sending it to the client. A ob_start(“ob_gzhandler”); in the beginning of your code will do the trick and similar ob_flush() can be used to send the compressed output. But note that while this will save the network bandwidth, it will increase the computation load on your CPU for compression. So there’s a trade-off in this case.

Now something about SQL queries, DO NOT USE mysql_query() inside a loop ! Instead, first build the query using the loop and then use a single mysql_query() to execute it.

But actually, for security reasons, don’t use mysql_query() at all and use Prepared MySQL queries. This will not only relieve you from having to worry about SQL injection attacks, it will also does some query optimization at its end to server you better. PHP already comes with PDO support. Check it out under “Appendices” > “Extension Categorization” > “Bundled Extensions” > “PDO” in the PHP Manual

Enabling Apache’s mod_deflate and mod_gzip can also help.

Set “AllowOverride” to “None” in the Apache configuration if you actually don’t need it.

Always put static pages into a separate server than the one hosting your PHP codes. And use some fast filesystem server to access them like thttpd.

That’s all I could think of for now. More tweaks can be done from Apache’s side also to improve the performance.

]]>https://abhishekdelta.wordpress.com/2010/11/27/php-optimizations/feed/3jeremeWorld’s biggest conspiracy ! (Part 1)https://abhishekdelta.wordpress.com/2010/09/10/worlds-biggest-international-scam-part-1/
https://abhishekdelta.wordpress.com/2010/09/10/worlds-biggest-international-scam-part-1/#respondThu, 09 Sep 2010 22:10:29 +0000http://abhishekdelta.wordpress.com/?p=385Continue reading →]]>Recently I read an editorial titled “Uncle Sam’s Scam”. It refreshed the memories of a Zeitgeist movie I saw long ago. It was about how the United States has tricked the world to satisfy its avarice and accumulated so much wealth that not even in the next 50 years can any country dream of. Ironically, many of us are not even aware of the scandal going around us. When our police are busy capturing thieves who stole a few lakhs from the banks, the people who stole Trillions of Dollars are sitting in the White House ( or in the Treasury next to it )! The reason US is also the most technologically advanced nation also lies in this very fact because it’s obvious that money attracts talent and talent leads to innovation. Here’s a brief description of the truth (as I see it) :

Let us start with the World Bank’s list of Top 10 countries by its GDP ( Gross Domestic Product : its the combined sum of all the goods and services produced within the borders of the country. Basically, it is a measure of the economy of a country ) :

It is clearly evident that US figures in the TOP of the list with 14 Trillion $ economy. The closest is Eurozone or the “European Union”, which is actually a union of many European counties, so it cannot be considered as a “one entity” and has been excluded from the rankings. So, effectively, Japan is the 2nd country in the list with close to 5 Trillion $ economy. The difference, is 9 Trillion $.

About 200 years ago, India or rather the Indian-subcontinent had the largest economy in the World. Now it ranks 12th. So what did the US do to come to the Top of the list ? Looking into the annals of the period of its independence, we see its conditions were similar to what other countries suffered during independence. Nor there is any clarity in the argument that they’ve had adequate time to develop and grow given that they got independence in the 18th century, because that would contradict the fact that United Kingdom was never even captured for a millennium and around half of the world (including both India and US ) were under the U.K. territory at not-so-long-ago point in the history. So then what is the arcane recipe to affluence they’ve got ? The answer is, an amalgam of Debt as Money and the “Globalized” Dollar.

While it may seem blatant to us that the US is the richest country in the World, the truth is only partial. What completes the truth is the fact that US is also the most indebted country in the World. Every time the US economy or their budget rose, so did their National Debt. To understand the point I’m trying to make here, you should have some basic idea about the money system in a country. As of now, I assume you do have a bleak idea about the entities like “World Bank”, “Reserve Bank of India” or “US Treasury”. The important thing to note is that whenever the government needs to spend more money than it actually accrued from the tax revenues, it needs to borrow it from the Central Bank, which in case of India is the RBI and in case of US is the Treasury. The Central Bank allocates the government a loan amount, which the government prints in the form of the national currency (as “new” money) and spends it, while in return the government signs “bonds” which are nothing but an official agreement of “promise” signed by the government that it will pay back the amount it has borrowed along with the interest back to the Central Bank. Hence, new money is printed by the government only when the Central Bank approves the loan amount which is indirectly restricted by the amount of “Gold” the Central Bank has (i.e. there exists a limit up to which the Central Bank can grant loan to the Government and that limit depends on the quantity of gold ). To know the significance of Gold in the current economic structure, you’ll have to know about the evolution of money system, which is quite an article in itself. Perhaps I’ll skip that for now to maintain the focus in the current agenda. So, this is the way the creators of this antiquated money system expected it to work. However, years of adulteration by corrupt governments, economists and industrialists have begot a completely different money system that although seems more profitable in the short-run, can annihilate the world in the near future, if left unchecked.

In the current system, the creation of new money is virtually unrestricted unlike in old days when stringent conditions used to control the amount of new money fed into the money supply of a country. Now taking the US example as the case study, the US can literally print money at its will. Without ignoring the fact that being a capitalist economy US government’s major source of income is from its industrial sector, the US government can still borrow more money whenever they are in need.

In Layman’s terms, US simply creates the money every time it needs to spend.

This is the end of part 1. In the next part, I’ll discuss why this bizarre spending and borrowing by the US government doesn’t hurt its economy. Moreover, how this act of US government actually makes it more richer and sucks money out of the economy of developing countries including India. And finally, what is the role of global entities like World Bank and IMF in this act.

]]>https://abhishekdelta.wordpress.com/2010/09/10/worlds-biggest-international-scam-part-1/feed/0jeremeEuro symbol.svgQuickly configuring an LDAP + NFS client in Fedorahttps://abhishekdelta.wordpress.com/2010/08/15/quickly-configuring-an-ldap-nfs-client-in-fedora/
https://abhishekdelta.wordpress.com/2010/08/15/quickly-configuring-an-ldap-nfs-client-in-fedora/#commentsSun, 15 Aug 2010 18:08:20 +0000http://abhishekdelta.wordpress.com/?p=401Continue reading →]]>Recently I needed to configure 6 PCs for a central workplace. I needed central authentication as well as Network File System(NFS) on all those machines. All this was to facilitate the people of my technical club (the “Delta Force” Webteam) to use those machines for working on collaborative projects. The central authentication assured that I can easily manage user accounts from say, an LDAP server i.e. I can disable login of a user in a client machine or create a new user without having to touch the client machine at all. Similarly, NFS assured that no matter in which of those 6 machines the user logs in, he will always see the same files in his home directory and same configurations like his background-image, firefox addons, etc on that machine as if he always used the same computer for all his work. This eliminates the problem of people complaining that the machine in which their files resides are being used by someone else.

So my overall network configuration has the following prototype :

1) 6 client machines in which user will be able to login (Subnet of the machines : 10.1.39.0/24)
2) An LDAP server ( IP : 10.0.0.163 ) to take care of authentication when user logs into a client machine
3) The LDAP base DN which has the list of all users is ou=people,ou=delta,dc=ldap.delta.nitt,dc=edu
4) An NFS server ( IP : 10.0.0.126 ) which has the user home-directories of all users inside /webteam folder.Overall working : When a user (say “jereme”) logs into a client machine, his username and password are checked from the LDAP server at 10.0.0.163. If authentication is successful, he’s logged into the machine and his home directory is actually mounted from /webteam/jereme in the NFS server at 10.0.0.126.

I assume you already have the fully configured LDAP and NFS servers since this article is only about configuring the “clients”. So here we go. Pick any of your client machines and do the following :

First we will configure NFS client. For this purpose, we will use the autofs package.

Step 1 : Install nfs-utils and autofs

For Ubuntu :

sudo apt-get install nfs-utils autofs

For Fedora :

yum install nfs-utils autofs

Step 2 : Edit the file /etc/auto.master and it should contain the following lines :

/webteam /etc/auto.home
+auto.master

Step 3 : Edit /etc/auto.home and it should contain the following line :

-rw,nfs,soft,intr,nolock 10.0.0.126:/webteam/&

Step 4 : Edit /etc/fstab and append the following line :

10.0.0.126:/webteam /webteam nfs soft,rw 0 0

Step 5 : Edit /etc/sysconfig/autofs and it should have the following lines :

Step 3 : The above will open a graphical window in the terminal. The first page will ask for the login type. It will have 2 columns. In the first column, select “LDAP authentication” and in the second column, select “LDAP,MD5,Shadow and Local Authentication”. Then click on Next.

Step 4 : Enter the following details when asked for LDAP configurations :

Step 5 : Open /etc/openldap/ldap.conf and uncomment “SIZELIMIT, TIMELIMIT and DEREF” and change it to :

SIZELIMIT 0
TIMELIMIT 0
DEREF never

Step 6 : Open /etc/nsswitch.conf and modify :

passwd: files sss
shadow: files sss
group: files sss

to

passwd: files ldap sss
shadow: files ldap sss
group: files ldap sss

Step 7 : Now, run the following command :

nss_updatedb ldap

That’s it. You are done :). Now reboot.

Important Note : Some tools like “chkconfig” and “/etc/nsswitch.conf” configuration are Fedora-specific. Ubuntu has other alternatives. If you’re an Ubuntu user, the above configurations might not run for you. But its still worth a try. Good Luck!