Tuesday, May 8, 2012

MATLAB: error using drawnow: Interrupt while evaluating uicontrol Callback

I have a problem with a while loop inside a switch-case statement, used together with callback functions and "drawnow". In my code, while the cases of the switch-case are determined by pushbuttons in uicontrol, the case statements involves further callback functions to track mouse movements using 'windowbuttondown/up/motionfcn's. Because I draw multiple plots inside the while loop in the case statement, however, I use 'drawnow', which gives me the following error when I run the programme:



Error on line 160 ==> drawnow
??? Interrupt while evaluating uicontrol Callback



The piece of code inside the case statement gives no error when I run independently but somehow creates problem when is integrated with the rest of the code, which I attach below. Any help would be so much appreciated. Many thanks!



function programme(selection)

if nargin == 0
selection=0
end

switch selection
case 0 %start GUI and uicontrols to set up the cases i.e programme(1), programme(2) etc
uicontrol('style','pushbutton',...
'string','First', ...
'position',[50 700 50 20], ...
'callback','programme(1);');
uicontrol('style','pushbutton',...
'string','Second', ...
'position',[150 700 50 20], ...
'callback','programme(2);');

case 1

%mouse track:
set(gcf,'windowbuttondownfcn','mousedown=1;');
set(gcf,'windowbuttonupfcn','mouseup=1;');
set(gcf,'windowbuttonmotionfcn','mousemotion=1;');

%to terminate the while loop, set up stopit=1 on one of uicontrol buttons:
uicontrol('style','pushbutton',...
'string','First', ...
'position',[50 700 50 20], ...
'callback','stopit=1;');

stopit=0;

while (stopit==0)
if mousedown==1
statements
if mouseup ==1
statements (plots)
mouseup=0;
mousedown=0;
mousedown=0;
end
end
drawnow
end

case 2
statements
otherwise
statements


end





Show a drop down list of recently entered text when clicks on an android edit box

I have to show a drop down list of recently typed texts when the user edits the text.Example is the login pages shows previously logged in users





send email from asp.net app

i configure all setting for send email using c# but when i execute than i get the following error
The requested address is not valid in its context 74.125.53.109:25



my code is



MailMessage mail = new MailMessage();
mail.To.Add("to@gmail.com");
mail.From = new MailAddress("from@gmail.com");
mail.Subject = "Test Email";

string Body = "<b>Welcome to CodeDigest.Com!!</b>";
mail.Body = Body;
mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["SMTP"];
smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);
smtp.EnableSsl = true;
smtp.Send(mail);


Web.Config



<appSettings>

<add key="SMTP" value="smtp.gmail.com"/>

<add key="FROMEMAIL" value="mail@gmail.com"/>

<add key="FROMPWD" value="password"/>

</appSettings>




RadiobuttonFor is not working for property inside a colletion (ASP.Net MVC3)

My view model looks like :



public class ShippingInfo
{
public string DiagID { get; set; }

public Collection<AddressInfo> AddressSuggestions { get; set; }
}


public class AddressInfo
{
public int ID { get; set; }
public string CompleteAddressInfo { get; set; }
}


When I am trying to bind the radio button in my view, its not rendering.



    @if (Model.AddressSuggestions != null)
{
for (int i = 0; i < Model.AddressSuggestions.Count; i++)
{
Html.RadioButtonFor(m => m.AddressSuggestions[i].CompleteAddressInfo, Model.AddressSuggestions[i].CompleteAddressInfo, false);
}
}


I am expecting my radio button selection should persist in the Model when I am posting the form (Model Binding). I would appreciate if anyone points out the problem in my code.





Android MMS Intent with with Image and body text

I am trying to create an intent that will start the MMS application for me with an image file attached and some pre-defined text present in the message body.



Thus far I've been able to accomplish either or, but not both at the same time.



Things I've tried (with their results):



