Thursday, 13 May 2021

what is "dist" folder in angular

dist folder used for deploying angular app in production , because dist folder consists of files compiled from angular(typescript).

In Development, The Angular app runs on the port 4200 with the help of a webpack dev server.(webpack used only in dev, in production only js engine is used it understand only js file not typescript files). This is not the case for running in production. We have to build the Angular project and load those static assets with the node server.

dist folder consists of plain js files compiled from angular and other angular asset files. Let express know there is a dist folder and assets of Angular build

In nodejs index/server.js

app.use(express.static(__dirname + '/dist/proj_name'))

Now angular and nodejs can run on same port in production, In development you can choose to use different server for node and angular.

References
  • https://www.geeksforgeeks.org/how-to-bundle-an-angular-app-for-production/
  • https://medium.com/bb-tutorials-and-thoughts/how-to-develop-and-build-angular-app-with-nodejs-e24c40444421

Tuesday, 4 May 2021

How to find linux distribution and its version

If you are working on virtual machine, you want to know about linux distribution and its version in order to dowload related packages or software. There is a command to know it.

cat /etc/os-release

just run above command on virtual machine

Monday, 3 May 2021

set OPENSSL path in windows

openssl is a library, so no need to install, just set the path in enviorment variables

  • Download openssl from internet. you may find it here : https://sourceforge.net/projects/openssl/
  • Extract inside C:\Program Files\ folder
  • You will find project structure like this C:\Program Files\OpenSSL\bin
  • Set this path in environment variables. Advanced System Settings > Enviroment variables > System Variables > path
  • Run openssl command in command prompt. if you get "WARNING: can't open config file: C:/OpenSSL/openssl.cnf" error, run set OPENSSL_CONF=C:\Program Files\OpenSSL\bin\openssl.cnf
  • if still you are getting C:/OpenSSL/openssl.cnf error, use openssl.conf path while creating certificate / key , for example

    reference : http://irwinj.blogspot.com/2008/11/unable-to-load-config-info-from.html for example : openssl req -new -key my.key -config "C:\Program Files\...\openssl.cnf" -out my.csr

Saturday, 1 May 2021

solving PostgreSql pg_restore.exe path error : C:\Program Files\PostgreSQL\13\pgAdmin 4\runtime\pg_restore.exe not found

You may face this error when you restore stored/backup schemas.Following solution works only in windows.

  • Make sure you have installed postgreSql and pgadmin
  • Goto C:\Program Files\pgAdmin 4\v5 and copy runtime folder
  • Paste runtime folder inside C:\Program Files\PostgreSQL\13\pgAdmin 4
  • Restart pgAdmin and try

Sunday, 29 December 2019

Datatype of int , float and bool in python.


we all know that datatype of whole numbers is int
print(type(3))
output : class int


and the datatype of True is boolean
print(type(True))
output : class bool


and the datatpye of decimal numbers is float print(type(5.5))
output : class float


The type of int , float and bool in python is class "type", class type is defined in python library. Also called as metaclass. It is called metaclass because it helps to create the object of int, float and bool (and other datatypes)
print(type(int))
print(type(float))
print(type(bool))

output : class 'type'

Tuesday, 20 March 2018

copy content of two arrays into seperate array



public class TestLooping {

public static void main(String[] args) {

                //first array
                int[] firstArray = {2,4,6,8,10};

                //second array
                int[] secondArray = {12,14,16,18,20};

                //third array, size of third array is sum of firstArray length and secondArray length
                int[] thirdArray = new int[firstArray.length + secondArray.length];

                //copying elements of first array to third array
                for(int i = 0 ; i < firstArray.length ; i++) {
thirdArray[i] = firstArray[i];
}

                // copying elements of second array to third array, index of third array is added with length                  // of first array
for(int i = 0 ; i < secondArray.length ; i++) {
thirdArray[i+firstArray.length] = secondArray[i];
}

                // print all the elements of third array
for(int i=0; i<thirdArray.length;i++) {
System.out.println(thirdArray[i]);
}

}

}

Wednesday, 12 April 2017

How to Implement Parcelable in Android with String Integer and ArrayLists as fields

How to Implement Parcelable in Android with String, Integer and ArrayLists as fields

Parcelable and Serialization are used for marshaling and unmarshaling Java objects. 

Parcelable :

Parcelable process is much faster than serializable. One of the reasons for this is that we are being explicit about the serialization process instead of using reflection to infer it. It also stands to reason that the code has been heavily optimized for this purpose.

Serializable :

Serialization is a marker interface, which implies the user cannot marshal the data according to their requirements. In Serialization, a marshaling operation is performed on a Java Virtual Machine (JVM) using the Java reflection API. This helps identify the Java objects member and behavior, but also ends up creating a lot of garbage objects. Due to this, the Serialization process is slow in comparison to Parcelable.

Sample

Lets take an example of School class which has a name and obiviously School has list of Students.

First lets create School class which implements parcelable.

Remember four points to implement Parcelable

