Wednesday, 24 April 2013

PHP script downloading instead of executing in browser

To run a PHP script in Ubuntu or likewise other Linux-based distributions, your file should be located in the /var/www/ folder. To run the script in the terminal, you can type php filename.php when in /var/www folder. To run the script in browser, type the url as localhost/filename.php.

If opening the file in the browser, downloads the file, instead of executing it, you need to install some packages. To do this, type the following in a terminal:

sudo apt-get install apache-mod2-php5

Now open the file again in the browser by using the url shown above, and your script should be up and running.

Sunday, 21 April 2013

Trouble installing Adobe Flash Player on Firefox in Windows

Installing or updating Adobe Flash Player using the links redirecting it to its official online page almost never works for me. Be it network connection or some other problem, it is very difficult to get this working. What I usually get is this or some other kind of error:


The error I usually get when installing the online version
If you are one of me, don't worry, there is a solution to this; download the full offline installer!

To get the offline installer, download the offline version by clicking on the button below and follow the normal Next-Next-Finish method on Windows applications and you have the latest version of Adobe Flash Player.


Saturday, 23 March 2013

Trivial Lex program to tokenize a C program


/*
* Copyright (c) 2012-13 Jobin Raju George <jobin.rv@gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* A copy of the GNU General Public License is available at
* <http://www.gnu.org/licenses/>.
*/
%{
#include <stdio.h>
%}

