Saturday, 24 August 2013

Calling Jquery function from .Net, with parameters

Calling Jquery function from .Net, with parameters

I have a .Net method which does some validation on an object, and then, I
need to display the issues to the user.
I am trying to use a jquery message box I found:
The jquery function:
function ShowPopup() {
$.msgBox({
title: "Unable to save",
content: "An error has occured while saving the object."
});
}
I need to call that from a .Net method, passing it a List of strings. Is
that possible? And then set the content property to be the list of errors?
My .Net saving method, which may trigger this popup, looks like this:
protected void btnSave_Click(object sender, EventArgs e)
{
var o = new UserDto
{
DisplayName = txtName.Text,
Email = txtEmail.Text,
Username = txtUsername.Text,
Password = txtPassword.Text,
TimeZoneId = ddZones.SelectedValue,
Id = Session["SelectedUserId"] == null ? 0 :
int.Parse(Session["SelectedUserId"].ToString())
};
var result = new UserService(Common.CurrentUserId()).SaveUser(o);
if (result.Success == false)
{
// Show an error.
return;
}
Response.Redirect("users.aspx");
}
If, if success is false, I want to pass it a list of errors, and show that
popup.
The jquery function is from here.

How to use xcasset

How to use xcasset

I started developing for ios 7 with xcode 5 and I want to use xcassets for
my images. The problem is, when I try to set the image for my
navigationBar it doesnt work. I tried the folowing :
[self.navigationController.navigationBar setBackgroundImage:[UIImage
imageNamed:@"navigationBar.png"] forBarMetrics:UIBarMetricsDefault]; but
it didnt set it to anything. What is the method for setting images with
xcassets?

What are the consequences of omitting @autoreleasepool { } in main()?

What are the consequences of omitting @autoreleasepool { } in main()?

What are the practical consequences of omitting @autoreleasepool { ... }
in main() of a command line program?
These two pieces of code compile and seem to work equivalently:
1.
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"Hello, World!");
}
return 0;
}
2.
int main(int argc, const char * argv[])
{
NSLog(@"Hello, World!");
return 0;
}
I suspect that the theoretical consequences are that the second version
can leak memory. I want to know why.

code for how to send username and password to their email in ios after registering account

code for how to send username and password to their email in ios after
registering account

IN .xib file i will have
First Name :----------- Last Name :------------ email id :------------
pincode :------------
-----------------
register button
-----------------
After clicking registration button the user name and password should be
send to the given email id in the form.
I need code for this please.

Best way to implement Kleen star (closure) operation in C or C++?

Best way to implement Kleen star (closure) operation in C or C++?

Assume that I have a string "AAAB" and a pattern "A*B". How do I check
that the string matches with pattern?

Friday, 23 August 2013

Using PhantomJS in webdriver, what are ways to improve navigation in sites using JavaScript templates?

Using PhantomJS in webdriver, what are ways to improve navigation in sites
using JavaScript templates?

To start off with the simplest example, I have a Python script that uses
selenium/webdriver and includes Ghost Driver/PhantomJS() as it's
webdriver.
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("http://shaneofalltrades.com")
driver.find_element_by_id("navbar-contact").click()
print driver.current_url
driver.quit
I opted to test in this site as it is using JavaScript templating to
create new pages and happens to do the funky stuff I get errors in when
scraping other similar sites. This is my site, so I can add anything to
help debug if any ideas. So far I can use this script on some other sites
and I can process the test on shaneofalltrades using Firefox...
driver = webdriver.Firefox()
Am I missing something about using a headless webdriver or is it always
going to be more difficult? Also, because it is "headless", I take it many
UI features are missing, so maybe I need specific selectors?
The reason I would rather use phantom.js over Firefox is the speed.

ng-repeat does not seem to rebind ng-click on a re-rendering

ng-repeat does not seem to rebind ng-click on a re-rendering

I have an ng-repeat assigned to a row in a table as shown below. When the
user selects a down arrow in the row, the method moveDown gets executed,
which reorders the list (see code).
When I look at the DOM, everything looks right - The rows are reordered,
and the ng-click sees the newly assigned seqNbr.
Better explanation:
Initially first row shows data-ng-click='moveDown(0);' second
data-ng-click='moveDown(1);'
After selecting the first one, the first and second row trade places. The
seqNbr are swapped in the objects and list is reordered, then the
ng-repeate is reexecuted.
Now the DOM shows that the NEW first row has: data-ng-click='moveDown(0);'
and the old first row, now the second row, has
data-ng-click='moveDown(1);'
However if I select the new first row, what gets executed is moveDown(1)
(the old method associated with that row). Its as if the DOM is updated,
but not the method binding.
HTML:
<tr class='evidencerow' data-ng-repeat="e in data.evidence">
<td><div class='assertion webdiv' style='height:4em;'
data-ng-dblclick='openReference(e);'>
<span data-ng-bind-html-unsafe='e.assertion'></span>
</div>
</td>
<td>
<img src='img/UpArrow16x16.png' data-ng-hide='$first'
data-ng-click='moveUp({{e.seqNbr}});'
style='width:32px;'>
<img src='img/DownArrow16x16.png' data-ng-hide='$last'
data-ng-click='moveDown({{e.seqNbr}});'
style='width:32px;'>
</td>
</tr>
controller code:
$scope.moveUp = function(seq) {
var recs = $scope.data.evidence.slice(0);
recs[seq].seqNbr = seq - 1;
if (_ev.notEmpty(recs[seq - 1])) {
var s2 = seq - 1;
recs[s2].seqNbr = seq;
}
recs.sort(_ev.compareSeqNbr);
$scope.data.evidence = recs;
};
$scope.moveDown = function(seq) {
var recs = $scope.data.evidence.slice(0);
recs[seq].seqNbr = seq + 1;
if (_ev.notEmpty(recs[seq + 1])) {
var s2 = seq +1;
recs[s2].seqNbr = seq;
}
recs.sort(_ev.compareSeqNbr);
$scope.data.evidence = recs;
};
This behavior doesn't seem right to me. The result is instead of the rows
moving up and down, they toggle back and forth.