Trunk-based Development vs. Git Flow

2017-12-18 12 min read C Programs

In order to develop quality software, we need to be able to track all changes and reverse them if necessary. Version control systems fill that role by tracking project history and helping to merge changes made by multiple people. They greatly speed up work and give us the ability to find bugs more easily.

Moreover, working in distributed teams is possible mainly thanks to these tools. They enable several people to work on different parts of a project at the same time and later join their results into a single product. Let’s take a closer look at version control systems and explain how trunk-based development and Git flow came to being.

Continue reading

web services in c with cgi

2016-06-13 2 min read C Programs

I was trying to setup a simply webservice to reply to POST requests. Earlier this was being done in tomcat which seem a little overkill to me since I already had a webserver up and running. So, a quick c program to respond to request is all that I needed. And here is the result.

/*
 * =====================================================================================
 *
 *       Filename:  Login.cpp
 *
 *    Description:
 *
 *        Version:  1.0

 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Amit Agarwal (),
 *   Organization:
*
* == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
    */
#include <stdio .h>
#include <stdlib .h>
#include <string .h>


#define MAXLEN 1024

#ifdef DBG
#define DEBUG(a,b) fprintf(stderr, a, b);
#else
#define DEBUG(a,b) 
#endif

#define HEAD "n"
#define TAIL ""

int main(void)
{

    char input[MAXLEN];
    char * data;
    char*lenstr;
    long len;


    printf("%s%c%cnn",
           "Content-Type:text/xml;charset=iso-8859-1", 13, 10);

    // len = getenv("QUERY_STRING"); // This is for GET
    lenstr = getenv("CONTENT_LENGTH");
    DEBUG( "Length string is %sn", lenstr);

    if(lenstr == NULL || sscanf(lenstr,"%ld",&len)!=1 || len > MAXLEN)
        printf("Error in invocation - wrong FORM probably.");
DEBUG( "Length is %ldn", len);
{
int count=0;
while ( count < len )
input[count++] = getchar();
input[count]='?';
DEBUG ( "Read characters = %dn", count)
}

//fprintf(stderr, "VAlue is %sn", input);
///unencode(input + 5 , input + len, data);

data = input;
DEBUG("Data value is %sn", data);

printf(HEAD);
printf("Everything else goes heren");
printf(TAIL);

fprintf(stderr, "Sent resp: tid[%s], eaid[%s], tcode[%s]n", tid, eaid, tcode);
}
</string></stdlib></stdio>

Additionally, the makefile:

Continue reading

C program to get the ascii string from a string

2012-07-25 1 min read C Programs
Example diagram of the printf function in the ...
Example diagram of the printf function in the C programming language (Photo credit: Wikipedia)

Lot of times, you would like to get the complete string in hex or ascii format and if you are one of them then this is something that will be helpful for you 🙂

Example output:

lp-amita[d=~/bin]> ./ascii aamit
String – aamit, Length – 5

Continue reading

colorgcc – Color your compiler output on Fedora

2012-07-11 2 min read C Programs Fedora

Lets start with installing colorgcc :

sudo yum install colorgcc

Now once that is done, you will need to ensure that the call to g++, gcc and others that you want to use, you will need to create a link in the “~/bin” directory, like so:

for i in g++ gcc c++ cc 
do
    ln -s $(which colorgcc) ~/bin/$i
done

The one liner above will create the links for colorgcc as **** your favourite compiler in your homedir. Don’t forget to add the bin diretory to your PATH variable:

Continue reading

Convert string to hex.

2012-04-13 1 min read C Programs

If you want to use snoop or tcpdump with advanced search in the packet, then you would need to convert the string to hex string. For this, either you can use a web search and find some web application to do that or you can use a simple C program like this 🙂

/*
* =====================================================================================
*
*       Filename:  ascii.c
*
*    Description:  ascii to dec
*
*        Version:  1.0
*        Ceated:  03/02/2012 12:08:49 PM
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  Amit Agarwal (aka), amit.agarwal@roamware.com
*  Last modified: Thu Mar 08, 2012  08:47PM
*
* =====================================================================================
*/
void main (int argc, char **argv){
    int i=0;
    char a[200]="",b[200]="";
    printf("String - %s, Length - %d\n",argv[1],strlen(argv[1]));
    /*printf("%x\n 0x",argv[1]);*/
    while (i < strlen(argv[1])){
        /*printf("%c",argv[1][i]);*/
        sprintf(a,"%s%x",a,argv[1][i]);
        /*printf("a=%s\n",a);
        printf("b=%s\n",b);*/
        sprintf(b,"%s%d",b,argv[1][i]);
        i++;
    }
    printf ("\n");
    printf ("String : %s\n",argv[1]);
    printf ("Hex    : 0x%s\n", a);
    printf ("Dec    : %s\n", b);

}
Enhanced by Zemanta

Inotify Example - Introduction to Inotify with a C Program Example

2010-05-24 1 min read C Programs Learning Linux

<a href="http://www.thegeekstuff.com/2010/04/inotify-c-program-example/">Inotify Example: Introduction to Inotify with a C Program Example:

<a class="zem_slink freebase/en/inotify" href="http://en.wikipedia.org/wiki/Inotify" title="Inotify" rel="wikipedia">inotify utility is an effective tool to monitor and notify <a class="zem_slink freebase/en/file_system" href="http://en.wikipedia.org/wiki/File_system" title="File system" rel="wikipedia">filesystem changes. You can specify a list of files and directories that needs to be monitored by inotify. This <a class="zem_slink freebase/guid/9202a8c04000641f8000000000023d0f" href="http://en.wikipedia.org/wiki/Library" title="Library" rel="wikipedia">library is used by various other programs. For example, <a class="zem_slink freebase/en/cpan" href="http://www.cpan.org/" title="CPAN" rel="homepage">CPAN module Linux::Inotify is developed based on this library.
iNotify Execution Flow

Continue reading

Last access time for file

2010-02-03 1 min read C Programs Linux

The C program will print the last access time for the file.

This is quite helpfull program when you want to find old files. Modifying the source to take the filename as argument and take multiple arguments is left as an exercise.

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <time.h>
#include <stdlib.h>
int main(void)
{
    char datestring[80];
    struct  stat a;
    //int fd = open("ak",O_RDONLY);
    if (stat ("iptc.c", &a) == -1) {
        perror("stat");
        printf (" Error");
        return;
    }
    printf (" Last Access Time is %s", ctime(&a.st_atime));
    printf (" Last Access Time is %s", a.st_atime);
}

Continue reading