DIGIT [0-9]
NUMBER {DIGIT}+
REAL {DIGIT}*"."{DIGIT}+
TEXT [a-zA-Z ]+
TEXT_NUMBERS [a-zA-Z0-9]
CONDITIONALS "if"|"else"|"else if"|"switch"|"case"
KEYWORD "break"|"continue"|"goto"|"printf"|"scanf"|"sprintf"|"sscanf"|"fopen"|"fwrite"|"fread"|"fclose"|"write"|"read"|"open"|"close"|"return"|"int"|"float"|"char"|"unsigned"|"signed"|"short"|"long"|"double"
ITERATORS "for"|"while"|"do"
PREPROCESSOR "#"|"#line"|"#undef"|"#error"|"#elif"|"#else"|"#endif"|"#if"|"#define"|"#include"|"#pragma"|"#ifndef"|"#ifdef"
DELIMITER [; :\t\n()"]
IDENTIFIER [a-zA-Z]{TEXT_NUMBERS}*|[a-zA-Z]{TEXT_NUMBERS}*[[{NUMBER}+]]
NON_IDENTIFIER {NUMBER}+[A-Za-z]+
FORMAT_SPECIFIER "%"{TEXT_NUMBERS}+
FILE "<"{IDENTIFIER}.h">"
COMMENT "/*"[a-zA-Z0-9 \t\n;.~!@#$%^&*()_+=<>?:"{}]*"*/"
AOPERATOR "+"|"-"|"*"|"/"|"="
BLOCK_BEGINS "{"
BLOCK_ENDS "}"
UNARY "++"|"--"
LOPERATOR "&"|"|"|"&&"|"~"|"||"|">"|"<"|">="|"<="|"=="
FUNCTION {IDENTIFIER}+"("{DELIMITER}*{TEXT}{TEXT_NUMBERS}*{DELIMITER}*")"
%%

{CONDITIONALS} { printf("%s is a conditional\n", yytext); }
{ITERATORS} { printf("%s is an iterator\n", yytext); }
{DIGIT} { printf("%s is a digit\n", yytext); }
{NUMBER} { printf("%s is a number\n", yytext); }
{REAL} { printf("%s is a real number\n", yytext); }
{PREPROCESSOR} { printf("%s is a preprocessor directive\n", yytext); }
{DELIMITER} { printf("%s is a delimiter\n", yytext); }
{KEYWORD} { printf("%s is a keyword\n", yytext); }
{NON_IDENTIFIER} {printf("Could not process %s", yytext); }
{IDENTIFIER} { printf("%s is an identifier\n", yytext); }
{COMMENT} { printf("%s is a comment\n", yytext); }
{AOPERATOR} { printf("%s is a mathematical operator\n", yytext); }
{LOPERATOR} { printf("%s is a logical operator\n", yytext); }
{BLOCK_BEGINS} { printf("Block begins\n", yytext); }
{BLOCK_ENDS} { printf("Block ends\n", yytext); }
{FILE} { printf("%s is a file\n", yytext); }
{UNARY} { printf("%s is a unary operator\n", yytext); }
{FUNCTION} { printf("%s is a function\n", yytext); }
{FORMAT_SPECIFIER} {printf("%s is a format specifier\n", yytext); }
%%

int main(int argc, char *argv[]) {
yylex();
return 0;
}

To compile this program, type the following commands:
lex filename.l
cc lex.yy.c -ll
./a.out

Saturday, 9 February 2013

How to read files in Linux-based partitions from Windows?

A PC with Windows and Ubuntu lets you choose the best of both Operating Systems. While I use Windows usually for gaming, Ubuntu is all for work, and need to store data in both of them.

As you all are aware, Ubuntu can read NTFS, the file system that Windows uses, so can read and also store data into Windows' drives. But unfortunately, Windows is "blind" to ext partitions, i.e, Windows does not read data in ext partitions, the ones used by Ubuntu. So, while on Windows, I was unable to read files stored in my Ubuntu operating system. It was only when I came to know about Linux Reader, that I stopped rebooting my Windows to fetch files from Ubuntu.

Linux Reader is an application that lets you read Linux-based Operating System files from Windows.



Getting started:

To read files, first download this application and install using the usual Next-Next-Finish installation method of Windows and then open Linux Reader and choose the partition from which you want to read files from.

The first screen that you see when you open "Linux Reader"

This way, please:

I want to copy my Pictures folder from my /home partition. So I go to /home and then choose Pictures and then Save to save the folder to any location that you want in Windows.

The folder I want to save is located in /home. The screen shot shows "Pictures" folder is selected.


This will copy the files from your Linux partition to the folder you desire.

Select the location where you want to save the folder.


I have tested this application to work for Debian and Ubuntu, though it should work on all Linux-based operating systems.

Drawbacks:

  1. The worst thing about this application is you can't edit files unless you save them to Windows.

  2. The second drawback is a less serious one, but is relevant to some: Though this application is free of cost, its not open source, so you won't get to see the source code.

P.S.:There may be many other softwares better than these, offering more and better functionalities. Please let me know if you know of any. I liked Linux Reader, that's why I personally recommend this software.

Saturday, 26 January 2013

How to use conky to configure my Ubuntu's desktop?

Ubuntu is a very powerful Operating System which offers immense control and options to its users so that they can customize it to their own needs. One of these options is customizing the desktop using various tools and softwares.

One of the most popular tools to customize the desktop is conky. From the manual page of Conky:

"A system monitor for X originally based on the torsmo code, but more kickass. It just keeps on given'er. Yeah."


Though this does not provide sufficient information about conky, it does reveal a lot about its developers. Yeah!

In order to customize your desktop using conky, you need to configure the conkyrc file located in the .conky folder of your home folder. Don't worry, if you could not locate such a folder, since it has to be created when you first configure this file.

So, lets begin customizing our desktop.

First, install conky by typing the following command on your terminal:

sudo apt-get install conky-all

Next, we need to configure the /home/$USER/.conky/conkrc file. I was too lazy to do this myself and looked out for a good Samaritan who could provide me with a fully configured file. I found this website while going through my Google+ posts when I saw Carlo Coppa's post, and the wallpaper from here, which appeased me and I quickly pilfered it! This page is in Italian, so I thought I could just translate it for you, in my words, using what you have already guessed!

Next, click here, and press "Save". The file will be saved in a location depending upon the configuration of your browser. Its probably in your "Downloads" folder. Extract it by right-clicking on it and clicking on "Extract here". Open the newly created folder, named "Conky-lua", and again extract the contents of "Conky ubuntu-lua.tar.gz".

Now, copy all the files of this folder, "Conky ubuntu-lua" and create a folder .conky in your home folder and paste all the files you just copied to .conky .

Next, open a terminal and type the following:

mkdir -p ~/.lua/scripts/
cp ~/.conky/clock_rings.lua ~/.lua/scripts/



Don't worry about the -p option to mkdir, it resolves errors if parent directories are not found, by creating them.

Now, we are almost set to watch the show, type the following to run conky:

conky -c ~/.conky/conkyrc



This is how my desktop looks after this configuration. I'm lovin it!

The script to get this!

You can click on "Download the script", which will help you to configure your desktop exactly as shown.



Click "Save" after you click on the link and to run this, open a terminal and go to the path where you have downloaded this script and type:

bash get_this.sh



This will only run conky this time. The next time you login, the script will have to be run again using the command

conky -c ~/.conky/conkyrc

I am sorry for this trouble, but I am working to add it to "Start-up Applications" and will soon add this, till then, Enjoy!

Feel free to question me regarding these configurations or if you have any problems before, during or after running this script, I'll be very happy to solve them for you, if I am able to!

Friday, 25 January 2013

How to annotate PDF's in Ubuntu?

According to me, there is no particular application in Ubuntu that annotates PDF's well, or at least, as well as Nitro PDF reader or Adobe Reader's Professional version. Because of this reason, I had to keep switching to Windows whenever I wanted to read and annotate PDF's, which is the common source of learning material in college. Annotations formed a very important part of reading as marking the important lines for further reading were essential, which would otherwise lead me to constant searching of certain important points.

However, recently, courtesy a good read, I found a very useful tool in evince, the default PDF reader in Ubuntu, which could annotate PDF's albeit involving some laborious tasks.

There is a little drop-down menu "Thumbnails" at the top-left corner of evince, when you open a PDF in it. Click on the arrow besides it. You should see the "Annotations" option that appears in the list just appeared.



Next, click on "Add" that has appeared now, which may give you a small icon with a "pencil" image over it. Click on the "pencil", and move the cursor over the reading region, which would change the pointer to a "cross-signed" cursor. Now click where you want to add a note. A yellow-colored mark-up should appear accompanied by a note that can be edited below it. You may not be able to type on it, unless you try to resize it by clicking on its lower corners and resize it to a different size.




Unfortunately, even after this arduous and tedious toil, you may only be able to type in lemon yellow colored font, which for-the-moment seems to be immutable.



I'll surely try to find a better alternative to this, before that, lets hope the evince authors write a better "annotator".

P.S.: There are some other PDF readers which you may want to try out:
1) Okular: a light-weight PDF reader. This is a very compact reader, about 1.5 MB in size,(Adobe reader is more than 40 MB!, just for comparison) and allows simple configuration like full-screen reading, colour inversion, etc.

2) Xournal: Another light-weight application, specially designed for taking down hand-written notes but also allows PDF's to be read and annotated. Though not very useful for annotation, highlighting and mark-up tools are available, worth giving a try.

