How to enable hibernation on windows 7

Well I have been using Windows XP for a very long time now and I am quite happy with it. Even after when Vista was launched ,I kind of stuck with XP because I found Vista to be a real pain. Most of the things in Vista were quite complicated and for doing a very small thing we had to go through a lot of confirmations and pop-ups and screens which was quite annoying for a user sometimes.

Well then came windows 7 which I recently loaded onto my desktop just to try it out because I got good reviews from my friends and connections , I thought maybe I should give it a shot once . So after installing Windows 7 , I am quite satisfied with it till now . It works fine on my machine , it still has some complications for users like me who are very used to working on XP , but still a lot better than Vista by far .

Initially I found myself stuck with a small thing like changing the hibernate option settings on Windows 7 . I couldn’t find the way to enable the hibernate option as I easily did on XP  but after going through few options and settings I finally found the way  ,so just thought that I would put it up over the internet.

Steps to enable the hibernate option on Windows 7 :

1)

personalize

personalize

first just right click on the desktop and then click personalize in the menu list

2)

screensaver

screensaver

then click on the screen saver icon on the right-bottom corner of the window

3)

power option

power option

a window will open after you click on screen saver and on that there will be a text written as ” change power settings ” , click on it which will open another window

4)

select power plan

select power plan

now when you see a window like above , find the link given as ” change plan settings ” on the right side of the window , corresponding to the power plan currently being used for the computer (indicated on the left-middle side of the window with a highlighted radio-button)

5)

edit plan settings

edit plan settings

after that you will again see another window having a link given as ” change advanced power settings ” , click on that to manage the advanced power settings

6)

change advanced power settings

change advanced power settings

a small window will open with several options displayed as a list , from that list look for an option called ” sleep “, click on that option to expand it further for listing more options

7)

sleep

sleep

now you will see another extended option called “ allow hybrid sleep ” , click on it to display the options in it which will show setting as ” ON ” (default value) , now you just have to change it to ” OFF ” in the drop down box to enable the Hibernate option for your Windows.

8 )

hibernate after

hibernate after

now there are several other power options which can be changed , like for example there is an option called ” Hibernate After ” which is used to set the time duration after which the computer will go into hibernation automatically if no user is using the machine or no work is being done by the operating system (in this case Window 7)

You can set it in form of minutes like 60 mins or 120 mins or even 111 mins to be precise or you can disable automatic hibernation by choosing 0 (zero).

9)  When you are done with your settings , just click on the ” Apply ” button of the window to save your settings and then click Ok to confirm  - Or -   you can directly click on ” Ok ” button to save and confirm at the same time .

10)

hibernate enable

hibernate enable

now after changing the settings , when you go to the start menu , you will get see another option called hibernate in the shutdown button .

Well i started of from right clicking on the desktop and then navigated to the power options , to reach the power options window there is a another way to go through the control panel in the start menu .

control panel

control panel

here you will get to see a lot more options for you windows which are very useful , but right now we are going to look at the part of windows hibernation settings , so there is an option called “ Hardware and Sound “, click on it to go to the next window .

hardware and sound

hardware and sound

now on this window you will see the link ” Power Options “, clicking on which will go to the window which you see in the above stated step number (4) .

Well after that, all the steps from step (5) are the same .

18

02 2010

Installing PHP 5 on FreeBSD

A tutorial on installing PHP from the FreeBSD ports for Apache and MySQL.

What you need to add to the httpd.conf file and which of the PHP5 ports to choose.