sendIntent = new Intent(android.content.Intent.ACTION_SEND,Uri.parse("mms://"));
sendIntent.setType("image/gif");
sendIntent.putExtra(Intent.EXTRA_STREAM, imgStreamUri);
sendIntent.putExtra("sms_body", "HelloWorld");
startActivity(Intent.createChooser(sendIntent,"Send"));
/**********
Image file is attached but no text added to message body.
**********/

sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("image/gif");
sendIntent.putExtra(Intent.EXTRA_STREAM, imgStreamUri);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "HelloWorld");
sendIntent.putExtra(Intent.EXTRA_TITLE, "WorldHello");
startActivity(Intent.createChooser(sendIntent,"Send"));
/**********
Image file is attached but no text added to message body(or subject or anything).
**********/


Does anyone know how I can attach both body text and an image file to an mms intent that will launch the default messaging application with the appropriate items filled in?



EDIT: Tested the code @lenik provided in answer. It is working on some devices, here's what I found



Works correctly:




  • Epic 4g (Galaxy S)

  • Epic 4g Touch (Galaxy S II)

  • Galaxy Nexus(ICS 4.0.4)

  • HTC Desire (Froyo 2.2)

  • Motorola Photon



Image attached but no text:




  • Sidekick 4g

  • Samsung Transform Ultra



Anyone know if I am basically s.o.l. on the devices that don't work properly this way?





MATLAB: error using drawnow: Interrupt while evaluating uicontrol Callback

I have a problem with a while loop inside a switch-case statement, used together with callback functions and "drawnow". In my code, while the cases of the switch-case are determined by pushbuttons in uicontrol, the case statements involves further callback functions to track mouse movements using 'windowbuttondown/up/motionfcn's. Because I draw multiple plots inside the while loop in the case statement, however, I use 'drawnow', which gives me the following error when I run the programme:



Error on line 160 ==> drawnow
??? Interrupt while evaluating uicontrol Callback



The piece of code inside the case statement gives no error when I run independently but somehow creates problem when is integrated with the rest of the code, which I attach below. Any help would be so much appreciated. Many thanks!



function programme(selection)

if nargin == 0
selection=0
end

switch selection
case 0 %start GUI and uicontrols to set up the cases i.e programme(1), programme(2) etc
uicontrol('style','pushbutton',...
'string','First', ...
'position',[50 700 50 20], ...
'callback','programme(1);');
uicontrol('style','pushbutton',...
'string','Second', ...
'position',[150 700 50 20], ...
'callback','programme(2);');

case 1

%mouse track:
set(gcf,'windowbuttondownfcn','mousedown=1;');
set(gcf,'windowbuttonupfcn','mouseup=1;');
set(gcf,'windowbuttonmotionfcn','mousemotion=1;');

%to terminate the while loop, set up stopit=1 on one of uicontrol buttons:
uicontrol('style','pushbutton',...
'string','First', ...
'position',[50 700 50 20], ...
'callback','stopit=1;');

stopit=0;

while (stopit==0)
if mousedown==1
statements
if mouseup ==1
statements (plots)
mouseup=0;
mousedown=0;
mousedown=0;
end
end
drawnow
end

case 2
statements
otherwise
statements


end





Is this a higher kinded type in Scala?

Having following definition



type MyMap = Map[String, List[Map[Int, String]]] 


Can Map be defined as a higher kinded type ?





SVN Merge Between Sibling Branches

In SVN I have two branches, 1.0 and 2.0. If I fix an issue in 1.0, how do I merge that fix into 2.0 and vice versa?



Consider the following scenario:




  1. I make a fix on the 1.0 branch and it creates a new file A (rev X).

  2. I do a plain merge with just that fix from 1.0 to 2.0 (rev X+1)

  3. I then make a fix on the 2.0 branch and it modifies A (rev Y).

  4. If I merge that fix back to 1.0 I get a merge conflict!



