Wednesday, 13 September 2017

Basics of Bitcoin and Blockchain

For Blockchain & Bitcoin understanding,


If you are looking for general use of Bitcoins,  https://bitcoin.org/en/

For technical & nontech people, it is always good to understand terms in Plain English.

In case of Bitcoins, it is possible: http://amzn.to/2vTOaMM

These are the books you can refer because reading a tutorial might lead you into Confused state:


For Beginners:            Blockchain Basics: A Non-Technical Introduction in 25 Steps

For implementation:    Blockchain: Blueprint for a New Economy

For Bitcoin & block chain:  Mastering bitcoin programming the open blockchain 2nd edition

For python freaks, here is a treat:  https://github.com/bigchaindb/bigchaindb

If you want to try out Bitcoins for windows, you can download it from here:

https://www.bitcoinunlimited.info/download

Tuesday, 10 January 2017

How to reach from Swargate to Vishrantwadi

If you are arriving in the night at swargate between 9:00 to 10:00 pm, you can reach to vishrantwadi quickly as follows:

  1. Take the Pune station bus from outside of Swargate City bus Depot.

    Cost = Swargate to Pune Station = Rs. 10/-
  2. When conductor will say this is the last stop, board there.
  3. Now you are at the bus stand of Pune station. It is a small one and having 3 tracks which is its identity.
  4. You will get next bus within 10-15 min approx for Vishrantwadi and last bus will be on 11:30 pm.

    Cost = Pune Station to Vishrantwadi = Rs. 15/-
Otherwise, you can wait inside City bus Depot for the bus from Swargate to Vishrantwadi which costs Rs 20/- and a long wait time unless you are lucky ;)


Hope this helps,

Happy Journey!

Tuesday, 19 July 2016

Fix/Solution of MySQL 5.7 warning for SSL in Netbeans/Eclipse

If you are running MySQL 5.7.x and Netbeans 8.1 and you come across this warning,

"WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification." 
Don't worry! The culprits are:

1. MySQL 5.7.x (Actually its a good feature but really annoying to new users)

2. MySQL Java Connector Jar File

Solution for Culprit 1:

If your traditional code for JDBC is like:

 /*
  * To make java and mysql connectivity
  */
 package com.java.databases;
 import java.sql.*;
 /**
  *
  * @author mayur
  */
 public class Java2MySQL {
   public static void main(String[] args) {
     String dbname = "ram_db";
     String uname = "root";
     String passw = "ramayan";
     String url = "jdbc:mysql://localhost:3306/";
     String driver = "com.mysql.jdbc.Driver";
     try {
       Class.forName(driver);
       System.out.println("Connection is Registered");
       Connection conn = DriverManager.getConnection(url+dbname, uname, passw);
       System.out.println("Connection is Open");
       conn.close();
       System.out.println("Connection is closed");
     } catch (Exception e) {
       System.err.println("Something is wrong!! Please wait while we fix it");// e.printStackTrace();//(Something is wrong!! Please wait while we fix it);
     }
   }
 }

So the modified code is:

 /*
  * To make java and mysql connectivity
  */
 package com.java.databases;
 import java.sql.*;
 /**
  *
  * @author mayur
  */
 public class Java2MySQL {
   public static void main(String[] args) {
     String dbname = "don_db";
     String uname = "root";
     String passw = "";
     String url = "jdbc:mysql://localhost:3306/"+dbname+"?autoReconnect=true&useSSL=false";
     String driver = "com.mysql.jdbc.Driver";
     try {
       Class.forName(driver);
       System.out.println("Connection is Registered");
       Connection conn = DriverManager.getConnection(url, uname, passw);
       System.out.println("Connection is Open");
       conn.close();
       System.out.println("Connection is closed");
     } catch (Exception e) {
       System.err.println("Something is wrong!! Please wait while we fix it");// e.printStackTrace();//(Something is wrong!! Please wait while we fix it);
     }
   }
 }

You will find that we have appended [+dbname+"?autoReconnect=true&useSSL=false" ] to the part after URL of database.

Example:

 Connection con = DriverManager.getConnection
 ("jdbc:mysql://localhost:3306/"+dbname+"?autoReconnect=true&useSSL=false","root","");

