JIRA: Useful Filters

Work Log Per Week

worklogAuthor = <Your Username> AND worklogDate >= startOfWeek() AND worklogDate <= endOfWeek()

Work Log Last Two Weeks

worklogAuthor = <Your Username> AND worklogDate >= startOfDay(-14d) AND worklogDate <= endOfDay()

All Tickets Where You Are the Assignee

assignee WAS currentUser()

All Defects Created Daily

issuetype in (Defect) AND “Group ID” IS NOT EMPTY AND “Environment” in (Production) AND createDate >= startOfDay(-1d)

Your Open Issues

assignee = currentUser() AND resolution = Unresolved order by updated DESC

Issued Viewed Currently

issuekey IN issueHistory() ORDER BY lastViewed DESC

Share
Leave a comment

There are better options than using one array for names and another array for resources.

I encounter a piece of code which bugs me:

int[] images = {
		R.drawable.ic_image_1, R.drawable.ic_image_2, R.drawable.ic_image_3, R.drawable.ic_image_4, R.drawable.ic_image_5
		R.drawable.ic_image_6, R.drawable.ic_image_7, R.drawable.ic_image_8, R.drawable.ic_image_9, R.drawable.ic_image_10
};

String[] imagesNames = {
	"Image One", "Image Two", "Image Three", "Image Four", "Image Five", 
	"Image Six", "Image Seven", "Image Eight", "Image Nine", "Image Ten"
};

Later on, these two array are pass to all kind of method and constructors together for example:

    @Override
    public void onBindViewHolder(MasonryView holder, int position) {
        holder.textView.setText(imagesNames[position]);
        holder.imageView.setImageResource(images[position]);
    }

While this is correct, light on the memory, and use fewer CPU resources (less like of code run, smaller Big O), it welcomes all short of possible bugs, for example, lets say you add an image and forgot to add a name. You get mismatch arrays. Your code breaks. This issue is common if you are building these arrays dynamically; therefore, why not keeping the information together?

There are different ways to handle this

One way would be to create a class which holds these two items (image and image name). Then, you can create an array of objects.

private class Resource {
	public int image;
	public String name;
	Resource(String name, int image){
		this.image = image;
		this.name = name;
	}
}

Resource[] resources = {
	new Resources("Image One", R.drawable.ic_image_1),
	new Resources("Image Two", R.drawable.ic_image_2),
	new Resources("Image Three", R.drawable.ic_image_3),
	...
	new Resources("Image Ten", R.drawable.ic_image_10),
}

Then, you can iterate them:

    @Override
    public void onBindViewHolder(MasonryView holder, int position) {
        holder.textView.setText(resources[position].name);
	    holder.imageView.setImageResource(resources[position].image);
    }

Now, this is cleaner than before.

However, lets say you don’t wish to use a (public or private) class, then what to do? Well, you could use our old friend LinkedHashMap, which works like a HashMap; however, it keeps the order in which the elements were inserted into it.

LinkedHashMap = new LinkedHashMap<String, Integer>();
resources.put("One", R.drawable.ic_image_1);
resources.put("Two", R.drawable.ic_image_2);
...
resources.put("Ten", R.drawable.ic_image_10);

Now, here there is a problem. While you can iterate each of these items and get them based on the key (name), you cannot access them with an index. Do not despair! There is a solution around it by using the entrySet() method which is offer with the LinkedHashMap. The entrySet() method returns a set view of the mappings contained in the map. Lets see how it can help us:

resourcesIndexed = new ArrayList<Map.Entry<String, Integer>>(resources.entrySet());

    @Override
    public void onBindViewHolder(MasonryView holder, int position) {
        holder.textView.setText(resourcesIndexed.get(position).getKey());
        holder.imageView.setImageResource(resourcesIndexed.get(position).getValue());
    }

As you can see, without creating a container, such as a class, we can use an index to obtain the information and keep track of each pair.

 

Share
Leave a comment

Android: Multi-threading UI and Database (Room)

Each time I need an application, I encounter that those publish never fit my needs. However, I am lucky! I can make them myself.

Recently, I decided to create an exercise app that fit my purpose. Therefore, I began developing for Android again.

A few months ago, my Microsoft Phone’s battery gave up and a massive deployment to production was coming which required me to be available; therefore, I purchased the first Android I could find. For those who wonder why I had a Microsoft Phone, I was developing apps using Universal Windows Platform using HTML5, JavaScript and the WinJS library. Pretty slick; however, there were bugs and poor designed features which made people drop the Windows Phone. No even Verizon Wireless support it. A shame

Anyways, you folk are not reading this post to listen to my poorly written stories but to find a solution to your problem such as dealing with messages as:

  • Only the original thread that created a view hierarchy can touch its views.
  • Cannot access database on the main thread since it may potentially lock the UI for a long period of time

These error messages are common when working with the UI and trying to do transactions with the database via Room.

In Short

For those who don’t have the time or patience here is the code I use more often from all the other solutions:

