Hot Posts:

Jun 15

Solved Python – Object of type ABC is not JSON serializable


Problem: For your custom Python class if you try to use json serializer or try to return the object through REST api you see this error – Object of type ABC is not JSON serializable

Solution: For simple custom class you can use following solution

import json
class ABC:
  def to_json(self):
  return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)

abc = ABC()
abc.to_json()

Aug 24

Solved: fatal: multiple stage entries for merged file ‘Assets/Prefabs/Resources’


In some cases you might run into this git issue

fatal: multiple stage entries for merged file ‘xyz’

OS : Mac
Git : 2.5.4

Solution:
1. Delete git index rm .git/index

2. Add files again git add -A

3. Commit files again git commit -m "Message"

Aug 10

Solved: Class JavaLaunchHelper is implemented in both


Recently ran into this weird issue while running the application using Eclipse photon. The message looked like this

objc[3979]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.

This is a known issue with some earlier jdk versions; Though oracle website claims that it is a harmless issue. The easiest fix is to upgrade your jdk version. In my case upgrading to jdk1.8.0_151.jdk fixed the issue.

Aug 07

CURL post file data and additional parameters


Problem: Post file data & additional parameters to REST API through curl or command line

Solution:

curl -F ‘file=@{LOCAL_FILE_LOCATION}’ http://localhost:8080/api/data/add -F “info={“p”:false,”subtype”:”BT”,”userid”:”abcd@gmail.com”}”

Eg Java API to consume the above curl data:

@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity<String> addData(@RequestParam("info") String info, @RequestParam("file") MultipartFile file) {

Aug 01

Solved – Upgrading AWS EC2 instances from M4 to M5 type


AWS had recently launched M5 instance type; which are essentially upgrade to M4 instances. We wanted to use the latest instances so we decided to upgrade our server infrastructure.

But it’s a tricky processes then we had anticipated and AWS documentation has tooo much information. Here are the steps we took:

    • Before you start – Create an image of your current system
    • Assumption – You have an active M4 instance
    • Check if ENA (Elastic Network Adapter) support is available on your machine. This is must for M5 instance. From your local console (assumption aws cli has been installed)

      aws ec2 describe-instances --instance-ids instance_id --query "Reservations[].Instances[].EnaSupport"

      If you get empty response then it means it’s not enabled.

      []

    • Read the rest of this entry »

Nov 20

Mac – Install NPM / Nodejs without sudo or root


I don’t like to use sudo/root while installing third party softwares. I ran into issues while installing nodejs. Then I found a nice article which takes cares of this issue.

npm installs packages locally within your projects by default. You can also install packages globally (e.g. npm install -g ) (useful for command-line apps). However the downside of this is that you need to be root (or use sudo) to be able to install globally.

Here is a way to install packages globally for a given user.

1. Create a directory for your global packages

mkdir “${HOME}/.npm-packages”

Read the rest of this entry »

Oct 26

Fixed: redirect_uri_mismatch Google SignIn Problem Oauth2


If you are trying to integrate Google oauth into your application then you might see this kind of error. This happens because you didn’t correctly configure the redirect url in Google console. Follow this steps:

– Login to https://console.developers.google.com & Go to your existing project
– Go to Api & Auth -> Credentials
– In my case I was trying to integrate it locally so ‘Authorized Javascript Engines’ say ‘http://localhost:8080’
– Now in ‘Authorized redirect URIs’ add entry ‘http://localhost:8080/signin/google’. You are done!

Oct 20

Fixed : Spring Hibernate – could not obtain transaction-synchronized Session for current thread


If you ever run into this exception in your spring-hibernate setup then just do following things.

1 – Annotate all your @Repository classes with @Transactional attribute
2 – Add @EnableTransactionManagement to your config class which is generating sessionFactory & hibernateTransactionManager. That’s it 🙂

Oct 16

Multi module project spring boot parent


If you are using a spring boot in your application then you might stumble upon spring-boot-parent artifact is represented this way e.g.

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.2.RELEASE</version>
<relativePath /> <
</parent>

But in case if you already have multi-module project setup, you might have existing parent structure. How to integrate two?

Solution:

Just keep your existing project structure as it is and instead of the above spring block add a dependency management section in pom. e.g

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>${springboot.version}</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

This was suggested on the stackoverflow & it did trick for me 🙂

Oct 12

criteria uniqueresult() null projections hibernate


Ran into weird issue with hibernate

criteria.setProjection(Projections.rowCount());
long count = (Long) criteria.uniqueResult();

in above case criteria.uniqueResult() should never return null.

Solution:
This happens when you have multiple sessions factories in the code & they are not wired correctly. Just match them correctly so they don’t interfere with each other. 🙂

←Older