Search This Blog

Thursday, June 8, 2023

Why python django uploaded images not showing in angular UI profile or any screen ?

Option 1: 

    Note:  keep your images under media/ <folder> for upload and view 


Option 2: 

if you want to change the default media folder under your project root, 

then please go to settings.py 

MEDIA=<custom path> 

MEDIA_URL=<path after above media settings>


Now

http://<url:port>/media/customfolder/image.jpg



Tuesday, June 6, 2023

Ubuntu Port Firewall uwf - not via iptables

 step 1: apt install ufw

step 2: ufw enable

step 3:   sudo nano /etc/default/ufw

          #enable ipv6=yes

step 4: Added default deny of incoming and allow outgoing

   sudo ufw default deny incoming

   sudo ufw default allow outgoing


#. to see the list   

sudo ufw app list


step 5: #. Allow open ssh for all your login and other operations

sudo ufw allow OpenSSH

   sudo ufw allow ssh

   sudo ufw allow 22

   sudo ufw show added

   sudo ufw enable


step 6: #. Allow default web ports and custom ports

   sudo ufw allow http

   sudo ufw allow https

   sudo ufw allow 8099

   sudo ufw allow 88


 

#. To see the port list

   sudo ufw status verbose


#. To deny the ports

   sudo ufw deny <port>


Thank You

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04



Thursday, June 1, 2023

Linux Ubuntu - SSH command to copy server to local or vice versa

 Copy file to Server to Local

    scp -P <port> <localfile path> <server user>@ip:<remote user home path>

    ex: > scp -P 22 mq/target/test.jar drvijay@192.2.2.2:/home/drvijay


Connect server : 

        ssh -p <port> <server user>@<IP>
        ssh -p 22 drvijay@182.2.2.2

Copy file from Server to Local
 





Note: ssh -p <port> small case for port option
          scp -P <port> upper -P for port specify.




Wednesday, May 31, 2023

Ms Sql server problem with linux python django app/settings.py

 From Database {section}


'driver': 'SQL Server Native Client 11.0',


To         

    'driver': 'ODBC Driver 17 for SQL Server'



Linux Ubuntu - See Running process with port number and details for that service

To see the pid details of running process

step 1.

lsof -i TCP:<port number>


lsof -i TCP:99


step 2

ps -ef | grep <pid>

ps -ef | grep 39100


step 3

kill -9 <pid>

Monday, April 24, 2023

Java Sample - Copy any object into any object including sub object fields generic

 Steps 1:

Source

Person.java(list address)

Address.java(User.java)


public class Person implements Serializable

{

private String firstName;

private String lastName;

private int age;

private List <AddressaddressList;

}

public class Address implements Serializable

{

private int id;

private String address1;

private String address2;

private String city;

private String state;

private String country;

private String pincode;

private String contactNumber;

private String email;

private User user;

}




Target

PersonDTO.java (list addressDTO)

AddressDTO.java (User.java)

public class PersonDTO implements Serializable

{

private String firstName;

private int age;

private String lastName;

private List <AddressDTO> addressList;

}

public class AddressDTO implements Serializable

{

private int id;

private String address1;

private String address2;

private String city;

private String state;

private String country;

private String pincode;

private String contactNumber;

private String email;

private User user;

}


Step 2: Sample java class

package com.drvijay;

import java.lang.reflect.Field;

import java.lang.reflect.Modifier;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.HashMap;

import java.util.List;

import org.apache.commons.lang3.RandomStringUtils;

import com.product.base.utils.ObjectUtils;

import com.product.base.utils.ProductConstants;

/**

* @author drvijay

* @date Apr-20-2023 10:30 AM

*/

@SuppressWarnings ( "unused" )

public class UtilHelper

{

private static final long serialVersionUID = 1L;

public static void copy ( Object source, Object target ) throws IllegalArgumentException, IllegalAccessException

{

Class <?> sourceClass = source.getClass ();

Class <?> targetClass = target.getClass ();

Field [] sourceFields = sourceClass.getDeclaredFields ();

Field [] targetFields = targetClass.getDeclaredFields ();

for ( Field sourceField : sourceFields )

{

for ( Field targetField : targetFields )

{

// If the source and target fields have the same name and type

if ( sourceField.getName ().equals ( targetField.getName () ) && sourceField.getType ().equals ( targetField.getType () ) )

{

// Make the source and target field accessible

sourceField.setAccessible ( true );

targetField.setAccessible ( true );

// Copy the value from the source field to the target field

targetField.set ( target, sourceField.get ( source ) );

// Stop looping through the target fields

break;

}

}

}

}

public static void main ( String [] args ) throws Exception

{

// Create a source object

Person sourcePerson = new Person ();

sourcePerson.setFirstName ( "vijay" );

sourcePerson.setLastName ( "kumar" );

sourcePerson.setAge ( 30 );

User u = new User ();

u.setUA ( "ua" );

u.setUB ( "ub" );

List<Address> aList = new ArrayList();

Address address = new Address ();

address.setAddress1 ( "add 1" );

address.setAddress2 ( "add 2" );

address.setPincode ( "54534" );

address.setUser ( u );

aList.add ( address );

address = new Address ();

address.setAddress1 ( "add 11" );

address.setAddress2 ( "add 22" );

address.setPincode ( "545341" );

aList.add ( address );

sourcePerson.setAddressList ( aList );

// Create a target object with similar properties

PersonDTO targetPersonDTO = new PersonDTO ();

// Copy the properties from the source object to the target object

UtilHelper.copy ( sourcePerson, targetPersonDTO );

// Print the values of the target object

System.out.println ( targetPersonDTO.getFirstName () );

System.out.println ( targetPersonDTO.getAge () );

System.out.println ( sourcePerson.toString () );

System.out.println ( targetPersonDTO.toString () );

System.out.println ( targetPersonDTO.getAddressList ().toString () );

}

}



