Thursday, July 25, 2019

Bit field Sample C Code

/*Space optimized Structure representation of date */
#include <stdio.h>
struct date
{
         /* d has value between 1 and 31, so 5 bits are sufficient */
          unsigned int d: 5;
         /* m has value between 1 and 12, so 4 bits are sufficient */
         unsigned int m: 4;
         unsigned int y;
};
 
int main()
{
         printf("Size of date is %d bytes\n", sizeof(struct date));
         struct date dt = {31, 12, 2014};
         printf("Date is %d/%d/%d", dt.d, dt.m, dt.y);
         return 0;
}

Creation of Structure Pointer variable

#include<stdio.h>
#include<stdlib.h> /* For malloc() and free()*/
#include<string.h> /* For strcpy() */

struct test{
char name[10];
unsigned int rollno;
unsigned int marks;
};
int main()
{
struct test *ptr;
ptr = (struct test *)malloc(1*sizeof(struct test));
/* ptr->name = "Sreekanth"; Not allowed */
strcpy(ptr->name, "Sreekanth"); /* We should copy char by char or use strcpy() */
/* printf("Enter the name:"); scanf("%s",ptr->name); */
/* printf("Enter the Roll no:"); scanf("%d",&ptr->rollno);*/
ptr->rollno = 101;
ptr->marks = 555;
printf("Name: %s\n Roll no: %d\n Marks: %d\n",ptr->name, ptr->rollno, ptr->marks);
free(ptr);
return 0;
}

Tabata workout

Attended a session in KBR park on 09 May 2015.
Cross fit - High intensity workout with 10 Sec breaks.

1) Warm up:
 - Stretch your hands to backwards and keep it for  10 Sec
 - Rotate hands both forward and backward
 - Bend backwards and wait
 - Bend front and wait for 10 Sec

(1)
(2) Skipping
(3) Jogging
(4) Boxing



Bench push ups - Push up and wait for 5 Sec, 10
Mountain climb - 30
Sleep back and stretch forward (for abs)  - 10
Push ups by moving right and left sides (move both legs and hands)

The above whole cycle for 4/8 times.

Sunday, July 13, 2014

Uncompressing files in linux

gzip Compressed files: 
.gz
.tar.gz
.tgz

To uncompress these files
$ gunzip file.gz
$ tar -zxvf file.tar.gz
$ tar -zxvf file.tgz

bzip Compressed files:
.bz2
.tar.bz2

To uncompress these files
$bunzip2 file.bz2
$tar -xvfj file.tar.bz2

xz Compressed files:
.xz
.tar.xz
To uncompress these files
$xz --decompress file.xz
$tar -xfvJ file.tar.xz

Uncompressing zip files
$unzip file.zip

Tuesday, January 28, 2014

grep command in Linux

grep (Options) "Search String” path/folder
Options:
-i Case insensitive search
-r Recursively search the sub directories
-n Prints the line number

Also we can use:
find . |xargs grep -rn "search string" *

Friday, October 4, 2013

Executing a set of commands using while on Linux command prompt

To execute set of commands on command prompt use below command:

root@user-desktop:/home/user# while [ 1 ]; do ls -ltr; ls; done

This will run until we terminate (Using Ctrl+c/Ctrl+z)

Wednesday, July 31, 2013

Using "wget" command for transferring files in Linux machines

Enable the http server in a Linux machine

Go to, vim /etc/httpd/conf/httpd.conf (In Redhat)

Look for "Listen X.X.X.X:80", remove the # mark before it and change it to "0.0.0.0:80"

Now restart the service using the command:

service httpd restart

Not go to some Client machine, which is directly reachable from the Server. And you can get files from  the server using the command:

If you want to get a file "sample.txt" from "/var/www/html" folder, use the following command:

wget ftp://USER:PASSWORD@192.168.10.11://file.txt

1) Provided the Server is reachable with IP 192.168.10.11 and user credentials as "USER", password as "PASSWORD".
2) "/var/www/html" is the default location where the files are stored.
To change this location, go to file "/etc/httpd/conf/httpd.conf" and look for "DocumentRoot" and change this "/var/www/html" to "/home/user/" and then restart the httpd service, now you can download files from "/home/user"
e.g. To download a file with name "sample.tgz", use

wget ftp://user:user123@192.168.10.11://home/user/sample.txt