Choosing which port to use
In the past there were several ports for PHP such as /www/mod-php5, /lang/php5-cli, and /lang/php5. Since the release of PHP 5.1.14 there is now only /lang/php5 This port now allows you to choose if you want to install the CLI, CGI, and Apache module.
CLI stands for command line interpreter. It is used for running PHP scripts from the command line and makes creating shell scripts very simple if you already know PHP. The Apache PHP Module is disabled by default, so make SURE that if you plan to use this for web work that you enable it.
Installing the port
Since all PHP ports are now combined you will need to configure it to be sure the parts you need are built.
# cd /usr/ports/lang/php5
# make config
# make install
When you run make config you will be shown a list of options. To use PHP with Apache make sure the Apache Module box is selected.
Once php has installed you will need to install the extra modules for things such as MySQL. These modules are all located in the ports. Some of the most common modules are
/usr/ports/databases/php5-mysql - MySQL Database
/usr/ports/www/php5-session    - Sessions
/usr/ports/graphics/php5-gd - Graphics Library
Adding the PHP 5 module to Apache
Apache needs the following lines in the httpd.conf file to use php. These lines should already be added by the port but if you have problems you should double check your httpd.conf file. Note that Apache 2.x does not need the AddModule line.
# Apache 1.3.x
LoadModule php5_module        libexec/apache/libphp5.so
AddModule mod_php5.c
# Apache 2.x
LoadModule php5_module        libexec/apache/libphp5.so
If you installed using the port and had apache installed already it should do this automatically for you.
Next find your DirectoryIndex section in your httpd.conf file. Apache is set up for PHP 4, but not PHP 5 currently so you will need to modify it and change the 4s to 5s like this.
<IfModule mod_dir.c>
<IfModule mod_php3.c>
<IfModule mod_php5.c>
DirectoryIndex index.php index.php3 index.html
</IfModule>
<IfModule !mod_php4.c>
DirectoryIndex index.php3 index.html
</IfModule>
</IfModule>
<IfModule !mod_php3.c>
<IfModule mod_php5.c>
DirectoryIndex index.php index.html index.htm
</IfModule>
<IfModule !mod_php4.c>
DirectoryIndex index.html
</IfModule>
</IfModule>
</IfModule>
This code is telling Apache to open index.php first you have the PHP 5 module loaded. You can change the order as you wish. Or if you just wanted to skip it you could simply add the following line to the httpd.conf file since you know you are going to have php 5.
DirectoryIndex index.php index.html index.htm
Now apache just needs to know what it should parse the PHP files with. These two lines should be added to the httpd.conf file, and can be put at the bottom if needed.
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
If want to use PHP code inside of .htm files you can just add on those extensions.
AddType application/x-httpd-php .php .htm .html
Configuring PHP
Settings for PHP are stored in /usr/local/etc/php.ini You will need to create this file by copying it from /usr/local/etc/php.ini-dist
# cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini
In this file you can set the memory limit for programs. Turn on global variables if you must, set the max file upload size, and everything else you need.
Testing PHP
Once you have restarted Apache so the changes take effect you are ready to test it. To test it run the following command to create a php file that you can attempt to run
# echo “<? phpinfo(); ?>” >> /usr/local/www/data/test.php
Then point your web browser to http://yourdomain.com/test.php and if it works you will see several pages of information on your PHP settings. If it did not work you will see only the text you typed in.

23

12 2009

Getting Apache installed

Installing Apache2.2

Make sure you update ports and then run the following commands:

# cd /usr/ports/www/apache22
# make install clean
That will install apache2.2
Configuring apache2
Lets edit the httpd.conf file:

# vi /usr/local/etc/apache22/httpd.conf
Scroll down and change the following settings. The optional settings I will put OPTIONAL before the setting:

OPTIONAL: Listen 80 - You can change this default option if you have more than one apache server running on your network

User www - Changes what user apache runs as

Group www - Changes what group apache runs as

ServerAdmin you@example.com- change you@example.comto your email address.

DocumentRoot “/usr/local/www/apache22/data” - I don’t usually use the default path. I put my www documents on a seperate drive.

Directory “/usr/local/www/apache22/data” - Change this to the same path as DocumentRoot (See above)

<Directory /usr/local/www/apache22/> Change this to the root of your vhosts folder

DirectoryIndex index.html index.html.var - add any pages you would use. For instance, add index.php if you use php pages

OPTIONAL: #CustomLog /var/log/httpd-access.log combined - I usually leave this commented unless you want to use this to track users looking at your site

ScriptAlias /cgi-bin/ “/usr/local/www/cgi-bin/” - change this to your cgi-bin path

Directory “/usr/local/www/cgi-bin”> - change this to the same path as ScriptAlias /cgi-bin above

