mardi 2 juin 2015

Is it correct to use while-loop to report progress and completion?

I have added zip4j library to my Android project. It is very easy to use.

ZipFile zipFile = new ZipFile(downloadedFilePath);
zipFile.extractAll(context.getFilesDir().getPath());

But there is one feature that I am concerned about. Instead of subscribing to get the progress of unzipping, they use while-loop as follows:

while (pm.getState() == ProgressMonitor.STATE_BUSY) {
    // my progress handler is here
}

And if I need to know that unzip is complete, I should use it as follows:

while (pm.getState() == ProgressMonitor.STATE_BUSY) {
    // the loop runs until progress monitor changes its status
}
if (pm.getResult() == ProgressMonitor.RESULT_SUCCESS) {
    // my code to handle completion
}

To me it looks as anti-pattern and poor coding. Should I use in my project, or switch to a different zip-library?

lundi 1 juin 2015

In given code which exception that will occur in the following program and how will u fix it?

What is the exception that will occur in the following program and how will might I fix the problem?

package com.quest.interview;

public final class Singleton {

    private static final Singleton sinleton_inst= new Singleton();
    public static final Boolean have_Instance = true;
    private final Boolean inst_Avail=have_Instance;

    private Singleton(){};

    public final Boolean isInstAvail() {
        return inst_Avail;
    }

    public static void main(String[] args) {
        System.out.println(sinleton_inst.isInstAvail() ? "Instance is there." : "No instance");
    }
}

EmberJS and URL structure issues

We are using EmberJS for some sign up forms on our website. The sign up is for different sections of our offering. We should like the form to reflect the section, in the following URL pattern:

http://ift.tt/1db2PZy  
http://ift.tt/1K5UlQy  
http://ift.tt/1db2PJj  
...

We want the signup form across these sections, around ten sections or so, to be the same Ember code but referring to ten config files.

The issue with this is that EmberJS would either require all the JS and assets to be in the root folder to achieve the architecture I describe above, or we would need multiple copies of the same Ember and assets in ten folders for each section.

Because ember wants the JS etc to be in the same location, ideally in root, I suppose the following is easy:

http://ift.tt/1K5Uofd  
http://ift.tt/1db2PJl  
http://ift.tt/1K5Uofh  
...

But this is not ideal for us given our URL pattern ambition. Both for human users and SEO purposes.

Is there something creative we can do to work around this Ember limitation? Something like URL rewriting or any other clever structuring of code. Welcome any thoughts from the gurus.

Thank you

What is the best way to implement a fast, scalable statistics aggregation architecture?

The problem:

When displaying user statistics in our e-commerce website (e.g: sales/shopping analytics, etc…) we use a fan-in approach: certain flows in the system trigger an event to a rabbit worker, which aggregates statistics per user in MongoDB, so that most of the calculations are done upon insert and retrieving statistics for display is trivial and very lightweight.

When an event isn’t received in the worker, the counters start to ‘drift away’ from the true MySQL count.

counters may drift due to:

  • Service outages
  • Bugs
  • Multiple-workers synchronisations (2 workers can update the same document, so updates must be atomic, like mongo’s ‘inc’)

As the number of users/orders/messages/etc keeps growing, doing MySQL counts and joins to calculate these stats on-the-fly becomes less and less scalable. So we can’t do that. That’s why we chose the fan-in approach to begin with.

What is the best solution to overcome these "drifts away" in a robust and scalable way?

HOW DO YOU CHOOSE WHICH DESIGN PATTERN TO USE? [on hold]

How would you decide which design pattern to use?

I am asked the above question in at-least 2 different interviews .Apparently I am not the only one.Somebody else posted the same question on glassdoor.

http://ift.tt/1cucmu6

Any thoughts/suggestions/comments on how to answer that question ?

Fire and forget pattern over TCP, is it good to connect, send and disconnect?

I was wondering how the fire and forget pattern is implemented over TCP. I think that the three steps are connect, send message and disconnect but what keeps me thinking about how it is really implemented is the overhead related to the three-way-handshake. Maybe it is implemented with a persistent connection due to this overhead? I don't think so but I need some clarification about this.

In SQL, what is the memory-efficient way of "mapping" 1 ID to multiple IDs?

I'll describe my scenario so you guys understand what type of design pattern I'm looking for.

I'm making an application where I provide someone with a link that is associated with one or more files. For example, someone needs somePowerpoint.ppx, main.cpp and somevid.mp4, and I have a tool that makes kj13h1djdsja213j1hhadad9933932 associated with those 3 files so that I can give someone

http://ift.tt/1FPtoxm

and they'll get a list of those files that they can download individually or all at once.

Since I'm new to SQL, the only way I know of doing that is having my tool use a table like

     fid                        |          filename
------------------------------------------------------------------
kj13h1djdsja213j1hhadad9933932            somePowerpoint.ppx
kj13h1djdsja213j1hhadad9933932            main.cpp
kj13h1djdsja213j1hhadad9933932            somevid.mp4
jj133823u22h248884h4h24h01h232            someotherfile.someextension

to go along with the above example. It would be nice if I could do some equivalent of

     fid                        |          filename(s)
---------------------------------------------------------------------------
kj13h1djdsja213j1hhadad9933932      somePowerpoint.ppx, main.cpp, somevid.mp4
jj133823u22h248884h4h24h01h232            someotherfile.someextension

but I'm not sure if that's possible or if I should be using some other design pattern altogether.

Any advice?