I suppose I can always force that fixes are made on the 1.0 branch first or I could manually block the X+1 revision on the 1.0 branch. Both of these are non-ideal and I was wondering if there were a better way to handle sibling branches.





SVN Merge Between Sibling Branches

In SVN I have two branches, 1.0 and 2.0. If I fix an issue in 1.0, how do I merge that fix into 2.0 and vice versa?



Consider the following scenario:




  1. I make a fix on the 1.0 branch and it creates a new file A (rev X).

  2. I do a plain merge with just that fix from 1.0 to 2.0 (rev X+1)

  3. I then make a fix on the 2.0 branch and it modifies A (rev Y).

  4. If I merge that fix back to 1.0 I get a merge conflict!



I suppose I can always force that fixes are made on the 1.0 branch first or I could manually block the X+1 revision on the 1.0 branch. Both of these are non-ideal and I was wondering if there were a better way to handle sibling branches.





Variable Return Type of a Method in C#

I want to give a parameter to a method and i want my method to return data by looking the parameter. Data can be in type of boolean, string, int or etc. How can i return a variable type from a method? I don't want to return an object type and then cast it to another type. For example:



BlaBla VariableReturnExampleMethod(int a)
{
if (a == 1)
return "Demo";
else if (a == 2)
return 2;
else if (a == 3)
return True;
else
return null;
}


The reason why i want that is i have a method that reads a selected column of a row from the database. Types of columns are not same but i have to return every column's information.





How to correctly use static files in bottle templates?

I am able to download the css file mentioned in my template, but the page renders as if the browser was unable to access the stylesheet.



Here is my directory structure:



/myapp
myapp.py
bottle.py
views
template.tpl
styles
main.css


here is the relevant line from the template:



<link rel="stylesheet" type="text/css" href="main.css" />


and I have this in myapp.py



from bottle import route, run, debug, template, error, static_file


@route('/styles/<filename>')
def send_css(filename):
return static_file(filename, root='styles')

@route('/')
def index():
return template('template')

debug(True)
run(host='localhost', port=8080, reloader=True)




Session stickiness on Amazon Web Services

I'm a bit confused about the use of the session stickiness on Amazon Web Services. When I deploy my java web application using Amazon Elastic Beanstalk, I can choose to enable the session stickiness and then specify a cookie expiration period.



My application uses cookies for the session (JSESSIONID) as well as for other small things. Most of the website is accessible only after logging in (I use Spring security to manage it). The website will run on up to 25 small EC2 instances.



Should I enable the session stickiness? If I don't enable it, does it mean that I could be suddendly logged out because the load balancer took me to another server (not the server that authenticated me)? Basically, why and when should I use session stickiness?



Thank you very much.





Variable Return Type of a Method in C#

I want to give a parameter to a method and i want my method to return data by looking the parameter. Data can be in type of boolean, string, int or etc. How can i return a variable type from a method? I don't want to return an object type and then cast it to another type. For example:



BlaBla VariableReturnExampleMethod(int a)
{
if (a == 1)
return "Demo";
else if (a == 2)
return 2;
else if (a == 3)
return True;
else
return null;
}


The reason why i want that is i have a method that reads a selected column of a row from the database. Types of columns are not same but i have to return every column's information.





send email from asp.net app

i configure all setting for send email using c# but when i execute than i get the following error
The requested address is not valid in its context 74.125.53.109:25



my code is



MailMessage mail = new MailMessage();
mail.To.Add("to@gmail.com");
mail.From = new MailAddress("from@gmail.com");
mail.Subject = "Test Email";

string Body = "<b>Welcome to CodeDigest.Com!!</b>";
mail.Body = Body;
mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["SMTP"];
smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);
smtp.EnableSsl = true;
smtp.Send(mail);


Web.Config



<appSettings>

<add key="SMTP" value="smtp.gmail.com"/>

<add key="FROMEMAIL" value="mail@gmail.com"/>

<add key="FROMPWD" value="password"/>