1. Creare Protected Constructor with Parcel as argument.
2. Override describeContents which always returns zero.
3. Override writeToParcel method with Parcel and int as arguments.
4. Create instance of Creator interface.


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
School.java
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1. public class School implements Parcelable {
  2. private String name;
  3. private ArrayList<Student> studentsList = new ArrayList<Student>();
  4.  
  5. public School(){ 
  6.  
  7. } 
  8.  
  9. public String getName() {
  10. return name;
  11. } 
  12.  
  13. public void setName(String name) {
  14. this.name = name;
  15. } 
  16.  
  17. public ArrayList<Student> getStudentsList() {
  18. return studentsList;
  19. } 
  20.  
  21. public void setStudentsList(ArrayList<Student> studentsList) {
  22. this.studentsList = studentsList;
  23. } 
  24.  
  25. protected School(Parcel in) {
  26. name = in.readString();
  27. if (in.readByte() == 0x01) {
  28. studentsList = new ArrayList<Student>();
  29. in.readList(studentsList, Student.class.getClassLoader());
  30. } else { 
  31. studentsList = null;
  32. } 
  33. } 
  34.  
  35. @Override 
  36. public int describeContents() { 
  37. return 0; 
  38. } 
  39.  
  40. @Override 
  41. public void writeToParcel(Parcel dest, int flags) {
  42. dest.writeString(name);
  43. if (studentsList == null) {
  44. dest.writeByte((byte) (0x00));
  45. } else { 
  46. dest.writeByte((byte) (0x01));
  47. dest.writeList(studentsList);
  48. } 
  49. } 
  50.  
  51. @SuppressWarnings("unused") 
  52. public static final Parcelable.Creator<School> CREATOR = new Parcelable.Creator<School>() {
  53. @Override 
  54. public School createFromParcel(Parcel in) { 
  55. return new School(in); 
  56. } 
  57.  
  58. @Override 
  59. public School[] newArray(int size) { 
  60. return new School[size]; 
  61. } 
  62. }; 
  63. } 
  64. /////////////////////////////////////////////////////////////////////////////////////

Now create Student class
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Student.java
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  1. public
    class Student implements Parcelable {
  2. private String name;
  3. private int age;
  4. private float height;
  5.  
  6. protected Student(Parcel in) {
  7. name = in.readString();
  8. age = in.readInt();
  9. height = in.readFloat();
  10. } 
  11.  
  12. public Student(){ 
  13.  
  14. } 
  15.  
  16.  
  17. public String getName() {
  18. return name;
  19. } 
  20.  
  21. public void setName(String name) {
  22. this.name = name;
  23. } 
  24.  
  25. public int getAge() { 
  26. return age;
  27. } 
  28.  
  29. public void setAge(int age) {
  30. this.age = age;
  31. } 
  32.  
  33. public float getHeight() { 
  34. return height;
  35. } 
  36.  
  37. public void setHeight(float height) {
  38. this.height = height;
  39. } 
  40.  
  41. @Override 
  42. public int describeContents() { 
  43. return 0; 
  44. } 
  45.  
  46. @Override 
  47. public void writeToParcel(Parcel dest, int flags) {
  48. dest.writeString(name);
  49. dest.writeInt(age);
  50. dest.writeFloat(height);
  51. } 
  52.  
  53. @SuppressWarnings("unused") 
  54. public static final Parcelable.Creator<Student> CREATOR = new Parcelable.Creator<Student>() {
  55. @Override 
  56. public Student createFromParcel(Parcel in) { 
  57. return new Student(in); 
  58. } 
  59.  
  60. @Override 
  61. public Student[] newArray(int size) { 
  62. return new Student[size]; 
  63. } 
  64. }; 
  65. } 
  66. /////////////////////////////////////////////////////////////////////////////////////////


Now we want to send Student object from one activity to another activity
In one activity create instance of School and Students classes.

/////////////////////////////////////////////////////////////////////////////////////////
First activity
//////////////////////////////////////////////////////////////////////////////////////////
  1. School school = new School();
  2. school.setName("Jnana Bharathi");
  3. Student student1 = new Student();
  4. student1.setName("Arun");
  5. student1.setAge(9);
  6. student1.setHeight(4.1f);
  7. Student student2 = new Student();
  8. student2.setName("Tarun");
  9. student2.setAge(10);
  10. student2.setHeight(3.9f);
  11. Student student3 = new Student();
  12. student3.setName("Varun");
  13. student3.setAge(11);
  14. student3.setHeight(4.0f);
  15. ArrayList<Student> studentArrayList = new ArrayList<>();
  16. studentArrayList.add(student1);
  17. studentArrayList.add(student2);
  18. studentArrayList.add(student3);
  19. school.setStudentsList(studentArrayList);
  20. /* call second activity using intent and send School instance */
  21. Intent intent = new Intent(MainActivity.this,SecondActivity.class);
  22. intent.putExtra("school_object",school);
  23. startActivity(intent);
  24. ////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Second activity
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1. School school = (School)getIntent().getParcelableExtra("school_object");
  2. Log.d("school=",school.getName());
  3. for (int index=0;index<school.getStudentsList().size();index++){
  4. Student student = school.getStudentsList().get(index);
  5. Log.d("**************","");
  6. Log.d("student name =",student.getName());
  7. Log.d("student age = ",student.getAge()+"");
  8. Log.d("student height =",student.getHeight()+"");
  9. Log.d("**************","");
  10. } 
  11. ///////////////////////////////////////////////////////////////////////////////////////
  12. You can download sample from github, below i have given link

Please leave suggestions if you face any problems.