Skip to main content


Showing posts from October, 2014

PyTorch Code for Simple Neural Networks for MNIST Dataset

youtube-dl (Command Based Youtube Downloader)

Downloading videos to local machine is always a challenge as the streaming sites keep on updating their policies in blocking the videos. But there is a tool that is available in the command line (Terminal based) on Linux Operating Systems. That is youtube-dl, this is a python based code and can be executed in linux OS without any hassles. youtube-dl in windows or Mac OS can be achieved by installing python interpreter and try it. for installing in linux, the command is $prompt] sudo yum install youtube-dl (in redhat or centos or fedora) $prompt]  sudo apt-get install youtube-dl (ubuntu or linux mint) See the image for downloading in Fedora 20 Youtube-dl in Fedora 20 In ubuntu, you can update the sudo package before installing the youtube-dl. sudo apt-get update To download videos  $prompt] youtube-dl the above command will download the video in the best possible format. See the image below. The video dow

Blogging and Google Adsense get me a DSLR Camera

By blogging and Google Adsense, my long time wish have come true that I got an DSLR (Nikon D5100).  Nikon D5100 Blogging is a word that seems to be a "No man's Land" when I started this blog in 2006. Yes I started this blog mainly for providing lecture notes to my students. Initially I started this with and a year later, I purchased  (this website) and shared contents.  Initially I was not bothered about the ranking, search engine optimisation (SEO), page rank, etc. My main motive was to create content for the student community. Slowly, I improvise my contents to satisfy the global readers too. The topics that covered in my domains play a vital role in the provide information to open source research community.  The topics of interest are  Network simulator 2 Linux Open Source Technologies MOODLE Wordpress PHP, MySQL Real TIme Systems Embedded systems, Java and etc. This website was hacked twice and contents gets

nohup command in Linux

Often you come across a situation where you try to open a machine remotely using ssh and try to start a server or a run a command indefinitely. But once you close the ssh session, your session also terminates and the background process also terminates. So here is a solution. To open ssh remotely, prompt $] ssh username@machinename Ex: ssh root@ Ex: ssh  prompt $] ssh -X username @machinename  Ex. ssh -X root@  (this -X indicates the remote session can be opened in X window (GUI) mode) Assume we need to start a httpd server in the remote machine. we can issue the command like this usage: prompt$] nohup command  if any error or log information may be stored in the nohup.out file. if you want to redirect to a file use the redirected symbol (1>  indicates standard output and 2> indicates standard Error). Specify the filenames for the output. Here is the typical nohup command to start the httpd server. prompt $] nohup

How to display Product name and Vendor name in Linux

This post will help you to find out the Product Name System Vendor Name  This will help you to find the suitable device drivers if any. The following is the command to find the System Vendor (in my case it is Hewlett Packard) prompt $] cat /sys/class/dmi/id/sys_vendor Here is the command to find the product name prompt $] cat /sys/class/dmi/id/product_name Printing the System Vendor and Product Name cat is the command to concatenate the files and print it to the standard output  T S Pradeep Kumar

C Programming Examples - Part 2

Here is the list of sample programs using C, This is list number 2. There are 21 more programs at this post. C Program 1 – To find the reversal of a given number Assume the number 1234, after reversal the number becomes 4321. Input: One number, Ex 1234, declared to num Output : One number, Ex 4321, rev is the variable Logic: separate each digit using modulo operator from the right and bring that number to front divide the given number by 10, so the right most digit will be discarded. run till the number becomes <=0 output the result #include <stdio.h> #include <conio.h> int main() {     int num,rev=0;     printf("enter the number to be reversed");     scanf("%d", &num);     while(num>0) //till the number is positive, perform the process     {     rev=rev*10 + (num%10); //separate each digit and bring it to the first

Passing a Structure to a Function

