Monday, 2 September 2013

Rails DB based on param

Rails DB based on param

How to specify DB connection for a specific session, based on parameter.
For example, app lives from September to September. after it's live cycle
over last year will be stored in old db, and a new db will be created for
a new live cycle. The api will work like this:
domain.com/2013/#/backbone_urls. in the place of 2013, may be stored any
year, based on what Active record will create connection with particular
db, so all queries for this user was from this db. This may be hard issue,
or wrong solution for this.

Alert Dialog comes before another Intent activity finished

Alert Dialog comes before another Intent activity finished

In the following code spinet , I want that dialog comes only after
activity (Intent) i finished its work. I searched a lot but couldn't
figure out how to do this. :( Currently, dialog popped in between when
Intent I is doing work .
Do anyone know how to allow dialog to wait until Intent i finished its work
Thanks
Intent i = new Intent(MainActivity.this,
KeyFrame.class);
i.putExtra("keyFrame", filename1+"#"+duration);
//Log.e("Mobicom: Video Name" +
MainActivity.videoDir + video_filename,
MainActivity.videoDir + video_filename);
startActivity(i);
MainActivity.this.showDialog(MainActivity.GENRE_PREFERENCE_OPTION);
Here is the full code.
@Override
public Dialog onCreateDialog(int id) {
switch (id) {
case VIDEO_OPTION_DIALOG:
Builder optionDialog = new AlertDialog.Builder(this);
optionDialog.setTitle("Options");
optionDialog.setItems(
new String[] { "Option1", "Option2", "Delete", "Cancel"},
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int
which) {
String video_filename =
MainActivity.mSelectedVideoFilename;
String filename1 = MainActivity.videoDir +
video_filename;
switch (which) {
case OPTION_PREVIEW_ID:
// preview
startActivity(new
Intent().setAction(android.content.Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(new
File(MainActivity.videoDir +
video_filename)), "video/*"));
break;
case OPTION_PREVIEW_WITH_RECOM_ID:
Intent i = new Intent(MainActivity.this,
KeyFrame.class);
i.putExtra("keyFrame",
filename1+"#"+duration);
//Log.e("Mobicom: Video Name" +
MainActivity.videoDir + video_filename,
MainActivity.videoDir + video_filename);
startActivity(i);
MainActivity.this.showDialog(MainActivity.GENRE_PREFERENCE_OPTION);
//finish();
break;
}

C#, .Net - Is Locking this instance method required

C#, .Net - Is Locking this instance method required

For the question that I have probably I need more convincing answer to
implement in my solution. I am not sure whether my understanding is
correct. Following are the implementation details:
In a class, in the main method, where the class object C is created to
call an instance method that takes integer as a parameter:
public <AnyClass> MyMethod(int classVar)
{
return new <AnyClass>(classVar);
// Can have more implementation, using the parameter passed
}
In the main, I want this method to be called on the multiple threads,
using the same class object, the parameter would be the value supplied by
for loop that starts the threads to execute. Now in memory we are
executing same method, does this needs any kind of locking. In my view No,
I have tested, but I am not sure in theory why, wouldn't different threads
mess up with each other's parameter value, in my implementation it doesn't
seems the case.
Only thing I cannot guarantee, is which thread access and returns first as
that would not be in the order, but if I do not care about it, is this
implementation correct.
Please note, this is an attempt to describe the issue in a stand alone
manner, I have similar implementation as part of a complex project.
Any suggestions / pointers would be great. Please let me know if you need
a clarification.
thanks,
Mrinal

Sunday, 1 September 2013

Automatically assigning a value to a Guid

Automatically assigning a value to a Guid

can we automatically assign a value on a Guid? like for example, i want
this to be a value of my guid: "914aaa44-4e11-e311-96f7-d8d3855b1531"
is it even possible?

why operator '=' can not match?

why operator '=' can not match?

I constantly got compilation error:
no match for 'operator=' in 'bObj1 =
Balance::operator+(Balance&)(((Balance&)(& bObj2)))'
Could you someone help to point out the reason? Thanks in advance.
code:
class Balance
{
public:
Balance (int b = 0) {balance = b;};
Balance (Balance &);
Balance & operator= (Balance &);
Balance operator+ (Balance &);
int get() {return balance;};
void set(int b) {balance = b;};
private:
int balance;
};
Balance & Balance::operator=(Balance &copy)
{
balance = copy.get();
return *this;
}
Balance Balance::operator+ (Balance &rig)
{
Balance add;
add.set(this->get() + rig.get());
return add;
}
int main()
{
Balance bObj1, bObj2(100);
bObj1 = bObj2;
bObj1 = bObj1 + bObj2; // This line cause the error.
return 0;
}

How to flow text from DIV to DIV?

How to flow text from DIV to DIV?

I have two DIVs with absolute position on two sides of a HTML page such as
(EXAMPLE)
<div class="left">
</div>
<div class="right">
</div>
with CSS
.left{
position:absolute;
left:10px;
top:10px;
width:100px;
height:100px;
background:red;
}
.right{
position:absolute;
right:10px;
top:10px;
width:100px;
height:100px;
background:blue;
}
Is there a way to add text to the left DIV and flow excess text to the
right one? I am not stuck to this two DIV, and I'm just looking for a
solution to flow excess text to another position.
NOTE: I hope to find a pure CSS solution, though, it seems to be
improbable; then, I am looking for a pure javascript solution (not using
JS libraries).

'Sign In With Google' sign in button?

'Sign In With Google' sign in button?

Is there a way around this without downloading OpenId?
I have tried the PHP version of it, but I don't fully understand how it
works.
A HTML version would be nice.
Is there a solution to this?
Thanks.