Select a set of integer from postgres

Currently I need to return a list of integers from a select query from postgresql. I tried array (integer[]) but it didn’t look good. So, I found that we can return a type called setof.

This is the detailed post:

https://wiki.postgresql.org/wiki/Return_more_than_one_row_of_data_from_PL/pgSQL_functions

 

It’s awesome!

Awesome Tool To Clear Trash On Mac

Earlier today, my computer told me that I have only 17 GB of free storage left. 10 minutes later, it said I had 0KB left.

I didn’t know what caused the problem so I search for a tool to analyze files on my Mac. After some searches, I found OmniDisk Sweeper. It’s an awesome tool that gives me an overview of all files in my Mac. I was able find the files that occupied a lot of storage and delete it. Now, I have over 60GB of free space, which is awesome.

Here is the screenshot of the awesome software:

You can download it from here for free: https://www.omnigroup.com/more/

It’s really a great tool. However, make sure you know what you delete. Don’t touch the files that you don’t know.

Thanks the developers of Omni Disk Sweeper!

 

 

 

How to use text to speech in android

Reading text out loud using Android TTS should be an easy task. However, it wasn’t really easy for me. I spent the whole evening to get the phone to speak some text in Spanish. So, to save some time for someone who are searching, here is the way.

First, you need to create a class that implements TextToSpeech.OnInitListener. This is the class you will use to speak the text in your activities later. Let’s call it Speaker, we have the Speaker class like this:

pay close attention to this line:

This is where you set the language for the speaker. More details can be found here
 

Now, in your activity, you can make the phone speak with this:

Make sure you call:

On activity’s onDestroy.

Android SQLite ID field return 0 on query and how to fix

Lately I ran into a strange problem (for beginners maybe). This is the query I used to create a table:

However, after inserting few rows, I queried back and always got the ID field as null.

So I changed to this

And it worked properly now.

 

Why it happened?

I discovered that in the first query, somehow the INTEGER and AUTOINCREMENT stick together and there was a new type created INTEGERAUTOINCREMENT.

 

It could be a bug in Android Studio, I don’t know for sure.

Hope that helps someone who has the same problem.

 

Input field automatically hide text on click

There is a feature that has been implemented on various websites that when you click on the input field, the text disappear and the users enter their info.

Normally, you will need to know the value of the input field first to make this feature work. However, there is another way as shown below.

Here is a snippet that hide text of the input filed without knowing the value of the input field first:

You need to include jQuery first to use this snippet

Get all categories in WordPress

That’s how you get all categories in WordPress

When you click, how do you know which elements were blurred?

I’m building a drag drop page builder with jQuery and I faced this problem: I need to know when I click on a particular element, which element was blurred? Sounds easy, isn’t it? For example, there are two divs, A and B on the page. When I click on B, I want to know if right before that, A was focused. I don’t know if this make any sense to you but hopefully, it does. I thought it was impossible… Luckily, I found a solution and my editor is working as expected now.

The idea

In order to make this possible, the divs we want to check must have class attribute. Then in every click on the document, we will record the classes of elements that were clicked in a string (I will use localStorage). The problem is, how can you record the classes of elements that were clicked? This code does the trick:

In this case, the element I want to check later if it was blurred is vgt_actual_html_element.
If in the string that store all the class name of the elements that were clicked there is vgt_actual_html_element.

In the next click, when we check if the localStorage varialbe vgt_actual_html_get_clicked has the value no, that means our vgt_actual_html_element was blurred.

I hope that wasn’t too hard to understand.