final Handler handler = new Handler();
(new Thread(new Runnable() {
    @Override
    public void run() {
        // DO DATABASE TRANSACTION
        handler.post(new Runnable() {
	   @Override
            public void run() {
                // DO UI STUFF HERE.
	    }
        });
    }
})).start();

Other Options

So far, this is the easier and straight forwards solution that have being working for me.

I tried with runOnUiThread:

runOnUiThread(new Runnable() {
    @Override
    public void run() {
		// Run code here
    }
});

Also, I used AsyncTask:

new DatabaseAsync().execute();

private class DatabaseAsync extends AsyncTask<Void, Void, Void>{
    @Override
    protected void onPreExecute(){
    super.onPreExecute();
        // Pre-operation here.
    }

    @Override
    protected Void doInBackground(Void... voids){
        //Perform database operations here.
        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid){
    super.onPostExecute(aVoid);
        // Do UI operations here
    }
}

And used combinations of Thread and runOnUiThread:

new Thread(new Runnable() {
    @Override
    public void run() {
        // Database operation here
        try {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    // UI operation here
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}).start();

I even took a look into RxJava which is a “Java VM implementation of Reactive Extensions: a library for composing asynchronous and event-based programs by using observable sequences.”.

Conclusion

There are many ways to tackle this issue as you can see. The trick here is to understand how android handles threading and UI threading; however, such topics are for another post.

Share
Leave a comment

JavaScript: Executing synchronously

I am being ask this question often; therefore, I am posting the answer here.

Commonly there are those who wish to do a process that normally is asynchronously, such as performing AJAX operations in a synchronous fashion. There are a few ways to do this.

If you are coding in JS for NodeJS, then you can use the package async-waterfall, example:

  function readFile(callback) {
        fs.readFile('your_file.json', function (error, file) {
            if (error) {
                callback(error);
            } else {
                callback(null, file);
            }
        });
    }
    ...
    function processFile(file, callback){
        // Some code here
    }
    ...
    async.waterfall([
        readFile,
        processFile
    ], function (error) {
        if (error) {
            // handle error made in readFile or processFile method 
        }
    });

Else, you can use promise chains which is part of Javascript, example:

    new Promise(function(resolve, reject) {
      try{
          resolve(readfile());
      }catch(e){
          reject("error message");
      }
    }).then(function(result) {
      return processFile(result)    
    });

Or, you can use async/await: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

Share
Leave a comment

Great Idea, I wish I could Help You.

In the middle of the night, while sleeping, you got a great idea for a new app. You are excited and cannot wait to share it with your friend, the Amazing Developer. In the morning, you call your pal and arrange to meet for lunch. You met and shared your vision with great expectation that your companion becomes your partner; however, you find yourself being turned down. You should not be surprised. It was meant to happen. While your idea was great, you were not prepared to present it.

Developing an app is not just sitting down and coding until it happens. Many other aspects must be taken into account such as:

  • The user interface: how does the application look?
  • The user experience: how does the application behave when interacting with the user?
  • The application flow: How does it flow from the main page where the user can go inside the application?
  • The name: Does the name already exist?
  • The market research: Are there other applications like it already existing? What differentiates your application from them? What it is unique or enhanced?
  • The website: No application will be taken seriously if there is not a website for it.
  • Publishing your application: Is your application a website? Then, what hosting do you need? Is your application a mobile app? Then, what are the requirements to publish such an application? Is your application for a desktop? Which OS will it support? How are you going to sell it?
  • Social Network: Do you need a presence on social networks to promote your app?
  • The maintenance: Who is going to take care of it? How will customers reach you when trouble shows up?
  • Do I need to add an End User License Agreement? How about a Disclosure Agreement?

The list goes on, but do not despair. There is a way that you can increase your chances of success and it is by doing your homework prior to presenting your idea.

So… You got your idea. You have it in your mind. You know how it should work and why it is so great. However, let’s face it, you do not know how to do programming nor you have the intention to learn about it, then what can you do? Well, let us tackle down the things that you can do that do not require any programming skills to accomplish it.

Draw a storyboard. You only need a pencil, a ruler, an eraser, and paper. Lots of paper. The idea is to draw how the program would look and how the program should behave when interacting with the user. What will happen when the user presses the arrow button? What text will show up in the text area? Check out how other applications do it and pick what you like about them. No technical skill required for that!
Draw the website. You should use four colors. Black and white, plus two colors of your choice. Keep it simple. Browse through the internet and use other websites as inspiration to build yours. What sections will the website have? What text and pictures will those sections hold? What can the users do on your website?

Do some market research. Are there already applications out there that do the same? What will your application provide that they do not have? Does the name you wish to use already exist?

Do you require funds? Can you obtain them if you have to? How much funds do you think you will need?

Do you need to create a corporation? What kind of corporation it is?

What else can you do that does not require programming?

In short, you need to do more than just present your inspiration. Before you present your idea to your Friendly Neighborhood Developer, you should already have a lot of work done. Then, your friend can worry about making time to do the coding because you are already on top of things. Your associate does not have to spend time designing, researching and doing extra work. He or she will be more than willing to join you on your enterprise.

 

Share
Leave a comment