Solution for Culprit 2:

Change the driver version of mysql connector other than 5.1.39. I have checked for 5.1.38,5.1.36.

Just use these versions and you program will be free from warning.

I have tested this with Eclipse also.

Hope this will help you !

Saturday, 3 October 2015

Installation of CUDA Toolkit on Ubuntu 20.04 LTS

About this tutorial

This tutorial will guide you about installation steps for CUDA parallel programming
architecture.

Introduction

CUDA (Compute Unified Device Architecture) is technology developed by NVIDIA Inc. 
The purpose of CUDA is to execute the programs and instructions in parallel manner on 
the processor. 

Prerequisites

Installation

After completing download and installation of Ubuntu, follow the next steps.
1. Log in as root user
2. Update Ubuntu for latest packages

# apt-get update

3. To install compiler, essential for CUDA toolkit, run following command:

# apt-get install build-essential

Some desktop version of Linux might cause problems such as slow response, 
unresponsive GUI. In order to avoid such problems, we need to switch to text mode.

4. To switch to text mode, use keyboard shortcut:  Alt+Ctrl+F1
5. Login as root.
6. Stop GUI service, use following command:
# service lightdm stop
7. Go to folder location of CUDA toolkit file
# cd /home/user_name/Downloads/

8. Download CUDA toolkit
# wget https://developer.download.nvidia.com/compute/cuda/11.4.0/local_installers/cuda_11.4.0_470.42.01_linux.run

9. Change the permission of file and run following command
# sudo sh cuda_11.4.0_470.42.01_linux.run

If file is not executable, try to run it with following command:
# ./cuda_11.4.0_470.42.01_linux.run

10. If prompt of absolute path of CUDA toolkit appear on screen, press Y
11. For /home/<user_name> option, where <user_name> will be your current name, press 'Enter'.

You'll see installation skipped then reboot with
# reboot -h

After restart, Linux will automatically switch to GUI mode. 
Repeat the steps from 4 to 9 to switch back from GUI to text mode. Now reboot system manually.

After system will start, enter two commands as general user:

# export PATH=/usr/local/cuda-11.4/bin:$PATH
# export LD_LIBRARY=/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH

Now we are ready to run our hello world program for Nvidia CUDA.

Copy and paste Hello World example in gedit.
.cu is the extension of our program.
Save to current directory.
To compile:  
# nvcc -cuda hello.cu
To run:      
# ./a.out

If you can see Hello World as output, you've successfully installed CUDA toolkit on Ubuntu.

Installing FreeGLUT in CodeBlock



Install FreeGLUT (Be Careful )

1.       Download : http://www.transmissionzero.co.uk/software/freeglut-devel/
From above location, download freeglut-mingw.zip
Extract the file in any folder.

2.       Now create two copies of GNU GCC Compiler.

a.       First is 32 bits and copy following files as directed:
        
File
From (FreeGLUT\)
To(MinGW32\)
freeglut.dll
bin
bin and C:\Windows\System32\
Freeglut.h
Freeglut_ext.h
Freeglut_std.h
glut.h  (optional as in previous step)
include\GL
include\GL
libfreeglut.a
libfreeglut_static.a
lib
lib

b.      Second one, 64 bits is other copy for it do as follows:

      File
From (FreeGLUT\)
To(MinGW64\)
freeglut.dll
bin\x64
bin and C:\Windows\SysWOW64\
Freeglut.h
Freeglut_ext.h
Freeglut_std.h
glut.h
include\GL
include\GL
libfreeglut.a
libfreeglut_static.a
lib\x64
lib

3.       Now move to settings of Compiler in CB.
a.  For 32 bits Compiler version,

Don’t forget to update Toolchain Executables as per need ,here, C:\TDM-GCC-32

Linker Settings =>Link Libraries
C:\TDM-GCC-32\lib\libfreeglut.a
C:\TDM-GCC-32\lib\libfreeglut_static.a

In “Other Linker Options”
-lOpenGL32 -lglu32 –lfreeglut

Search Directories Tab => Compiler
C:\TDM-GCC-32\include
Search Directories Tab => Linker
C:\TDM-GCC-32\lib

