How to use OpenCSV to write CSV files to S3

In the previous post about How to read csv files from S3 using OpenCSV, we have seen how to open and files on S3 and read the comma separated data into list of hashmaps. In this article, we will see how to perform the reverse, writing data to the files.

Most of the fundamental concepts do not change. You need to create S3 client if you want to do anything with S3. The AWS profile configured should be of the user or role that has permissions to write to S3. The bucket policy should allow writing files. I’m not going to cover how to setup aws credentials and IAM policies in this post. The method getS3() in the complete code snippet below is going to return an S3 client same as the previous post.

Read more
Thumbnail image

How to read S3 CSV files into hashmaps using OpenCSV

In this world where large amounts of data is becoming a norm, it is very frequently stored in S3 in csv format for consumption through serverless database layers such as Athena. However, you often have to read the csv files without using Athena. In such cases, you can use ever useful libraries such as OpenCSV to read csv files.

This example shows how to use opencsv to quickly read the S3 files without the need to download them first. This helps when you do not have a way to save files locally of if you don’t have enough hard disk space. The solution is quite simple. You just have to create an InputStream from an S3 object using getObject method on S3 client. Once the input stream is created, we can use this to create a CSVReader from it.

Read more
Thumbnail image

Expiring Local Storage Objects in JavaScript

All the modern browsers have multiple types of storage mechanisms for using in your web applications. You may have already heard of cookies which are small bits of information you can store and they will be automatically expired. However, cookies can only store small amounts of information. The other kind of storage is sessionStorage, where you can store big chunks of information. However all the data stored in this will be lost as soon as you close the browser tab.

Local storage provides an intermediary option, it can store large amount of information and it will not be lost after the user closes the tab or browser. The data is persisted across sessions. However, we may want a better solution. We want to store large chunks of data across sessions, but we still want to have an option of invalidating after a certain period of time. Let us see how to go on about solving the problem.

Read more

A Definitive Guide to AWS Application Integration

Last year has been a roller coaster ride for me. Adjusting to the new team, new technologies, new country, moving across continents and many more stressful scenarios. However something good came of 2019 by end of it. We have published our book, The Definitive Guide to AWS Application Integration. You can buy it from amazon any many more stores.

Top View of Binary Tree without Recursion

Top view of a binary tree

If you have a binary tree and wants to get all the nodes that will be visible when seen from the top of the tree, how do you print all such nodes? Final output for this tree should be 7, 13, 23, 44, 51, 65. A similar problem about printing right view is given in the previous post about Right View of Binary Tree without Recursion

Read more

A Great Tool for Datastructure Algorithm Visualisation

There have been many times, we get doubts about how a certain algorithms work. There is no better way than being able to visualise that algorithm. For example check this page where you can see how each sort works on same array input. I used to embed their webpage but now they have blocked cross site embedding, hence you need to go their page to see the animation. https://www.cs.usfca.edu/~galles/visualization/ComparisonSort.html Open the URL and click on the algorithm so that you can visualise how each algorithm sorts.

Read more

Right View of Binary Tree without Recursion

Right view of a binary tree

Right view of a binary tree

Imagine you have a binary tree and wants to get all the nodes that will be visible when seen from the right side of the tree. How do you print all such nodes? Final output for this tree should be 44, 51, 65, 26. In other words, the first nodes we touch upon if we draw horizontal lines from right side of the tree. Read on to find the solution.

Read more

Collapsible panel using OJet & jQuery

Before we begin, let me show you the final output we are going to get. Click Run Pen button if you want to see the collapsible panel in action

The panel can be minimized or maximized by clicking on the arrow button. It can also be removed completely by clicking close button. How do we achieve this? I have used KnockoutJS, OracleJET and jQuery to achieve the result. RequireJS is also used but only to get the required libraries from CDN. However, OracleJet is predomantly is used for styling alone. Rest of the bindings can be achieved by regular KnockoutJS and jQuery. Read forward to learn how to get the above result.

Read more
Thumbnail image

Breadth First Traversal In a Binary Tree Without Recursion

The Problem

Imagine you have a binary tree where as shown above. You may be aware of InOrder traversal where you follow a scheme of visiting left subtree and then visit root node and finally visit right subtree. With small variations in order same is done in pre-order as well as post-order traversal. How do you do a breadth first traversal? It is slightly more tricky. Doing it non-recursively is even more difficult at first sight. Let me first explain what is breadthfirst traversal. You start at root and process it and then you process both children of the root from left to right or right to left. Then you visit all the children of both the nodes you just visited and continue to do till all the levels are finished.

Read more

Restricting an ojInputText to accept only numbers

Oracle Jet is a beautiful toolkit for simplifying lot of tasks. ojInputText is a basic editor the framework provides, it can validate the text entered based on the regular expression we give, but validation only happens on blur and if we simply want to filter any keystrokes that don’t match that, we can’t do it by default.

Here is the result before we go and learn how to do it.

Ofcourse we can use ojInputNumber and use the example they gave for eating non-numbers, but what if we don’t want the increment and decrement the arrows of ojInputNumber. One way to do it is to bind a keyUp event and check everytime a character is pressed. Infact this is the approach that is used for the example given in OracleJet cookbook.

Here is an alternative approach using ojInputText. Instead of bindng to value, we can bind to rawValue attribute. This ensures that the observable gets updated on every keystroke.

Read more