Sunday, January 13, 2013
Root HTC Wildfire S
Wasted a day of my life trying out links that never worked.
This link was a life saver
http://forum.xda-developers.com/showthread.php?t=1702542
Saturday, January 12, 2013
Missing power option in Ubuntu 12.04
There is a feature/bug in Ubuntu 12.04 that does not let you choose actions on critical battery. I finally found a solution to the problem
As it turns out the option can be set if you use the non-GUI method. For those who wish that the laptop suspends instead of hibernate (defult action). You should use
NOTE: sudo is not required
gsettings set org.gnome.settings-daemon.plugins.power critical-battery-action 'nothing'
gsettings set org.gnome.settings-daemon.plugins.power critical-battery-action 'suspend'
Labels:
Bugs,
hibernate,
power options,
suspend,
terminal,
ubuntu 12.04
Saturday, December 15, 2012
How to make a bootable Windows USB under any LINUX version
There are a lots of softwares available for making bootable and live USB's but they all fail at one distro or another.
So here is a magic bullet that fits all.
All you need is a bootable OR live distro's iso image file. If you have a live distro you'd get a live USB, if you only have bootable iso image you would get a bootable USB only.
First locate your USB
Then run this, replace path-to-iso with the path to where the iso file is on your disk and the ? with drive letter for your USB
Dont forget the sync command at the end to flush the usb-cache. Example
Note: Do not include the numeric number e.g. its /dev/sdc and NOT /dev/sdc1!
sudo fdisk -l
Then run this, replace path-to-iso with the path to where the iso file is on your disk and the ? with drive letter for your USB
dd if=/path-to-iso of=/dev/sd? sync
Dont forget the sync command at the end to flush the usb-cache. Example
dd if=/home/me/ubu.iso of=/dev/sdc sync
Sunday, October 7, 2012
Generating random numbers in c++
#include "stdafx.h"
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
int c;
srand(time(NULL));
while(1)
{
cout<<rand();
}
return 0;
}
Lets have an in depth look at the code. The actual random numbers are generated by the rand() function. The numbers that it generates are not random but are pseudorandom i.e. they appear to be random but are not. In actual the rand() function generates a predictable series of numbers. The series however can be initialized with a seed value which in the above code is being done using the srand() function. The srand() needs only be called once during a typical program. However given a same seed value the program will generate the same random numbers every time the program is run. In order to avoid this repetition across program executions. We have passed the time(NULL) as an argument to the srand() function. Which will initialize the srand with a new value every time the function is called, hence now the numbers generated by rand() would appear to be random.
Saturday, October 6, 2012
Using the arrow keys in c++ using scan codes
As a programmer you may have been tempted to use the arrow keys to take input from the user, did you get frustrated and gave up because it was not as trivial as it should be?
Well it is a piece of cake but to eat it you have to earn it.
Wait no further....
For those in a hurry here is the code
Lets examine the code step by step. Before diving into details lets have a look at the background. Any key pressed from the key board generates a unique code (think of it as a number stored as a HEX value), this code is known as Scancode Generally each code is one byte in size but some keys (keys with special functions) generate two or more bytes and this code is referred to as extended Scancodes
The following keys fall under the extended category
If an arrow key is pressed it generates two bytes, one the code for the key pressed prefixed with an 0xE0 or decimal 224 (scan code for left shift release) on most systems. The corresponding scan codes for the keys are
Well it is a piece of cake but to eat it you have to earn it.
Wait no further....
For those in a hurry here is the code
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int c;
while (1)
{
c = getch(); // first call gets the 0xE0 byte or decimal 224
switch(c) // lets just waste the value
{
case 0:
case 224:
switch (getch()) //Here the actual code for the key is got
{
case 72: cout << "up arrow\n"; break;
case 75: cout << "left arrow\n"; break;
case 77: cout << "right arrow\n"; break;
case 80: cout << "down arrow\n"; break;
default: cout << "extended key " << c << "\n";
}
}
}
return 0;
}
Lets De-magicify
And here is the treat for the geeks.Lets examine the code step by step. Before diving into details lets have a look at the background. Any key pressed from the key board generates a unique code (think of it as a number stored as a HEX value), this code is known as Scancode Generally each code is one byte in size but some keys (keys with special functions) generate two or more bytes and this code is referred to as extended Scancodes
The following keys fall under the extended category
- Arrow keypad
- Home keypad
- Right Alt
- Right Ctrl
- keyboards with the arrow pad, home pad and number pad
If an arrow key is pressed it generates two bytes, one the code for the key pressed prefixed with an 0xE0 or decimal 224 (scan code for left shift release) on most systems. The corresponding scan codes for the keys are
- Up 72
- Down 80
- Left 75
- Right 77
Scancodes c++ and the getch function
The getch function gets a single character from the console, since extended scan codes, especially the arrow keys generate two bytes, you can already judge why we'd need two calls to getch(), the first call gets the code 224 and the next one gets the actual code for the key pressed. The rest is plain c++ switch statements. Enjoy your programming :)Thursday, July 5, 2012
How to configure a LAMP server on Ubuntu 10.04
A LAMP server refers to Linux, Apache, MySQL, PHP or Python.
Assuming you have already got a Ubuntu 10.04 (LINUX) machine up and running lets first install an Apache server.
Before we proceed with setting up apache lets set up the hosts file, this file holds ip mappings to machine names.
You will see something like this
Add the line 127.0.0.1 test-site-name.local to make it look something like this, i have used the name "ccl" in this example
Now when you are done setting up the hosts file, we'll now configure virtual hosting so that we can host multiple domains (or subdomains) with the server.
Once in the directory lets make setup our virtual host, for this we'll use the template provided by apache. This file is named default. Create a copy of the file first.
Now open the file you just created (by copying) for editing
This should open something similar to this
Edit path on line 9 and set it to /path-to-the-test-site-WITH-trailing-slash/. It should look something like this
Please Note: Be careful regarding where there is a trailing slash where there is none. Also change
to
for the first two directory nodes (the / one and the one with the path to your site). That will allow all the .htaccess files to work properly and allow redirection.
Now we are almost done, we just need to enable the site
In the next step lets configure and install MySQL
when prompted for a password choose one and save it for future reference Note the configuration file for MySQL is located at /etc/mysql/my.cnf we will not be modifying it but you should know it for future reference. Running the next command is recommended for securing your server, especially if it is a production server. When you will run the command you will be prompted for many things answering them with a yes is recommended.
Next lets create a database and grant control to a user
Note: The semicolons are important and identify end of MySQL commands. In the above case a database with the name of test-db has been created and the user zed has been granted full control over it. The password for the user is password. You can keep any password that you like. With Apache and MySQL installed we are now ready to move on to installing PHP. Install php
If you are not experienced with PHP the following configurations are useful for more detailed logging and better performance
Change the fields as shown below
Now restart Apache
if you need MySQL support in PHP then install the following package
The second package is a recommended package for security, it provided additionally security for PHP Restart Apache to make sure everything is correct
Wola! Your lamp server is now configured and good to go! :)
sudo apt-get install apache2
Before we proceed with setting up apache lets set up the hosts file, this file holds ip mappings to machine names.
sudo gedit /etc/hosts
You will see something like this
127.0.0.1 localhost.localdomain localhost # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
Add the line 127.0.0.1 test-site-name.local to make it look something like this, i have used the name "ccl" in this example
127.0.0.1 localhost.localdomain localhost 127.0.0.1 ccl.local z3d-laptop # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
Now when you are done setting up the hosts file, we'll now configure virtual hosting so that we can host multiple domains (or subdomains) with the server.
cd /etc/apache2/sites-available
Once in the directory lets make setup our virtual host, for this we'll use the template provided by apache. This file is named default. Create a copy of the file first.
sudo cp default your-site-name
Now open the file you just created (by copying) for editing
sudo gedit your-site-name
This should open something similar to this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> |
In this file add the line ServerName test-site-name.local just above the DocumentRoot directive (in front of line 4). Edit DocumentRoot /var/www path on line 4 and set it to /path-to-the-test-site-WITHOUT-trailing-slash. It should look something like this
DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash
Edit path on line 9 and set it to /path-to-the-test-site-WITH-trailing-slash/. It should look something like this
Directory /path-to-the-test-site-WITH-trailing-slash/
Please Note: Be careful regarding where there is a trailing slash where there is none. Also change
AllowOverride None
to
AllowOverride All
for the first two directory nodes (the / one and the one with the path to your site). That will allow all the .htaccess files to work properly and allow redirection.
Now we are almost done, we just need to enable the site
sudo a2ensite test-site-name
sudo /etc/init.d/apache2 restart
In the next step lets configure and install MySQL
apt-get install mysql-server
when prompted for a password choose one and save it for future reference Note the configuration file for MySQL is located at /etc/mysql/my.cnf we will not be modifying it but you should know it for future reference. Running the next command is recommended for securing your server, especially if it is a production server. When you will run the command you will be prompted for many things answering them with a yes is recommended.
mysql_secure_installation
Next lets create a database and grant control to a user
mysql -u root -p create database test-db; grant all on test-db.* to 'zed' identified by 'password'; flush privileges; quit
Note: The semicolons are important and identify end of MySQL commands. In the above case a database with the name of test-db has been created and the user zed has been granted full control over it. The password for the user is password. You can keep any password that you like. With Apache and MySQL installed we are now ready to move on to installing PHP. Install php
apt-get install php5 php-pear
If you are not experienced with PHP the following configurations are useful for more detailed logging and better performance
sudo gedit /etc/php5/apache2/php.ini
Change the fields as shown below
max_execution_time = 30 memory_limit = 64M error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR display_errors = Off log_errors = On error_log = /var/log/php.log register_globals = Off
Now restart Apache
sudo /etc/init.d/apache2 restart
if you need MySQL support in PHP then install the following package
apt-get install php5-mysql apt-get install php5-suhosin
The second package is a recommended package for security, it provided additionally security for PHP Restart Apache to make sure everything is correct
sudo /etc/init.d/apache2 restart
Wola! Your lamp server is now configured and good to go! :)
Thursday, May 24, 2012
Creating a Bootable USB the hassle free way
There are a lots of softwares available for making bootable and live USB's but they all fail at one distro or another.
So here is a magic bullet that fits all.
All you need is a bootable OR live distro's iso image file. If you have a live distro you'd get a live USB, if you only have bootable iso image you would get a bootable USB only.
First locate your USB
Then run this, replace path-to-iso with the path to where the iso file is on your disk and the ? with drive letter for your USB
Example
Note: Do not include the numeric number e.g. its /dev/sdc and NOT /dev/sdc1!
sudo fdisk -l
Then run this, replace path-to-iso with the path to where the iso file is on your disk and the ? with drive letter for your USB
dd if=/path-to-iso of=/dev/sd?
Example
dd if=/home/me/ubu.iso of=/dev/sdc
Subscribe to:
Posts (Atom)