Saturday, November 5, 2016

Kali Copy/Paste not working in VMware Workstation 12

solution found on following url

1. uninstall vmware-tools (if installed)
$ sudo /usr/bin/

2. Install VM Tools
$ sudo apt-get install open-vm-tools 
$ sudo apt-get install open-vm-tools-desktop 

3. restart Kali 
$ sudo init 6

Friday, September 9, 2016

change or set locale environment variable

$ more /etc/sysconfig/i18n 
For Kali Linux:
echo "export LANG=\"en_US.UTF8\"" >> .bashrc 
Note: .bashrc will be read everytime upon opening a new terminal. 

Tuesday, April 26, 2016

HDMI output issue with Raspberry Pi 3

You need to edit /boot/config.txt file in order to enable HDMI forcefully ie even if no display is connected.

the second entry 'hdmi_drive=2' force HDMI mode rather than DVI, this makes audio works in DMT (computer monitor).

complete file config.txt

The 64 MB partition of the SD-card is mounted as /boot when OS is booted and running.

New User add in Kali linux

To add new user in Kali (with root user):
  useradd -m username
  passwd username
  usermod -a -G sudo username
  chsh -s /bin/bash username

To set timezone:
  echo "TZ=Asia/Kolkata;export TZ" >> .profile

On Raspberian:
  sudo cp /usr/share/zoneinfo/Asia/Kolkata /etc/timezone

Monday, December 7, 2015

Portals for fetching open data

[From Open Source For You - November 2015 issue]


World Health Organisation:  - not available

The World Bank:


United States Government:

Monday, March 3, 2014

Compressing using bz2 library in C++

For Compiling:
$ g++ code.cpp -lbz2

Need to open two FILE*
one to read from and second to write compressed data 

#include <bzlib.h>

int bzerror = BZ_OK;
BZFILE *bfp = BZ2_bzWriteOpen(&bzerror, fpout, 9, 0, 30);
if (bzerror != BZ_OK)
    BZ2_bzWriteClose(&bzerror, bfp, 0, NULL, NULL);
    return 1;

memset(buf, 0, nBuf);
while (fgets(buf, nBuf, fpin) != NULL)
    len = strlen(buf);
    BZ2_bzWrite(&bzerror, bfp, buf, len);
    if (bzerror == BZ_IO_ERROR)
        std::cout << "bz-io-error detected\n";
    memset(buf, 0, nBuf);
BZ2_bzWriteClose(&bzerror, bfp, 0, NULL, NULL);

// ---- end ----

BZFILE *BZ2_bzWriteOpen( int *bzerror, 
                                                   FILE *f, 
                                                   int blockSize100k
                                                   int verbosity
                                                   int workFactor );

- blockSize100k specifies the block size to be used for compression
- verbosity should be set to a number between 0 and 4 inclusive. 
  0 is silent, and greater numbers give increasingly verbose monitoring/debugging output 
workFactor controls how the compression phase behaves when presented with worst case,   highly repetitive, input data. 
  If compression runs into difficulties caused by repetitive data,the library switches from the standard sorting algorithm to a fallback algorithm. 
  The fallback is slower than the standard algorithm by perhaps a factor of three, but always behaves reasonably, no matter how bad the input


Reading Compressed file ie Extracting Data

#include <bzlib.h>

int nBuf = 512;
memset(buf, 0, nBuf);

bzerror = BZ_OK;
while (bzerror == BZ_OK)
    BZ2_bzRead(&bzerror, bfp, (char*)buf, nBuf);
    if (bzerror == BZ_IO_ERROR)
        std::cout << "bz-io-error detected\n";
    std::cout << buf;
    memset(buf, 0, nBuf);
BZ2_bzReadClose(&bzerror, bfp);

// ---- end ----

BZFILE *BZ2_bzReadOpen(int *bzerror, 
                       FILE *f, 
                       int verbosity, 
                       int small
                       void *unused
                       int nUnused );

- If small is 1, the library will try to decompress using less memory, at the expense of speed.
- decompress the nUnused bytes starting at unused

Tuesday, September 11, 2012

URL Decode in C ( http query string )


* to decode http query_string ie to convert special characters in
* Query String to their original form like %20 to space %22 to  
* double-quote
* if 'str' contains  type=it%20is%20simple%20%22text%22
* ie when called as
* http://localhost/cgi-bin/a.out?type=it is simple "text"

* when used as cgi-bin with apache

* for GET method there is environment variable set by apache QUERY_STRING
* for POST method, need to read from STDIN 

int urlDecode(char *str);

int main(int argc, char *argv[])
    char *query_string;
    printf("Content-type: text/html\r\n\r\n"); /* required */
    query_string = getenv("QUERY_STRING");
    if (!query_string)
        printf("QUERY_STRING not found\n"); return 1;
    printf("text received: %s \n", query_string);

int urlDecode(char *str)
    unsigned int i;
    char tmp[BUFSIZ];
    char *ptr = tmp;
    memset(tmp, 0, sizeof(tmp));

    for (i=0; i < strlen(str); i++)
        if (str[i] != '%')
            *ptr++ = str[i];

        if (!isdigit(str[i+1]) || !isdigit(str[i+2]))
            *ptr++ = str[i];

        *ptr++ = ((str[i+1] - '0') << 4) | (str[i+2] - '0');
        i += 2;
    *ptr = '\0';
    strcpy(str, tmp);
    return 0;