Friday, 23 June 2017

Hello World program without using any semi colon in C

Question: Write the hello world program . . . Without using any semi-colon's ";" ?

#include <stdio.h>

void main()
if(printf("Hello World")) { }

Monday, 1 May 2017

Reduce image size

Sometimes, you need to fill an application form, but the size of your image is
too large, as per the mentioned size on the application. So, you can use imagemagick
utility of ubuntu, and get the desired size for your image.

To reduce the image size, you can run either of the below command.

$ convert  -resize 50% source.png dest.jpg and 

$ convert  -resize 1024X768  source.png dest.jpg

Saturday, 15 April 2017

Easter Egg: How to activate YouTube dark theme mode

After coming back home from office, we prefer to watch some videos on YouTube to get relax. But the white theme of YouTube is straining your eyes. So, YouTube introduced the dark theme for us. Now, enjoy your videos in dark room with dark mode. :)

This is found by reddit user.

Steps to activate dark mode:

1. Update your chrome browser to the latest one.
2. Open

Before dark theme:

3. Right click on anywhere on the screen, and choose inspect element. Or you can open the developer console using the key combination of Ctrl+Shift+I or CMD+Shift+I

4. Once it is opened, select the console tab in your developer console. and enter the below string.


5. Once entered, you will get below response.

6. Next step, is to reload your page, and the option to select "Dark mode" will become visible on your youtube account. when you click on gear icon(settings), on right top of your page.

7. Toggle it on, by selecting it. Once the dark mode is ON, then YouTube is available in dark mode and look like this:

Hope you enjoy this dark mode. Now, we dont need lights off add on anymore for YouTube. If you are facing any trouble in enabling it, feel free to comment or write to me.

Happy Easter.!!!

Monday, 20 March 2017

How to write in bold using ncurses in C

To use ncurses in your program, you first need to install ncurses. Once installed, write the below code:

#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  int ch;
  keypad(stdscr, TRUE);
  printw("Type any character to see it in bold\n");
  ch = getch();
  if (ch == KEY_F(1))
    printw("F1 Key pressed");
  else {
    printw("The pressed key is ");
    printw("%c", ch);
  return EXIT_SUCCESS;

To compile it, use the ncurses library using
$ gcc file.c -lncurses

Once compiled, it will generate a executable named a.out

Type any character to see it in bold
The pressed key is A

If you need any help installing ncurses, write in comment section.

Thursday, 16 March 2017

Generating password using openssl for your unix accounts

There is a need when you need to create an account using password hash, follow below steps to simply create password hash.

$ openssl passwd -1
Password: <your pass>
Verifying - Password: <your pass>
Hash will appear here as an output

openssl is the command to generate password
passwd is an argument and -1 represents here that we want unix kind of hash from passwords as an output. There are other options too, like md5, crypt.

For example, you can use:

$ openssl passwd -crypt
$ openssl passwd -md5

You can also provide the salt, to enhance the security

$ openssl passwd -crypt -salt (yourSalt)

This salt is required to decrypt the password.

You can also use python crypt function to create encrypted hashes:

# PASS="strongpass" python -c "import crypt; import os; print crypt.crypt(os.environ['PASS'], 'salt')"&
# ps fauxwww | grep 'python -c'

In this manner, the password will not appear in ps output.

To hide from history, you can disable and enable the history using following option
set +o history
# PASS="strongpass" python -c "import crypt; import os; print crypt.crypt(os.environ['PASS'], 'salt')"&
set -o history

So, go ahead and generate your hashes.

RAINBOW ROSE in shell script

To gift your friend, you can send him/her a rainbow rose by using below shell script


printf "${RED}    .--.---.\n"
sleep 1;
printf "   ( ${CYAN}\'--'/${RED} )\n"
sleep 1;
printf "  ( ${CYAN}'..-...'${RED} )\n"
sleep 1;
printf "   '.${CYAN}'-._.'${RED}.'\n"
sleep 1;
printf "    <'${CYAN}-.,.${RED}->\n"
sleep 1;
printf "${GREEN}       \`\\(  ${YELLOW}  _\n"
sleep 1;
printf "${GREEN}        < \ ${YELLOW} / \ \n"
sleep 1;
printf "       ${YELLOW}__${GREEN} \\\\\\ $YELLOW|_/\n"
sleep 1;
printf "      /  \ ${GREEN}\\\\\\ \n"
sleep 1;
printf "      ${YELLOW}'--'.${GREEN}\\\\\\ ${YELLOW}>\n"
sleep 1;
printf "${GREEN}            \\\\\\   \n"
printf "\n"

And it will look like this:

Sunday, 23 October 2016

Understanding Exec

At times, you have noticed that there is a usage of exec in shell scripts. What it actually does, and where to use it exactly?

The command works on the theory of, is "never coming back"

exec command is shell builtin, and other members of the commands are execve, execvp, execv.

1. exec command starts the new process, without forking, so once it starts the new process, the old process get finished.

Case 1:
bash:~$ ps -ef | grep -i bash
csblog  13062 12371  1 15:19 pts/5    00:00:00 bash
ksh$ ksh
ksh$ ps -ef | grep -i ksh
csblog  13093 13062  0 15:19 pts/5    00:00:00 ksh
ksh$ ps -ef | grep -i bash
csblog  13062 12371  0 15:19 pts/5    00:00:00 bash

Case 2:
bash:~$ exec ksh
ksh$ ps -ef | grep -i bash
ksh$ ps -ef | grep -i ksh
csblog  13062 12371  0 15:19 pts/5    00:00:00 ksh

You can see, in case 1, i have started the process, without using exec, so the new shell, is subshell for the old one. But in case of case2, a totally new process is started. In this manner, your resources are saved.

2. Sometimes, you don't need user to access the shell, you can directly change in /etc/passwd, but you need to load the environment, so you can add the exec command, at the end of .profile.
3. exec, also used with file descriptor. To open, close, read and write.

exec 3< thisfile          # open "thisfile" for reading on file descriptor 3
exec 4> thatfile          # open "thatfile" for writing on file descriptor 4
exec 8<> tother           # open "tother" for reading and writing on fd 8
exec 6>> other            # open "other" for appending on file descriptor 6
exec 5<&0                 # copy read file descriptor 0 onto file descriptor 5
exec 7>&4                 # copy write file descriptor 4 onto 7
exec 3<&-                 # close the read file descriptor 3
exec 6>&-                 # close the write file descriptor 6

read <&3
echo stuff >&4