[SOLVED] ‘Unknown’ filesystem in gparted

I had a primary NTFS partition with windows 7 installed on it. Somehow, its bootloader went corrupt so I used install-mbr in ubuntu to fix that but it only made the problem worse. Now my system didn’t recognise the partition as NTFS partition and I couldn’t access the partition.

I modified the partition ID using fdisk but that didn’t work. Fdisk recognised it as NTFS but gparted didn’t, nor did Ubuntu. To fix it, I followed the following steps:

 

      • Download

    testdisk

      •  and extract the files to a folder. The files are compiled executable files so there is no need for any installation. I extracted it in a folder named testdisk on my home directory. Ubuntu users can install it using

    sudo apt-get install testdisk

    cd ~/testdisk/linux
      • Execute the testdisk:
    sudo ./testdisk_static
      Select [Create] and press enter. On the resulting screen, select your harddrive using cursor keys and press enter. On the next screen select the partition table type. It’d generally be Intel if you are using a PC and Mac if you are on Mac. Select the correct one and press enter.
      Now you’ll be presented with lots of options. Use cursor keys to select Advanced and press enter. Select the partition which shows unknown type. Use left and right arrow keys to select [Type] and press enter. You’ll see the list of partition types. In the list the HPFS/NTFS has partition id 07. Press enter, type 7 for NTFS or another partition ID corresponding to your partition type. Press enter.
      Now use the right arrow key to select the [Boot] and press enter. Use right arrow key to select [Rebuild BS] and press enter. Select [Write] and press enter. Now type y. The partition should be fixed by now. You can now quit the testdisk
      • Refresh partition list
    sudo partprobe

 

The disk should be accessible again now

Cheers!

[SOLVED] “Ignoring file ‘.distUpgrade’ / ‘.save’ in directory ‘/etc/apt/sources.list.d/’ as it has an invalid filename extension” on Ubuntu 10.10

Recently apt-get update started throwing notices which read:

Ignoring file 'opera.list.distUpgrade' in directory '/etc/apt/sources.list.d/' as it has an invalid filename extension
Ignoring file 'opera.list.save' in directory '/etc/apt/sources.list.d/' as it has an invalid filename extension

It occured because sources.list.d directory isn’t supposed to contain files with .distupgrade and .save extensions, but since I upgraded my distribution from 10.04, backup copies of the source files were made with .distUpgrade appended to them. Similarly .save files were not supposed to be in the directory which made it throw this error. Fortunately you can suppress this error by executing the following command:

sudo sh -c "echo 'Dir::Ignore-Files-Silently:: \"(.save|.distupgrade)$\";' > /etc/apt/apt.conf.d/99ignoresave"

This will suppress the error. Next time you run sudo apt-get update you wouldn’t see those errors.

UPDATE: Apt 0.8.8 seems to have fixed the issue as mentionedby _khAttAm_ in comments. You can install it from Unstable repositories.

Cheers!

[HowTo] Add expires headers to cache static files using htaccess

Caching is one of the most important things to keep in mind when you are developing a website which is expected to get large amount of visitors. Most web developers neglect caching, some even don’t know correct ways to implement it.

In this tutorial, I’ll show you how to enable browser cache of static files simply using htaccess file. Basically server adds the Expires header to file-type you specify. Expires header will make sure the browser stores the file locally and use the same file until the time mentioned in expires header has passed.

Before we move ahead, please make sure apache’s mod_expires is loaded. You can check it using phpinfo() under ‘Loaded Modules’ section. If you don’t find it there, you can see this tutorial to enable mod_expires.

Copy the following code and paste it into .htaccess file in your website’s root directory.

# Turn on the Expires engine
ExpiresActive On
 
# Expires after a month client accesses the file
ExpiresByType image/jpeg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/plain A2592000
 
# Good for one week
ExpiresByType application/x-javascript M604800
ExpiresByType text/css M604800
ExpiresByType text/html M604800

Explanation:

ExpiresActive On turns on the expires engine. ExpiresByType image/jpeg tells server to check if MIME-type of file is image/jpeg. If yes, set the expires header.

‘A’ in A2592000 stands for ‘Access’ and it means set the expires header for 2592000 seconds (1 month) after the user has accessed the file. ‘M’ stands for ‘Modified’. M2592000 would mean ‘set expire date to one month after the file has been modified’.