b.  For 64 bits Compiler version,
Don’t forget to update Toolchain Executables as per need ,here, C:\TDM-GCC-64

For toolchain Executables (in order of appearance)
gcc.exe
g++.exe
g++.exe
ar.exe
windres.exe
mingw32-make.exe

Linker Settings =>Link Libraries
C:\TDM-GCC-64\lib\libfreeglut.a
C:\TDM-GCC-64\lib\libfreeglut_static.a

In “Other Linker Options”
-lOpenGL32 -lglu32 –lfreeglut

Search Directories Tab => Compiler
C:\TDM-GCC-64\include
Search Directories Tab => Linker
                  C:\TDM-GCC-64\lib

4.       Now, create empty project with choosing compiler suitable to your OS. Right click on Project and go to the project properites and Build Targets => build type => GUI application
5.       Now download and extract this zip file:
6.       And place *.h and *.cpp files into CB project locations.
7.       Now again confirm Compiler from Rt Click on project => Build options.
8.       Now rebuild => build => run.

                You will get this output:

Installing GLUT in CodeBlock



For GLUT:
Considering we are having Codeblock and MinGW compiler,
      1.      Download this file: http://www.deannicholls.co.uk/site/files/glut.zip
      2.      Now perform following steps:
Extract the 'Glut.zip' file you downloaded and do the following:-

Copy glut32.dll into your 'C:\Windows\System32' folder (If you're using Windows 7 64-bit, you'll need to copy this file into 'C:\Windows\sysWOW64').

Copy glut.h into the ‘include\GL’ folder in the MinGW compiler folder.This folder will be 'C:\MinGW\include\GL'.

Copy libglut32.a into the 'MinGW\lib' folder. If you installed CodeBlocks and MinGW to the default directory in Step 3, this folder will be 'C:\Program Files\CodeBlocks\MinGW\lib'.

      3.      Go to CB=>Settings=> Compiler => Copy your “GNU GCC Compiler”
      4.      Rename your new compiler.
      5.      In Linker Settings => Link Libraries, add the following lines:
opengl32
glu32
glut32

      6.      Your GLUT compiler is ready and its time to execute program:


 // Created by: Dean Nicholls  
 // Date: 18th June 2010  
 // Created For: http://www.levelbylevel.com  
 //  
 // This is a small OpenGL application which will display a  
 // blue sphere on a black background.  
 //  
 // This Program was created to acompany the tutorial  
 // for setting up CodeBlocks, MinGW, OpenGL and GLUT.  
 // Found at: http://www.levelbylevel.com  
 //  
 // It is not intended to be a guide or even a good  
 // template for building a graphic application. It is  
 // therefore not properly commented or efficient.  
 // However feel free to use this code in any way you wish.  
 #include <iostream>  
 #include <GL/glut.h>  
 using namespace std;  
 GLfloat mat_ambient[] = {0.5, 0.5, 0.5, 1.0};  
 GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};  
 GLfloat mat_shininess[] = {50.0};  
 GLfloat light_position[] = {10.0, 10.0, 10.0, 0.0};  
 GLfloat model_ambient[] = {1.0, 0.5, 0.5, 1.0};  
 void setupMaterials() {  
      glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);  
      glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);  
      glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);  
      glLightfv(GL_LIGHT0, GL_POSITION, light_position);  
      glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);  
 }  
 void changeColour(GLfloat r, GLfloat g, GLfloat b, GLfloat A) {  
      model_ambient[0] = r;  
      model_ambient[1] = g;  
      model_ambient[2] = b;  
      model_ambient[3] = A;  
      glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);  
 }  
 void init(void) {  
      glClearColor(0.0, 0.0, 0.0, 1.0);  
      setupMaterials();  
      glEnable(GL_LIGHTING);  
      glEnable(GL_LIGHT0);  
      glEnable(GL_DEPTH_TEST);  
      glEnable(GL_CULL_FACE);  
      glFrontFace(GL_CCW);  
      glShadeModel(GL_SMOOTH);  
 }  
 void reshape(int w, int h) {  
      GLfloat fAspect;  
      if(h==0) h=1;  
      glViewport(0,0,w,h);  
      fAspect = (GLfloat)w / (GLfloat)h;  
      glMatrixMode(GL_PROJECTION);  
      glLoadIdentity();  
      gluPerspective(60, fAspect, 0.5, 100.0);  
      glTranslatef(0,0,-1);  
      glMatrixMode(GL_MODELVIEW);  
      glLoadIdentity();  
 }  
 void display(void) {  
      int slices = 30;  
      int stacks = 30;  
      float radius = 0.2;  
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
   glPushMatrix();  
     changeColour(0.0, 0.0, 1.0, 1.0);  
     glTranslatef(0.0, 0.0, 0.1);  
     glutSolidSphere(radius, slices, stacks);  
   glPopMatrix();  
      glFlush();  
   glutSwapBuffers();  
 }  
 void keyboard(unsigned char key, int x, int y) {  
      switch (key) {  
           case 27:  
                exit(0); // Exit the application if 'Esc' key is pressed  
      }  
 }  
 void animate() {  
      glutPostRedisplay();  
 }  
 int main(int argc, char * argv[]) {  
   glutInit(&argc, argv);  
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);  
   glutInitWindowSize (800, 600);  
   glutCreateWindow (argv[0]);  init();  
   glutKeyboardFunc (keyboard);  
   glutDisplayFunc (display);  
   glutReshapeFunc (reshape);  
   glutIdleFunc(animate);  
   glutMainLoop();  
   return 0;  
 }  