How to measure the temperature of your processor?


If you have experienced that your laptop or desktop heats up a lot due to some strange reasons like may be having a dedicated graphics card and have wanted to check out some options to solve this, jupiter is one of the tools for you. This software was hinted to me by one of my good friends, +Pratik Nadagouda, thanks Nada!

jupiter is a tool that measures temperature and provides certain measures to reduce it like closing unwanted applications that are using up the processor and other resources.

To install jupiter, open "Software center" and go to "Edit" in the menu bar at the top. Select "Software Sources..." from the drop-down menu.

In the second tab, "Other softwares", click on "Add" button, and add the following line:
ppa:webupd8team/jupiter and click on "Add Source".


Then open a terminal and type:
sudo apt-get update and then
sudo apt-get install jupiter

After jupiter is installed, a thunder-like icon appears at the top menu bar. Click on the icon to see the temperature of your processor.
"jupiter" tunes the kernel and processor for AC or battery and subsequently increases battery-life.
If you can compromise on a little performance, then jupiter offers a mode called "Power Saving"(in the performance option when you click on the thunder-like icon of jupiter). This helps to cool down the processor a bit, albeit with a trade-off with performance.

Tuesday, 8 January 2013

How to open C drive when Windows is hibernated?

Windows saves the information needed to wake up from hibernation usually in the "C" drive, in a file named hiberfil.sys. Its size is approximately the size of your RAM and is stored on the hard disk when the computer is asked to hibernate.

Because the system is hibernated and needs to be in the same state when revived, the partition is made read-only and should not be changed from another operating system, if it is a multi-boot system. So, when you open your Windows drive from a Linux-based operating system, such as Ubuntu, you may get an error message such as this:
The error message obtained when the hibernated Windows partition is asked to mount.
You can retrieve your data from this drive, without having to open Windows in steps:
1) Open a command-prompt, such as your gnome-terminal.
2) Type