Images are not likely to change even in years. Hence, you can set several months of expiry time in that. Whereas, css and javascript are likely to be modified. Therefore, we put a week’s expire header in css, javascript and html files.

Check out the official documentation to read more about the mod_expires module.

Some people would argue that explicitly setting ‘expires’ header is not a good idea as it would override the default caching mechanism of the browser. But the fact is that browsers use ‘ETag’ header to cache the data. They would still request the server to see if the content has changed by matching the ETag of the local cached copy of the data and server’s copy. If the Etags are different, it would know the data has been changed and would download the new data. But this mechanism still requires the browser to send request for each object to check if a newer one is available adding fractions of second of lag for each request. Server has to still serve the response. This makes this method comparitively inefficient.

On the other hand, explicitly setting expire would make the browser not to send request until expire date has passed which means very few requests are made. Hence, very fast page loading.

Thus, using this file is advisable as it would make your website load faster on the viewers computer and would ease the burden on your server too.

Comments and suggestions are more than welcome.

Cheers!

[SOLVED] Error ‘dpkg: error processing (–unpack) trying to overwrite…

Recently I got this error after installing VLC on Ubuntu 10.10 Maverick Meerkat. Not really remembering what caused the error to be triggered in the first place, it became very difficult to find a solution for it.
When I executed sudo apt-get upgrade to upgrade my packages, it told me there was some issues and I needed to execute sudo apt-get -f install to fix them. I did as advised but it produced the following error:

Reading package lists… Done
Building dependency tree
Reading state information… Done
Correcting dependencies… Done
The following extra packages will be installed:
vlc vlc-nox
Suggested packages:
mozilla-plugin-vlc videolan-doc
The following packages will be upgraded:
vlc vlc-nox
2 upgraded, 0 newly installed, 0 to remove and 198 not upgraded.
66 not fully installed or removed.
Need to get 0B/5,258kB of archives.
After this operation, 229kB of additional disk space will be used.
Do you want to continue [Y/n]? y
WARNING: The following packages cannot be authenticated!
vlc vlc-nox
Install these packages without verification [y/N]? y
(Reading database … 206759 files and directories currently installed.)
Preparing to replace vlc 1.1.0-1~ppa1~maverick (using …/vlc_1.1.0-1ubuntu1_i386.deb) …
Unpacking replacement vlc …
dpkg: error processing /var/cache/apt/archives/vlc_1.1.0-1ubuntu1_i386.deb (–unpack):
trying to overwrite ‘/usr/lib/vlc/plugins/access/libxcb_screen_plugin.so’, which is also in package vlc-nox 1.1.0-1~ppa1~maverick
dpkg-deb: subprocess paste killed by signal (Broken pipe)
Preparing to replace vlc-nox 1.1.0-1~ppa1~maverick (using …/vlc-nox_1.1.0-1ubuntu1_i386.deb) …
Unpacking replacement vlc-nox …
dpkg: error processing /var/cache/apt/archives/vlc-nox_1.1.0-1ubuntu1_i386.deb (–unpack):
trying to overwrite ‘/usr/lib/vlc/lua/playlist/anevia_streams.luac’, which is also in package vlc 1.1.0-1~ppa1~maverick
dpkg-deb: subprocess paste killed by signal (Broken pipe)
Errors were encountered while processing:
/var/cache/apt/archives/vlc_1.1.0-1ubuntu1_i386.deb
/var/cache/apt/archives/vlc-nox_1.1.0-1ubuntu1_i386.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

After some time of googling and head-scratching, I finally found a solution and it wasn’t that difficult either.
To fix it just note down the path of files which are causing the trouble. From the above mentioned error, we can clearly see that there are these two files causing the error:

/var/cache/apt/archives/vlc_1.1.0-1ubuntu1_i386.deb
and
/var/cache/apt/archives/vlc-nox_1.1.0-1ubuntu1_i386.deb

You just forcefully overwrite them using the following command:

sudo dpkg -i –force-overwrite <filename>
sudo apt-get -f install

For the above two files you’d execute:

sudo dpkg -i –force-overwrite /var/cache/apt/archives/vlc_1.1.0-1ubuntu1_i386.deb
sudo dpkg -i –force-overwrite /var/cache/apt/archives/vlc-nox_1.1.0-1ubuntu1_i386.deb
sudo apt-get -f install