</appSettings>




Session stickiness on Amazon Web Services

I'm a bit confused about the use of the session stickiness on Amazon Web Services. When I deploy my java web application using Amazon Elastic Beanstalk, I can choose to enable the session stickiness and then specify a cookie expiration period.



My application uses cookies for the session (JSESSIONID) as well as for other small things. Most of the website is accessible only after logging in (I use Spring security to manage it). The website will run on up to 25 small EC2 instances.



Should I enable the session stickiness? If I don't enable it, does it mean that I could be suddendly logged out because the load balancer took me to another server (not the server that authenticated me)? Basically, why and when should I use session stickiness?



Thank you very much.





Can the synchronous file system api be used in a chrome extension

I'm creating page action popup in google extensions. I need to write contents back to a file when the popup gets closed. For this I have attached the window.unload event. In the unload handler I'm trying to write to the file. But since I'm using the asynchronous api, immediately after setting the successHandler for the getFile function, the page gets closed and the successHandler does not get executed. Can I use the synchronous file api here? I read that the synchronous apis can be used only with webworkers. Can it be used in extensions? Or is there some other way to deal with this situation. I'm pasting my code for the writing to the file here



fileSystem.root.getFile(fileName, {create : true, exclusive : true}, function (fileEntry) {
file.createWriter(function() {
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder;
var bb = new BlobBuilder();
bb.append(JSON.stringify(credentialsObj));
fileWriter.write(bb.getBlob('text/plain'));
}, errorHandler);
}, errorHandler);




Can the synchronous file system api be used in a chrome extension

I'm creating page action popup in google extensions. I need to write contents back to a file when the popup gets closed. For this I have attached the window.unload event. In the unload handler I'm trying to write to the file. But since I'm using the asynchronous api, immediately after setting the successHandler for the getFile function, the page gets closed and the successHandler does not get executed. Can I use the synchronous file api here? I read that the synchronous apis can be used only with webworkers. Can it be used in extensions? Or is there some other way to deal with this situation. I'm pasting my code for the writing to the file here



fileSystem.root.getFile(fileName, {create : true, exclusive : true}, function (fileEntry) {
file.createWriter(function() {
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder;
var bb = new BlobBuilder();
bb.append(JSON.stringify(credentialsObj));
fileWriter.write(bb.getBlob('text/plain'));
}, errorHandler);
}, errorHandler);




Variable Return Type of a Method in C#

I want to give a parameter to a method and i want my method to return data by looking the parameter. Data can be in type of boolean, string, int or etc. How can i return a variable type from a method? I don't want to return an object type and then cast it to another type. For example:



BlaBla VariableReturnExampleMethod(int a)
{
if (a == 1)
return "Demo";
else if (a == 2)
return 2;
else if (a == 3)
return True;
else
return null;
}


The reason why i want that is i have a method that reads a selected column of a row from the database. Types of columns are not same but i have to return every column's information.





Session stickiness on Amazon Web Services

I'm a bit confused about the use of the session stickiness on Amazon Web Services. When I deploy my java web application using Amazon Elastic Beanstalk, I can choose to enable the session stickiness and then specify a cookie expiration period.



My application uses cookies for the session (JSESSIONID) as well as for other small things. Most of the website is accessible only after logging in (I use Spring security to manage it). The website will run on up to 25 small EC2 instances.



Should I enable the session stickiness? If I don't enable it, does it mean that I could be suddendly logged out because the load balancer took me to another server (not the server that authenticated me)? Basically, why and when should I use session stickiness?



Thank you very much.





Can the synchronous file system api be used in a chrome extension

I'm creating page action popup in google extensions. I need to write contents back to a file when the popup gets closed. For this I have attached the window.unload event. In the unload handler I'm trying to write to the file. But since I'm using the asynchronous api, immediately after setting the successHandler for the getFile function, the page gets closed and the successHandler does not get executed. Can I use the synchronous file api here? I read that the synchronous apis can be used only with webworkers. Can it be used in extensions? Or is there some other way to deal with this situation. I'm pasting my code for the writing to the file here