7.       Create empty project with new compiler as its current compiler.
8.       Now extract  deannicholls_glut_tutorial_main.zip and paste main.cpp inside the location of CB project.
9.       Now, confirm again by setting compiler from Build Options.
10.   After that, rebuild => build => run.

Sunday, 6 September 2015

Running Graphics Program of C on Windows 7 64 bits In CodeBlocks IDE 13.12


Today we are going to see how to run C graphics program on 64 bits Windows 7 using CodeBlocks 13.12. 

It will require only 12 steps. Follow with caution and you are done.

These are the instructions I have tried for 64 bits windows 7:
  1. Download zip file from this repository: https://github.com/stahta01/windows-games
    This one is having latest files of Graphics Libraries.

  2. Now either you are using external GCC compiler or internal GCC compiler doesn’t matter, just follow the universal procedure recommended for this.
  3. Copy the following files 
From(windows-games-master\WinBGIm)
To (MinGW)
include folder  => graphics.h
Include
src folder => Winbgim.h
Include
lib folder => libbgi.a
Lib

           If any of the files are already at destination, please overwrite as these are going to work for 64
           bits versions.

4.  Now, go to Setting => Compile and Debugger => Selected Compiler => GNU GCC Compiler.
           -  I will recommend to make copy of existing compiler and rename it. So that any kind of mess will not
           disturb other type of program execution. 



     5.    Now in Linker settings => Add => File => C:\MinGW32\lib\libbgi.a
      
     6.    Go to right part, other settings paste these parameters:
           -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
       
     7. Now half of the configuration has been done.

          
     8. Create simple empty project using codeblocks and add file with extension .cpp.
  
     9.     Most IMPORTANT part is now:

      
Now, right click on Project Name => Build Options => selected Compiler.

       You have to select the compiler which you have configured.
       Otherwise you will get:
       i. Memory access violation error "Process-returned-1073741819-0xc0000005" 
               or 
      ii. Segmentation fault.
  
     After successfully completing above steps, try the following program with Hello.cpp   
  
     This is my sample program to print name of screen:

 #include<graphics.h>  
 #include<conio.h>  
 main()  
 {  
   int gd = DETECT,gm,left=100,top=100,right=200,bottom=200,x= 300,y=150,radius=50;  
   initgraph(&gd, &gm, "C:\\TC\\BGI");  
   rectangle(left, top, right, bottom);  
   circle(x, y, radius);  
   bar(left + 300, top, right + 300, bottom);  
   line(left - 10, top + 150, left + 410, top + 150);  
   ellipse(x, y + 200, 0, 360, 100, 50);  
   outtextxy(left + 100, top + 325, "My First C Graphics Program");  
   getch();  
   closegraph();  
   return 0;  
 }  


    10.  Now, rebuild the project.

    11.  After that, compile and run.

    12.  You will definitely see such message printed,