Now lets tell apache to start:

# apachectl start
and hit Enter on your keyboard
We now need to tell Apache to run on startup. Please run the following command:

# echo ‘apache22_enable=”YES”‘ >> /etc/rc.conf
If you get no errors, apache should be running. Look at the page by opening a browser to http://localhost or replace localhost with the IP or the actual hostname of the box. If you went with the DocumentRoot defaults, You will see an apache test page until you get your site up and going. If you are behind a router or firewall, make sure you forward the apache port (Port 80) to the FreeBSD box otherwise you won’t be able to get there from here. :-)

Configuring SSL

Let’s get SSL Configured and Installed:

(FROM http://www.bsdguides.org/guides/freebsd/webserver/apache_ssl_php_mysql.php)

# mkdir /usr/local/etc/apache22/ssl.key
# mkdir /usr/local/etc/apache22/ssl.crt
# chmod 0700 /usr/local/etc/apache22/ssl.key
# chmod 0700 /usr/local/etc/apache22/ssl.crt
Create Certificate
Now, you need to understand that one server can hold multiple certificates, but only one per listening IP address. So, if your server is listening on one IP address, you can only have one certificate for the server. Follow me so far? All of your virtual domains can share the same certificate, but clients will get warning prompts when they connect to a secure site where the certificate does not match the domain name. If your server is listening on multiple IP addresses, your virtual hosts have to be IP-based — not name-based. This is something to consider when creating your certificate. :-)

Change to your root dir by typing in the following command. We want to save this configuration there as a backup.

# cd /root
# openssl genrsa -des3 -out server.key 1024
You will now be prompted to enter in a password. Write this down as you will need it later. We need to make a Certificate Signing Request (CSR):

# openssl req -new -key server.key -out server.csr
Enter your password when it asks for it. Make sure you enter your FQDN for the “Common Name” portion.
Self-signing your Certificate
You could always pay money to Verisign or Thawte for this but it costs $$$. Here is the way to do it:

# openssl x509 -req -days 365 -in /root/server.csr -signkey /root/server.key -out /root/server.crt
Now your cert is good for 365 days. If you want to make it longer, go right ahead and do so :-)
If you would like more information about SSL Certs, go to http://httpd.apache.org/docs-2.0/ssl/ssl_faq.html#aboutcerts

Now we need to copy the certs to the right place:

# cp /root/server.key /usr/local/etc/apache22/ssl.key/
# cp /root/server.crt /usr/local/etc/apache22/ssl.crt/
Now to give them the right permissions as well:

# chmod 0400 /usr/local/etc/apache22/ssl.key/server.key
# chmod 0400 /usr/local/etc/apache22/ssl.crt/server.crt
We will now want to copy the default httpd-ssl.conf from the extras folder to the Includes folder:

# cd /usr/local/etc/apache22/extra
# vi httpd-ssl.conf
Now modify the following:

DocumentRoot “/usr/local/www/data” - Change the path to your httpd.conf document root.

ServerName www.example.com:443 - Change www.example.com to your domain name.

ServerAdmin you@example.com  Change this to your email address

ErrorLog /var/log/httpd-error.log - You can leave this or comment it out.

TransferLog /var/log/httpd-access.log - You can leave this or comment it out.

SSLCertificateFile “/usr/local/etc/apache22/ssl.crt/server.crt”

SSLCertificateKeyFile “/usr/local/etc/apache22/ssl.key/server.key”

One additional thing you will need to do is open up  /usr/local/etc/apache22/httpd.conf and comment out the following line:
Include etc/apache22/extra/httpd-ssl.conf
Now run the following:

# apachectl stop
# apachectl start
The start means it will start in ssl mode to serve both http:// and https:// addresses. This used to be apachectl sslstart but that command has been depreciated.
The URL below includes instructions on how to remove the pass phrase prompt when apache starts
http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html#removepassphrase

23

12 2009

Linked List class in Javascript

This  is an exercise in using the object oriented concepts in Javascript to implement a doubly linked list.