A function can accept a structure as a parameter and even it returns a parameter too. Either the individual structure elements can be passed or the entire structure can be passed. Here is the example, for passing the entire structure to a function #include <stdio.h> #include <conio.h> //Structure declaration struct student { char name[10]; int no; }; //Function prototypes void read(struct student); struct student display(struct student); //function which takes the entire structure as a parameter and it returns a structure also int main() {     struct student s1,s;      printf("Enter the details");     scanf("%s %d",,&;     s=display(s1);  //function call printf("Name is %s and number is %d",,;     getch(); } //Function definition struct student display(struct student s) { return s; } Nested Structures A structur

Structures and Unions

Structure in C groups different data type under a common name struct is a keyword to declare a structure The size of the structure depends on the size of the different data types Structure declaration always ends with a semicolon Example: struct employee { char name[50]; int empid; float salary; }; The total size occupied by the above structure is 50 + 2 + 4 = 56 bytes (on TC compiler) and 50 + 4 + 4= 58 (on other compilers like GCC, etc). Again the size depends on the compiler. GCC compiler always increase the size of structure which is divisible by 4 for faster code generation, so the above structure takes 60 bytes of memory Declaring a structure does not consume any memory, only when the structure object is created memory occupies Variables initialization will not be done during the structure declaration The above syntax declaration does not consume memory, but the following do int main() { struct employee e1; } Now e1 consumes memory of 60 bytes. S

String Functions in C