fileSystem.root.getFile(fileName, {create : true, exclusive : true}, function (fileEntry) {
file.createWriter(function() {
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder;
var bb = new BlobBuilder();
bb.append(JSON.stringify(credentialsObj));
fileWriter.write(bb.getBlob('text/plain'));
}, errorHandler);
}, errorHandler);




map in a JFrame using url

I'm trying to add a google-map in my frame, I read here that the best way is opening an URL, so, I did:



    JTextPane myMap = new JTextPane();
JScrollPane scroll = new JScrollPane();
scroll.getViewport().add(myMap);


scroll.setBounds(40,240,1200,644);
background.add(scroll);

try{
URL url = getClass().getResource("/html/maps.html");

myMap.setPage(url);
} catch (Exception e) {
e.printStackTrace();
}


But I see nothing, if I use helloWorld.html instead of maps.htm I see the content.



Why is it happening?



Thank you in advance





map in a JFrame using url

I'm trying to add a google-map in my frame, I read here that the best way is opening an URL, so, I did:



    JTextPane myMap = new JTextPane();
JScrollPane scroll = new JScrollPane();
scroll.getViewport().add(myMap);


scroll.setBounds(40,240,1200,644);
background.add(scroll);

try{
URL url = getClass().getResource("/html/maps.html");

myMap.setPage(url);
} catch (Exception e) {
e.printStackTrace();
}


But I see nothing, if I use helloWorld.html instead of maps.htm I see the content.



Why is it happening?



Thank you in advance





Ant: How to compare timestamps?