There is a class called Node which encapsulates the actual node in the list. The linked list is implemented as a global object with class variables and methods to:

  • Add a node
  • Remove a node
  • Search for a node
  • Sort the list in ascending order
  • Display the entire list

The Node object simply stores a string. There is scope for further improvement, as always. The source is easily available by viewing the page source. Any comments and recommendations for changes or improvements are welcome.

You can see the implementation here

18

03 2009

Cannot view hidden files in Windows Explorer

The Problem

When you view files and folders using Windows Explorer, you are unable to see hidden files. Experienced users will go to the Tools->Folder Options menu and change the setting as shown below:

Folder Options window

Folder Options window

If you are able to see hidden files after this, then you dont need to read this article further. However, if you still are not able to see hidden files and you come back to the Folder Options window and find that the ‘Show hidden files and folders’ has reverted back to its unchecked state, then read further.

First Reaction

The most logical thing in such a case would be to check for viruses, trojans, spyware and malware. Use well-known free or paid virus scanners and anti-spyware tools. Hopefully, after cleaning, if you come back to the Folder Options window and check ‘Show hidden files…’, it should work.

Aarrgh! What the heck!

‘Show hidden files and folders’ has reverted back to its unchecked state? Again? To fix this, and assuming your system is not infected, you need to change two registry keys. To do this you need to have administrator rights.

Please note , this article assumes you are confortable with using the Registry Editor. Making a mistake while editing could send your Windows into disaster zone.

1.Go to the command prompt and load regedit.exe.

2.First go to the key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\

Folder\Hidden\SHOWALL

3.In the right pane, the current value of CheckedValue would most likely be set to 2. Edit and make it 1.

HKLM key

HKLM key

4.Next go to the key:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced

5.In the right pane, the value of Hidden will be set to 2. Edit it to make it 1.

HKEY CURRENT USER

HKEY CURRENT USER

6.Close the registry editor and refresh Windows Explorer now. You should be able to see the hidden files and folders.

11

03 2009

A perfectly normalized database is a timebomb waiting to explode..

BOOM!

BOOM!

Once upon a time, God came down on earth in the form of E.F.Codd and gave us the Holy Tenets of Database Design.

EF Codd

EF Codd

Among the most important thing that every database designer or application developer had to learn was

“Thou shalt design your database so that it at least fulfills the conditions of 3NF (3rd normal form)”

Since then thousands of people have used that adage as the basis of good database design (myself included). And , it works, you know! Without following those basic principles of good database design, it just would not be possible to build databased applications in any sane manner.

So, what exactly is the problem then? The problem becomes apparent to anyone who ends up with a at least few thousand rows of data in multiple tables.

The more optimized a database is, the more effort and time it takes to retrieve data.

You see, database normalization is aimed at storing data in the most optimal manner - preserving referential integrity, and removing data redundancy, and making inserts, updates and deletes as painless as possible. But this is just looking at one part of the picture.

Due to the conceptual idea of a database being what it is, optimizing it for storage automatically makes it unoptimized for retrieval.

So lets say you have stored all the relevant details of Employees across 4 tables:

  • Employee master
  • Committees part of
  • Salary Transactions
  • Projects Handled

So , its all neatly stored in 4 tables with all the tables linked by primary and foreign keys and indexed and retrofitted with the relevant triggers. So now , what do we do when we want to see an employee’s details in one page. We form 4 JOIN operations and then retrieve the data. This is of course, assuming that the other fields in the tables themselves do not require accessing still more tables.

This above scenario is not so much of a performance issue, with a table of 40 employees records. But when you have 150,000 employee records then things start to crash. Imagine doing those join operations across 4 tables with that kind of data. No amount of indexing is going to save you from the massive load the database server will go through. Lets take this scenario a little further… Imagine 40 people trying to see the details of 40 different employees at the same time, when the database has over 500,000 records in each table.

Magic Lamp

Magic Lamp

Wouldn’t it have been ideal if , we could just get all the employee data in a single table for retrieval, but yet keep them normalized for storage?

There was a time when I didn’t even give a second thought to normalization. Like everyone else, I took it for granted that once normalized, I dont need to really worry about database design for the rest of the project.