Like numbered arrays, C handles character arrays (strings). Each string is identified as a character array and ends with a ‘\0’(null) character (the compiler automatically adds the null character). So the end of string is identified as a null character. Being an array, all the elements of the string array stored in continuous memory locations following is the declaration of character array char name[50]; or char name[]=”Pradeep Kumar”; or char name[20]=”Hello Pradeep”; Strings can be handled or manipulated through loops or library functions. There are some library functions to handle strings are available at string.h Some of them are strlen(string) This is to find the length of the string and returns an integer For example, if “Hello” is the string, the length will be 5 and “Hello “, the length is 6 (there is a blank space after o in hello) strcat(String1, string2) to concatenate two strings One string will be appended to another string (the concatenatio

Arrays of C Program

Arrays in C programming starts with memory addresses. Yes the compiler handles arrays as memory addresses. Similar elements group together with a single name is called array the indexing always starts with 0 and ends at n-1 (if the size of the array is n) Array elements stores in consecutive memory location. The array elements usually stores in consecutive memory location. For example, int a[10];  //Array with size 10 the above example is an integer array with size 10 or this array can hold 10 variables. The elements starts from a[0], a[1], a[2]…..a[9], so totally there are 10 elements. Array elements values memory address location a[0] 32 600AH  (This address is called as the base address) a[1] 34 600EH a[2] 23 6012H a[3] 35 6016H a[4] 45 601AH a[5] 67 601EH a[6]

User Defined Functions in C

Almost all the programming languages uses functions. Functions are the entities which are grouping a set of statements which do a specific job or set of jobs. Example: sum of integers, sum of float number, complex number addition. All the above three can be implemented as a single function or three separate functions. When someone wants to use that, a function can be simply called. So function implementation happens as Function prototype or Function declaration Function definition or function implementation Function call Function prototype It is necessary to specify the name of the function, the parameters and the return type to the compiler that the function is being defined in this program. The prototype ends with a semicolon syntax: int sum(int, int); //function prototype Function Definition This is the actual function definition which shows the function implementation. for the above syntax here is the function int sum(int a, int b) { int c; c=a+b; re

Decision Making and Looping

C supports Decision Making and Looping (Interations) In decision Making, if, if-else, if- else if – else, switch – case is used. if(condition) { //These statements are executed only if the condition is true or 1 } if – else if(condition) { //These statements are executed only if the condition is true or 1 } else { //these statement are executed only if the condition is false or 0 } (in the above example, there is no else part means that for some situation, there may not be a need for else part) if – else if – else if(condition 1) { //These statements are executed if the condition 1 is true or 1 } else if (condition 2) { //These statements are executed if the condition 2 is true or 1 } else { //These statements are executed neither condition 1 nor condition 2 are true // if all the conditions fails, then this statement will execute } Switch Case switch (expression) { case 1: statement 1; break; case 2: statement 2; break; case 3: statement 3;

Data Types in C Programming

Declaration of variable names does two things it tells the compiler what the variable name is specifies what type of data the variable will hold So it is mandatory that each variable should belong to a particular data type. C supports different data types like integer, character, float, double, etc. Data type Size on a 16 bit machine Range char 1 byte or 8 bits -128 to 127 signed char 1 byte -128 to 127 unsigned char 1 byte 0 to 255 short int or short 1 byte -128 to 127 int 2 bytes -32768 to 32767 unsigned int 2 bytes 0 to 65535 long int or long 4 bytes -2,147,483,648 to 2,147,483,647 unsigned long int 4 bytes 0 to 4,294,967,295 float 4 bytes 3.4E-38 to 3.4 E+38 double 8 byte

C Tokens

Tokens are classified as Keywords Identifiers Operators Constants Special Symbols Keywords Keywords are reserved by the compilers and keywords will not be redefined (means the keywords are not been declared as variable names, etc). There are standard 32 keywords in C compiler, and some compilers uses more keywords based on their specification. Here is the list of 32 keywords auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while Identifiers Identifiers are variable names declared inside the program. They use alphabets, number, symbols

IO Functions - printf and scanf

Printf() is a function to print strings to the display unit and scanf() is to scan the input through the keyboard the f in the printf and scanf are called as format. That is, printf() and scanf() will print and scan in some particular format, it is the duty of the developer to provide that formats. For example printf(“a=%d, b=%d”, a,b); //This function will print a=10, b=20 if the values of a and b are 10 and 20 scanf(“%f”, &a); //this will accept a float number as the specifier is %f which is for float, See the Ampersand symbol which to tell the compiler to store the variable into the address. Here is the list of format codes or format specifiers scanf() format codes Code Meaning %c read a single character %d read a decimal integer %f read a floating point value %e read a floating point value (even in exponential format) %g read a floating point

Simple C Program

/* This program is written by T S Pradeep Kumar on 28th Sep 2010 This is to display Hello World to the display unit */ #include <stdio.h> //including the standard IO functions like printf(), scanf() int main() { printf(“Hello World \n”); return 0; } stdio.h is the library which contains the printf(), scanf() and other standard IO functions, so before we use any function we need to include in our C program. Most of the compilers will take stdio.h automatically, even if we dont include in our program int main() {} is the main function printf(“Hello World\n”); printf() is the function which is printing to the display unit and it is displaying Hello World. Whatever is there inside the double quotes will displayed as it is in the monitor except the format specifiers or format codes (%d, %f, %c) return 0; is the final statement which returns the integer value 0 (this is just to make the compiler happy) Here in the above program, you can see there are semi colon

C Programming - Introduction

This post and the subsequent posts will help you in understanding the intricacies of C programming. These posts just shows you the basics of C programming and some worked examples for that.  C Program with Linux Features of C Programming C is a small language having lesser number of keywords than Java or pascal. C is a native language of Unix, Linux. Not only that many of the windows packages, database programs, graphics libraries are written in C program C is portable – it provides standard set of libraries that work on the same way with all machines C is modular, as it supports functions to divide the program in to sub program C is efficient on most machines, because certain constructs are machine dependant. Structure of a C program Comments the comments are usually ignored by the compiler so this part informs about the author of the program what is the usefulness of this program updation or creation of the program Example: //  - Single line comment /* -----

Simple C Programs for Beginners

This post has no relation with networks, however these C programs help anyone who started learning C programming. It covers from basics of C to Arrays and Functions. The readers are requested to get their outputs, as the output screenshots were lost. Also most of these programs were solved by my student friends. If you encounter any errors in the programs, kindly comment below to get it rectified through other readers. To compile these programs in Windows : Use Dev-C++ for compilation (It GUI Based), Also you may remove #include <conio.h> if you encounter any error during compilation In Linux:  You may try the gcc or g++ compiler Delete the #include <conio.h> delete the line that contains getch();  Here is the command  $] gcc -o first file.c  $] ./first (The file.c is compiled and linked to the binary file first and the output is executing in the second line using ./first) See the following screenshot for the Question 1. Output of a C Program Question 1