In a long running Ant script, I have a target that gets called roughly once per second. (This is probably not a good thing, but let's accept it for the moment.)

I only want it to execute if its last actual execution was at least five minutes ago.



One idea for a solution is to maintain a lastRunTimestamp property, and compare the current time to that.



Problem: How can I compare timestamps in Ant?



Another solution that would also be welcome is a means of executing the target only at specified time intervals, so that the check would not be necessary.



I am using Ant 1.7.1 and ant-contrib.



Any ideas are greatly appreciated - thanks!





Ant: How to compare timestamps?

In a long running Ant script, I have a target that gets called roughly once per second. (This is probably not a good thing, but let's accept it for the moment.)

I only want it to execute if its last actual execution was at least five minutes ago.



One idea for a solution is to maintain a lastRunTimestamp property, and compare the current time to that.



Problem: How can I compare timestamps in Ant?



Another solution that would also be welcome is a means of executing the target only at specified time intervals, so that the check would not be necessary.



I am using Ant 1.7.1 and ant-contrib.



Any ideas are greatly appreciated - thanks!





Problems with Jira gadget configuration screen

I keep running in to strange issues when writing gadgets for Jira. I get problems like the options being clipped out of view, reconfiguration not working and most annoyingly: projectOrFilterPicker not working.



Most of the weird issues I run in to I can work around which is what I've done however I need to allow the user to use that quick search box for selecting a project or a filter. However, as soon as I include one of these dialog boxes the gadget just loads endlessly and if I resize the screen (one of the workarounds I use for other things) I get an error 500.



A weird thing is that it works locally on the Atlassian SDK test Jira (V 4.4) but not on my workplaces full test server (V 2.1.3).



This is some of the code I'm using and I can post more if necessary:



var projectPicker = AJS.gadget.fields.projectOrFilterPicker(gadget, "projectId", args.projectOptions);


args.projectOptions are defined here:



args: function()
{

return [
{
key: "projectOptions",
ajaxOptions: "/rest/gadget/1.0/filtersAndProjects"
}
];
}()


Any insight/suggestions would be greatly appreciated. Thanks in advance.



Carl





Problems with Jira gadget configuration screen

I keep running in to strange issues when writing gadgets for Jira. I get problems like the options being clipped out of view, reconfiguration not working and most annoyingly: projectOrFilterPicker not working.



Most of the weird issues I run in to I can work around which is what I've done however I need to allow the user to use that quick search box for selecting a project or a filter. However, as soon as I include one of these dialog boxes the gadget just loads endlessly and if I resize the screen (one of the workarounds I use for other things) I get an error 500.



A weird thing is that it works locally on the Atlassian SDK test Jira (V 4.4) but not on my workplaces full test server (V 2.1.3).



This is some of the code I'm using and I can post more if necessary:



var projectPicker = AJS.gadget.fields.projectOrFilterPicker(gadget, "projectId", args.projectOptions);


args.projectOptions are defined here:



args: function()
{

return [
{
key: "projectOptions",
ajaxOptions: "/rest/gadget/1.0/filtersAndProjects"
}
];
}()


Any insight/suggestions would be greatly appreciated. Thanks in advance.



Carl





Ant: How to compare timestamps?

In a long running Ant script, I have a target that gets called roughly once per second. (This is probably not a good thing, but let's accept it for the moment.)

I only want it to execute if its last actual execution was at least five minutes ago.



One idea for a solution is to maintain a lastRunTimestamp property, and compare the current time to that.



Problem: How can I compare timestamps in Ant?



Another solution that would also be welcome is a means of executing the target only at specified time intervals, so that the check would not be necessary.



I am using Ant 1.7.1 and ant-contrib.



Any ideas are greatly appreciated - thanks!





Problems with Jira gadget configuration screen

I keep running in to strange issues when writing gadgets for Jira. I get problems like the options being clipped out of view, reconfiguration not working and most annoyingly: projectOrFilterPicker not working.



Most of the weird issues I run in to I can work around which is what I've done however I need to allow the user to use that quick search box for selecting a project or a filter. However, as soon as I include one of these dialog boxes the gadget just loads endlessly and if I resize the screen (one of the workarounds I use for other things) I get an error 500.



A weird thing is that it works locally on the Atlassian SDK test Jira (V 4.4) but not on my workplaces full test server (V 2.1.3).



This is some of the code I'm using and I can post more if necessary:



var projectPicker = AJS.gadget.fields.projectOrFilterPicker(gadget, "projectId", args.projectOptions);


args.projectOptions are defined here:



args: function()
{

return [
{
key: "projectOptions",
ajaxOptions: "/rest/gadget/1.0/filtersAndProjects"
}
];
}()


Any insight/suggestions would be greatly appreciated. Thanks in advance.



Carl





SVN Merge Between Sibling Branches

In SVN I have two branches, 1.0 and 2.0. If I fix an issue in 1.0, how do I merge that fix into 2.0 and vice versa?



Consider the following scenario:




  1. I make a fix on the 1.0 branch and it creates a new file A (rev X).

  2. I do a plain merge with just that fix from 1.0 to 2.0 (rev X+1)

  3. I then make a fix on the 2.0 branch and it modifies A (rev Y).

  4. If I merge that fix back to 1.0 I get a merge conflict!



I suppose I can always force that fixes are made on the 1.0 branch first or I could manually block the X+1 revision on the 1.0 branch. Both of these are non-ideal and I was wondering if there were a better way to handle sibling branches.





map in a JFrame using url

I'm trying to add a google-map in my frame, I read here that the best way is opening an URL, so, I did:



    JTextPane myMap = new JTextPane();
JScrollPane scroll = new JScrollPane();
scroll.getViewport().add(myMap);


scroll.setBounds(40,240,1200,644);
background.add(scroll);

try{
URL url = getClass().getResource("/html/maps.html");

myMap.setPage(url);
} catch (Exception e) {
e.printStackTrace();
}


But I see nothing, if I use helloWorld.html instead of maps.htm I see the content.



Why is it happening?



Thank you in advance