This fixed the error for me and I hope this fixes it for you too.

Cheers!

[HOWTO] Download youtube video from command-line

Linux is awesome and so is the terminal. Things become a lot more easy if you can just type in few commands and get your work done. Downloading youtube video has always been messy with GUI downloaders, browser extensions and web services which claim to give you the download link to that video. Now, you can download it from the terminal using youtube-dl in ubuntu. You can also download and install it in other flavors of linux. The script is written in python.

Install youtube-dl from the official repository in Ubuntu:

sudo apt-get install youtube-dl

To download a video execute the following:

youtube-dl <url>

Example screenshot:


More options and switches:

-b            Best quality
-m            Mobile version
-d            High Definition
-g            Don’t download, just show the url
-c            Resume download of a video which was interrupted before
-w            Don’t overwrite existing file

For complete list of switches execute man youtube-dl in terminal.

Cheers!

Passing variable number of arguments to a function in PHP

We all know about functions and how we can pass arguments to it. But did you know that we can pass variable number of arguments in a function?

Consider a function sum() which adds numbers passed into its arguments. Now we want it to add all the numbers passed onto the arguments. Eg; if we call sum (21, 45) or sum (45, 23, 78, 56, 90) it should add all of them. Even if we pass a 100 arguments, it should execute successfully.

Below is the code for making the function sum() :

function sum() {
	$count = func_num_args();
	 $sum = 0;
	 for($i=0; $i<$count; $i++) {
		 $num = func_get_arg($i);
		 $sum += $num;
	 }
	 return $sum;
}

In above function func_num_args() give the total number of arguments that have been passed and func_get_arg() takes argument number as argument and returns the argument value.
We also have another function – func_get_args() which returns all the arguments passed to the function as an array.

For more information and examples on these functions:

func_num_args()
func_get_arg()
func_get_args()

Cheers!

[Solved] ‘Public key is not available’ error on apt-get update in Ubuntu

I came across this error while doing sudo apt-get update

W: GPG error: http://ppa.launchpad.net karmic Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 5A9BF3BB4E5E19B8
W: GPG error: http://ppa.launchpad.net karmic Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 9ABD05E22847688C


This made me do some hunting on the web. I tried quite a few solutions out of which the following worked.

Run the following command in terminal:

gpg –keyserver subkeys.pgp.net –recv 5A9BF3BB4E5E19B8
gpg –export –armor 5A9BF3BB4E5E19B8 | sudo apt-key add –

Replace 5A9BF3BB4E5E19B8 with your own key. This solved the error. I repeated the procedure for second key and I stopped getting error messages.

On the first command, sometimes the server maybe down. In that case you can try the following servers.

hkp://subkeys.pgp.net
hkp://pgp.mit.edu
hkp://pool.sks-keyservers.net
hkp://keys.nayr.net
http://keys.gnupg.net

To use these servers just replace subkeys.pgp.net with any of the server above. For eg;

gpg –keyserver http://keys.gnupg.net –recv 5A9BF3BB4E5E19B8

Source:
http://gentoo-blog.de/ubuntu/ubuntu-gpg-error-httpppalaunchpadnet-intrepid-release/

Cheers!

[HOW-TO] Converting case in MySQL

I had been wondering this for few days. I wanted a solution which could comvert first letter of text in some fields to uppercase and the rest to lower. I got time today and experimented a bit and found a very simple solution.

CREATE TABLE  `temp_users` (
`fname` VARCHAR( 50 ) NOT NULL
`email` VARCHAR( 250 ) NOT NULL
) ENGINE = MYISAM ;

Query above makes a temporary table ‘temp_users’ to store the updated data.

INSERT INTO `temp_users`
SELECT CONCAT( UPPER( SUBSTRING( fname, 1, 1 ) ) , LOWER( SUBSTRING( fname, 2 ) ) ) , email
FROM `users`

This query selects the data from the current table, converts the case and inserts into our temporary table ‘temp_users’.

The converted data has now been been stored into a temporary table. Now you can drop the table ‘users’ and rename ‘temp_users’ to ‘users’.

DROP TABLE `users`;
RENAME TABLE `temp_users` TO `users` ;

And that is all.

Cheers!