Output


vijay

30

Person(firstName=vijay, lastName=kumar, age=30, addressList=[Address(id=0, address1=add 1, address2=add 2, city=null, state=null, country=null, pincode=54534, contactNumber=null, email=null, user=User(uA=ua, uB=ub)), Address(id=0, address1=add 11, address2=add 22, city=null, state=null, country=null, pincode=545341, contactNumber=null, email=null, user=null)])

PersonDTO(firstName=vijay, age=30, lastName=kumar, addressList=[Address(id=0, address1=add 1, address2=add 2, city=null, state=null, country=null, pincode=54534, contactNumber=null, email=null, user=User(uA=ua, uB=ub)), Address(id=0, address1=add 11, address2=add 22, city=null, state=null, country=null, pincode=545341, contactNumber=null, email=null, user=null)])

[Address(id=0, address1=add 1, address2=add 2, city=null, state=null, country=null, pincode=54534, contactNumber=null, email=null, user=User(uA=ua, uB=ub)), Address(id=0, address1=add 11, address2=add 22, city=null, state=null, country=null, pincode=545341, contactNumber=null, email=null, user=null)]


Thursday, April 20, 2023

How to skip or exclude Spring Hibernate @entities @tables creation

 Step 1:

    In your application.properties 

spring.jpa.properties.hibernate.hbm2ddl.schema_filter_provider=<your class with pacakge>
spring.jpa.properties.hibernate.hbm2ddl.schema_filter_provider=com.drvijay.ExcludeFilter

or application.yml

spring:

  jpa:

    properties:

      hibernate:

        hbm2ddl:

          schema_filter_provider: com.drvijay.ExcludeFilter


Step 2: ExcludeFilter.java

package com.drvijay;

import java.util.Arrays;

import java.util.List;

import org.hibernate.boot.model.relational.Namespace;

import org.hibernate.boot.model.relational.Sequence;

import org.hibernate.mapping.Table;

import org.hibernate.tool.schema.spi.SchemaFilter;

import org.hibernate.tool.schema.spi.SchemaFilterProvider;

public class ExcludeFilter implements SchemaFilterProvider

{

@Override

public SchemaFilter getCreateFilter ()

{

return MySchemaFilter.INSTANCE;

}

@Override

public SchemaFilter getDropFilter ()

{

return MySchemaFilter.INSTANCE;

}

@Override

public SchemaFilter getMigrateFilter ()

{

return MySchemaFilter.INSTANCE;

}

@Override

public SchemaFilter getValidateFilter ()

{

return MySchemaFilter.INSTANCE;

}

}

class MySchemaFilter implements SchemaFilter

{

public static final MySchemaFilter INSTANCE = new MySchemaFilter ();

@Override

public boolean includeNamespace ( Namespace namespace )

{

return true;

}

@Override

public boolean includeTable ( Table table )

{

List <String> list = Arrays.asList ( "table1", "table2" );

if ( list.contains ( table.getName ().toLowerCase () ) )

{

return false;

}

return true;

}

@Override

public boolean includeSequence ( Sequence sequence )

{

return true;

}

}

Wednesday, March 29, 2023

ModuleNotFoundError: no module named 'gaze_tracking', but installed python 3.x

 #Gaze_tracking

1. Install with below command, 

pip install gaze_tracking

2. find site-packages path with below command

> python -m site


3. extract gaze_tracking.zip and copy into site-packages

        > download the zip and extract into site-packages folder

    > git clone https://github.com/Arsenal-iT/gaze_tracking.git



Tuesday, March 21, 2023

Install Python Specific version upgrade or downgrade and Also Virtual Environment with the specific Python Version

1. install python 3.7 and 3.7 virtual env 

**********************************

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt update

sudo apt install python3.7

sudo apt install python3.7-venv



2. create environment
*******************
#goto your project root folder

python3.7 -m venv env3.7

source env3.7/bin/activate

now check version, all same
************************
python3 --version
python --version
python3.7 --version
pip --version
pip3 --version


3. upgrade pip
*************
python3.7 -m pip install --upgrade pip

Friday, February 24, 2023

Apache2 disable directory listing

Step 1: The best way to do this is disable it with webserver apache2. In my Ubuntu 14.X - open /etc/apache2/apache2.conf change from


Sample

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

to

<Directory /var/www/>
        Options FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Thursday, January 12, 2023

Solution Ubuntu - Anydesk Gtalk Teams Skype Screen Sharing Not Working

 Step 1: type below command in terminal

    > echo $XDG_SESSION_TYPE


Step 2: Open this file and remove the Comment # like below & reboot

> sudo nano /etc/gdm3/custom.conf

WaylandEnable=false


>reboot

Monday, January 9, 2023

Error starting Eclipse in Linux: "JVM terminated. Exit code=13"

 Steps 1:

    sudo apt install plocate
    locate javac

 Steps 2:

   Take the javac path and change to java rather in javac at last word

 >  open eclipse.ini and paste under -vm like below

-vm
/usr/lib/jvm/java-18-openjdk-amd64/bin/java

Hit Counter


View My Stats