Why does my async task handler for a sqlite database trigger postExecute
immediately
I have an async class that opens up an sqlite database and if is the first
time running the database will be populated with data that takes about 10
seconds to complete. Even though there is still working being done in the
background the async task finishes immediately. I think it has something
to do with the sqlite's oncreate method possibly doing another async task
or something
class BuildDatabase extends AsyncTask<Void, Void, Void> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
loading = ProgressDialog.show(ctx, "Please wait...", "Building
database, this may take a few seconds", true);
}
@Override
protected Void doInBackground(Void... params) {
// open up the database, if its the first time running the data will
// be populated
db = new SQLiteWrapper(ctx); //takes 1-10 seconds
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.d(TAG,"post execute");
loading.dismiss();
}
}
The sqlite helper class main methods look like this
public class SQLiteWrapper extends SQLiteOpenHelper {
public SQLiteWrapper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
ctx = context;
}
@SuppressWarnings("deprecation")
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
// populate our database with data from the zones file
try {
database.setLockingEnabled(false);
buildDatabase(database);
}
finally {
database.setLockingEnabled(true);
}
}
} If you're familiar with this class onCreate is only called if the
database doesn't exist.
If I manually call onCreate() within the database constructor the progress
dialog WILL show.
thoughts?
Tuesday, 10 September 2013
Return value of cell address in column to right or left of a given cell address
Return value of cell address in column to right or left of a given cell
address
I'm using the below formula to return the address of values from sheet2
that match my value in sheet1:
=ADDRESS(MATCH(C18,Sheet2!C:C,0),3)
If the returned result in sheet1 cell E19 is (sheet2)"$c$8" (and not
null), then I would like to find what value is in sheet2 "$h$8".
address
I'm using the below formula to return the address of values from sheet2
that match my value in sheet1:
=ADDRESS(MATCH(C18,Sheet2!C:C,0),3)
If the returned result in sheet1 cell E19 is (sheet2)"$c$8" (and not
null), then I would like to find what value is in sheet2 "$h$8".
jQuery: selecting first empty text input
jQuery: selecting first empty text input
Consider this HTML:
<input type="text" name="userinput[]" />
<input type="text" name="userinput[]" />
<a href="javascript:void(0);">More</a>
The intent here is for users to input values into the form fields and,
should they want more fields, clicking the link will execute this jQuery:
$('a').click( function(e) {
e.preventDefault();
$(this).before('<input type="text" name="team_names[]" />');
//refocus on the first empty input
$('input[value=""]:first').focus();
});
So "User A" fills in the two form fields, clicks the "More" link, two more
input fields are added and the browser focuses on the third overall field
(due to it being the first empty field). Unfortunately, the code selects
the first overall field. I can make it focus on the last input field... no
problem... but if the user clicks "More" multiple times before filling in
additional fields, I still want to focus on the first empty field.
What am I missing?
http://jsfiddle.net/TYjNE/1/
Consider this HTML:
<input type="text" name="userinput[]" />
<input type="text" name="userinput[]" />
<a href="javascript:void(0);">More</a>
The intent here is for users to input values into the form fields and,
should they want more fields, clicking the link will execute this jQuery:
$('a').click( function(e) {
e.preventDefault();
$(this).before('<input type="text" name="team_names[]" />');
//refocus on the first empty input
$('input[value=""]:first').focus();
});
So "User A" fills in the two form fields, clicks the "More" link, two more
input fields are added and the browser focuses on the third overall field
(due to it being the first empty field). Unfortunately, the code selects
the first overall field. I can make it focus on the last input field... no
problem... but if the user clicks "More" multiple times before filling in
additional fields, I still want to focus on the first empty field.
What am I missing?
http://jsfiddle.net/TYjNE/1/
How to apply H*p + t homography in matlab
How to apply H*p + t homography in matlab
I'm working on a project in computer vision in MATLAB and I have to apply
a special homography that looks like that : H1*(H2*p + t1).
H1, H2 - 3x3 matrix
T1 - 3x1 vector
p - is the image homogeneous coordinates of an image (3x1 vector)
Regular homography looks like H*p. I know how to apply those homographis
but all the functions in MATLAB that I have found wont work on this
special case. If someone knows how to do it I'll be very happy to read it.
Thanks.
I'm working on a project in computer vision in MATLAB and I have to apply
a special homography that looks like that : H1*(H2*p + t1).
H1, H2 - 3x3 matrix
T1 - 3x1 vector
p - is the image homogeneous coordinates of an image (3x1 vector)
Regular homography looks like H*p. I know how to apply those homographis
but all the functions in MATLAB that I have found wont work on this
special case. If someone knows how to do it I'll be very happy to read it.
Thanks.
Automate upload to an FTP
Automate upload to an FTP
Every day (7days/week) my job requires me to access a FTP an upload a
file. Some days I need a day off and would like to automate this process.
I know I could setup my FTP client to do the upload but would prefer not
to rely on a computer, power, internet connectivity etc.
I do some web development work and know PHP, JS and HTML. I also have
access to hosting where I could put some php or js to do the job.
Any suggestions on how to automate these tasks?
Every day (7days/week) my job requires me to access a FTP an upload a
file. Some days I need a day off and would like to automate this process.
I know I could setup my FTP client to do the upload but would prefer not
to rely on a computer, power, internet connectivity etc.
I do some web development work and know PHP, JS and HTML. I also have
access to hosting where I could put some php or js to do the job.
Any suggestions on how to automate these tasks?
Responsive design (issues with the alignment when resizing browser)
Responsive design (issues with the alignment when resizing browser)
First of all, if this is inappropiate I apologize. However I searched, and
searched and I don't have a clue on how to solve this. I have to mention
that I'm kinda new to this.
So, I was messing around a bit in order to understand the responsive idea
better. Now the issue:
The website looks good if I check the screen resolutions on
http://quirktools.com/screenfly/ but if I try to open the site in my
browser and play around with the window, resizing it, some elements are
not aligned well.
I put the files online so you can check it yourself
http://stilbarbatesc.ro/test3
You can see there is a problem with the tables when resizing the browser
window.
Hopefully I can get some help on this, and sorry if the question is
inappropiate.
Thanks
First of all, if this is inappropiate I apologize. However I searched, and
searched and I don't have a clue on how to solve this. I have to mention
that I'm kinda new to this.
So, I was messing around a bit in order to understand the responsive idea
better. Now the issue:
The website looks good if I check the screen resolutions on
http://quirktools.com/screenfly/ but if I try to open the site in my
browser and play around with the window, resizing it, some elements are
not aligned well.
I put the files online so you can check it yourself
http://stilbarbatesc.ro/test3
You can see there is a problem with the tables when resizing the browser
window.
Hopefully I can get some help on this, and sorry if the question is
inappropiate.
Thanks
Structuring a program for Data Collection
Structuring a program for Data Collection
As part of a wider project, I'm required to use the Twitter Rest API to
collect data about a user's network, so that their network may later be
graphed in 3D space.
Previously, I had no thought invested in the rate limits, and made a
Javascript program to (through codebird.js) grab the user's twitter id,
find their friends and followers ids, and recurse outward, expanding the
network in local runtime memory.
This fell short of collecting anything close to a reasonable network
depth, due to the very restricting rate limits on the API calls Twitter
imposes (15 calls per 15 minutes! That's 1 user added to my network model
a second).
Twitter API 1.1 Rate Limits
I decided I'd have to collect the user data over time (before the user
tries to graph their network), on a remote server (so that the user
doesn't have to wait for their data to be collected; that could take
hours), using PHP and a MySQL database.
After developing a database model and local cache models, I've hit a few
more snags;
My model requires asynchronous, periodic serving of queues (sending data
between the client and API, avoiding the rate limits), which is fairly
difficult (I'm running my script on a free web host with which I can't
configure pthread) in PHP.
My model requires huge execution times for the PHP script (hours) to wait
for the rate limits, but my webhost will terminate my script after 15s
My current model is (very simply):
userQueue = []
friendsQueue = []
followersQueue = []
registerUser(user):
userQueue.add(user)
friendsQueue.add(user)
followersQueue.add(user)
serveUserQueue():
serve the first 100 elements of userQueue, and send to the API as one
batch
add the API responses to the database
serveFriendsQueue():
serve the first friendsQueue element, and send to the API
for every user in the API response list:
add database link between the sent user and the iterated user
registerUser(user)
serveFollowersQueue():
serve the first followersQueue element, and send to the API
for every user in the API response list:
add database link between the sent user and the iterated user
registerUser(user)
// if only this were possible
call every 12 minutes (serveUserQueue())
call every 1 minute (serveFriendsQueue())
call every 1 minute (serveFollowersQueue())
Note this is a very very very simplified version, and removes all the
recursive base-case approaching and data-repetition prevention, but it
shows you the general algorithm and need for asynchronous calls.
It's been problem after problem on this project, and I feel like I'm
making no progress in what should be a very simple interaction with the
Twitter API.
Help?!
How should I approach this? Should I restructure my code, or my entire
approach?
Should I develop a completely PHP friendly solution (strictly consecutive
execution - I currently just don't see how I can do this)?
I feel like 'cron jobs' are going to be a tempting but inappropriate
answer, since I lose all stage of my recursive execution when the script
ends (and I'd really like an elegant solution).
Any direction / advice at all is appreciated.
Thanks!
As part of a wider project, I'm required to use the Twitter Rest API to
collect data about a user's network, so that their network may later be
graphed in 3D space.
Previously, I had no thought invested in the rate limits, and made a
Javascript program to (through codebird.js) grab the user's twitter id,
find their friends and followers ids, and recurse outward, expanding the
network in local runtime memory.
This fell short of collecting anything close to a reasonable network
depth, due to the very restricting rate limits on the API calls Twitter
imposes (15 calls per 15 minutes! That's 1 user added to my network model
a second).
Twitter API 1.1 Rate Limits
I decided I'd have to collect the user data over time (before the user
tries to graph their network), on a remote server (so that the user
doesn't have to wait for their data to be collected; that could take
hours), using PHP and a MySQL database.
After developing a database model and local cache models, I've hit a few
more snags;
My model requires asynchronous, periodic serving of queues (sending data
between the client and API, avoiding the rate limits), which is fairly
difficult (I'm running my script on a free web host with which I can't
configure pthread) in PHP.
My model requires huge execution times for the PHP script (hours) to wait
for the rate limits, but my webhost will terminate my script after 15s
My current model is (very simply):
userQueue = []
friendsQueue = []
followersQueue = []
registerUser(user):
userQueue.add(user)
friendsQueue.add(user)
followersQueue.add(user)
serveUserQueue():
serve the first 100 elements of userQueue, and send to the API as one
batch
add the API responses to the database
serveFriendsQueue():
serve the first friendsQueue element, and send to the API
for every user in the API response list:
add database link between the sent user and the iterated user
registerUser(user)
serveFollowersQueue():
serve the first followersQueue element, and send to the API
for every user in the API response list:
add database link between the sent user and the iterated user
registerUser(user)
// if only this were possible
call every 12 minutes (serveUserQueue())
call every 1 minute (serveFriendsQueue())
call every 1 minute (serveFollowersQueue())
Note this is a very very very simplified version, and removes all the
recursive base-case approaching and data-repetition prevention, but it
shows you the general algorithm and need for asynchronous calls.
It's been problem after problem on this project, and I feel like I'm
making no progress in what should be a very simple interaction with the
Twitter API.
Help?!
How should I approach this? Should I restructure my code, or my entire
approach?
Should I develop a completely PHP friendly solution (strictly consecutive
execution - I currently just don't see how I can do this)?
I feel like 'cron jobs' are going to be a tempting but inappropriate
answer, since I lose all stage of my recursive execution when the script
ends (and I'd really like an elegant solution).
Any direction / advice at all is appreciated.
Thanks!
Subscribe to:
Posts (Atom)