sudo mount -r /dev/sda2 /media/your_username


In place of sda2, type the name of the device where your Windows is installed, like sda1 or sdb1 or something like that. To see which device on your Windows is installed on, type

sudo fdisk -l

and try to recognise the Windows partition by looking at the "blocks" column which shows the size of the Windows partition. And in place of your_username, type your user-name or type /media/ and press tab to see a list of options or the correct option itself! The "C drive" is now mounted and you can see your data!


Caution: Do not try to modify any thing in the Windows drive, even if it may seem to be abnormal as this may cause your data to be lost which may not have been saved while hibernating.

Friday, 4 January 2013

How to set proxy authentication for applications in Ubuntu



Applications in Ubuntu can be configured to use your proxy authentication settings by configuring it in gsettings / dconf.


From the official GNOME site: dconf is a low-level configuration system. Its main purpose is to provide a backend to GSettings on platforms that don't already have configuration storage systems.


In order to set and authenticate proxy, type dconf-editor at the terminal. If it asks you to install dconf-tools, then type

sudo apt-get install dconf-tools

and enter your password and then, after installation, type

dconf-editor

.
A window, as shown below, shall open.




On your left hand side panel, click on the arrow besides "system", then on the arrow besides "proxy".





Check whether the mode is "manual".


Now, click on http and set your password and user-name by clicking on "Value" field in "authentication-password" and "authentication-user" respectively. Let the "enabled" and "use-authentication" fields have a tick on them.



Next, click on ftp, https and socks and type your host and port-number. Unfortunately, these cannot be assigned authentication parameters for reasons I am not aware of.

You can also download this script, which I prepared to configure your proxy settings.



How to use this script: 

1) Clicking on the link will lead you to a Google document, click on "Download" and then on "Save".

2) It will get saved to the path either given by you or most probably to your "Downloads" directory.

3) Open your terminal and go to location where the file is saved. Suppose the file is saved on the "Desktop". Type

cd Desktop


4) Type

sudo bash proth.

This will ask for your password, after entering your password, it will ask you for the host, port no, user-name and password for authentication. Give the appropriate details and you are done!


To watch a video of how to use this script, click the link below:

Tuesday, 18 December 2012

How to run an application from any path in Windows Command prompt

The problem:

If you need to open an application or software such as Microsoft Notepad, you need to go to the path where the application is installed, usually the default location is

C:\Windows\system32\

and then type

notepad

to open a new Notepad window. To search for the path where the application is installed, type the following on the prompt:

C:\>for %i in (notepad.exe) do @echo: %~$PATH:i
C:\WINDOWS\system32\notepad


Note the blank spaces, you need to specify it properly to work.

Replace

notepad

by the application name you want to search for.
This can be very irritating if you need to open an application often through the prompt and have to go to the path every time where the program is installed. If you try to type the name of the application anywhere other than the path where the application is installed, you will get an error which looks like this:





The solution:



To reduce this effort, you can specify Windows to search for the term you type in the prompt in certain fixed locations, called as class paths. You can specify the path to search as follows:

Start -> Settings -> Control Panel



Double-click on System, open "Advanced" tab, click on the "Environment Variables" button below. In the "System variables" frame below, scroll if there are many variables and click on "Path", click "Edit" to add or delete a new path. You can enter the path where your desired application is stored. If there are multiple paths, separate them by semi-colons(;).

For example, if you need to specify the class path for notepad++, installed at  

C:\Program files\Notepad++\


Click on "Path", then "Edit" button, if there already is a path specified, add a semi-colon after that, and type

C:\Program files\Notepad++\


after the already present path.

Now, you can type notepad++ at any path at the command prompt and a new "Notepad++" window will be opened.

Even more shorter:

In order to shorter the command notepad++, you can rename the file at the installed path to, say, np, and then type np at the prompt.
Caution: Renaming the executable file may cause the files linked to it, like a shortcut file on the Desktop, to stop working, so you will have to change the filename at respective locations too. However, this is one of the easiest methods to shorten the command. Please share if you find better methods to do so.