I was forced to reconsider that assumption, when I was developing a web application for a major newspaper a few years back. The job was to put everything they had for the last 10 years into databases and provide a web application for users to see old issues and search and retrieve articles etc.

Very early into the project, we realized that even with just 10,000 articles in the database, all normalized, to search using keywords was taking far too long. It was just not working out.

To cut a long story short, we ended up having two databases - one for storage which was to get all the data into the database and the second for retrieval which was used by the website to simply retrieve data. I wrote some offline code in Java to process and migrate the data from the storage db to the retrieval db. This approach was possible because updates were done only once at the end of the day when the newspaper was ready to go for print.

Due to this approach, (and a couple of other innovations which are not really relevant to this article), the search database worked very fast for retrievals - we got a almost a 100-fold increase in performance. We had simply denormalized the articles retrieval database enough so that it would take no more than 2 tables to retrieve the main article data.

I personally feel, that the optimal solution, is to keep a different database for storage and another one for retrieval, but I also know how impractical it would be to do so, given our current approach to creating databased applications. Unless someone comes up another radical approach to storing data, or maybe some new magic middeware which automatically takes care of separating and optimizing storage and retrieval, we will still be following the normalization process for quite some to come.

Oh and by the way I still cant think of designing a database without normalization :) . Its just too much trouble.

06

03 2009

How not to name a boolean variable

Out of personal experience and reading other people’s code,  I have come to realize a small but very tricky issue about how NOT to name boolean variables or any kind of variable where the code to evaluate is usually in the form of a boolean expression.

The pitfall to avoid is :

Do not use a name with a negative meaning or connotation

Instead of naming it notpassed call it failed . Instead of calling it no_data_present call it data_absent

The reason is simple. While reading the code, a negative sounding boolean variable causes more confusion than required.

Example:

bool not_done = false;

Various ways of checking it :

if (not_done) { }

if {!not_done) {}

if (not not_done) then //VB style

while (not_done  == false)

Try reading the above lines to yourself and you will see sometimes it gets confusing to actually understand what the condition is checking for really.

By common programming convention when we use a conditional operator , we are generally trying to see something positive has happened, so if the variable itself sounds like it stands for something positive it makes for easier understanding of the code.

Lets try the above example with a positive sounding variable:

bool done = false;

Various ways of checking it :

if (done) { }

if {!done) {}

if (not done) then //VB style

while (done  == false)

I think the above statements are easier to understand now.

27

02 2009

Finally upgraded to latest WP version

Been a couple of years since I installed WP blog on my site. That was version 2.0.x . After much dilly-dallying decided to upgrade to the latest version 2.7.1 , then plugged in a new Theme and now the blog looks cool.

26

02 2009

Moving from Mantis to Flyspray for issue tracking

i have recently shifted from Mantis to Flyspray for issue tracking.
I have been using Mantis for over a year now and its a very comprehensive bug tracker with a lot of features. The UI is a little dated though. One of my main problems was that the UI became a little slow in loading once the number of bugs reached around a 100. I suspect the database retrieval code was taking too long to fetch data so the page would load halfway and then wait for a couple of seconds before it completed the page load. Perhaps it would run better on a dedicated server. For the above reason, I was looking around for a more leaner and meaner software. The little drawbacks notwithstanding, Mantis remains a very good choice for large teams with multiple projects.

Flyspray has a very fast and clean interface. It’s screens do not have too much of data and the look is slick. I find it more easier to use than Mantis mainly because it requires less data than Mantis. Flyspray does not allow for too much elaboration of bugs, but it does deliver the goods for a basic bug tracker. It’s setup screens are one of the most user-friendly I have seen for any web application. Strongly recommended for small to medium sized projects.

03

12 2008

How to prevent CDialog closing on pressing Escape key

MFC CDialog classes have a default behaviour of closing if the user presses Esc key anytime while the dialog has focus. To overcome this behaviour, the Esc key has to be trapped and disabled in the PreTranslateMessage event handler:


BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// disable closing by escape key
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)
return TRUE;
return CDialog::PreTranslateMessage(pMsg);
}

19

11 2008