Archive for May, 2009
(Portuguese) Bons desenvolvedores são preguiçosos
Sorry, this entry is only available in Portuguese.
Ajax post requests in Asp Net Mvc
I really enjoy that Asp Net Mvc gave me back the control of my Html.
Now I can easily work on nice javascript user interactions and integrate it with server side code in a very clean approach.
So let’s see how I am doing Ajax post requests in Asp Net Mvc, on the top of jQuery library.
At the master page I have a hidden input called ErrorAction, so my client-side code will know what url should be called when an error occurs in Ajax requests.
Still at the master page, we tell jQuery that by default this Error Action should be invoked when something bad occurs while executing a request.
Finally, we can work on the post requests in a safe way. And that is really easy.
Here is how it works.
<% =Html.Hidden("ErrorAction", Url.Action("Index", "Error"))%>
<script type="text/javascript">
jQuery.ajaxSetup({
error: function(XMLHttpRequest, textStatus, errorThrown)
{ window.location = $("ErrorAction").value; }
});
</script>
<% =Html.ActionLink("Update Permissions", "Permissions", null ,
new { id = "updatePermissions",
style = "visibility: hidden;",
onclick = @"jQuery.ajax(
{
url:this.href,
type:'POST',
data:
{
scrumMasters:permissionsInRole('scrumMasters'),
productOwners:permissionsInRole('productOwners'),
teamMembers:permissionsInRole('teamMembers'),
chickens:permissionsInRole('chickens')
},
complete: permissionsUpdated
}); return false;"
})%>
Project Euler Problem 1
I am starting a new topic on this blog today.
I’ll be writing some code resolving Project Euler problems.
Not all of them, sure.
Let’s begin with the first problem, a very simple one.
I tried to resolve the problem in two ways.
The first worked correctly, but there is some bug on the second approach.
The correct result is 233168.
The second way gave me 266333.
It would be cool if you can show me where is the problem on that.
Thanks to Rodrigo for the tip on this great material…
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
<p>
class EulerProblem1
def first_way
sum = 0
x = 0
while x < 1000
sum += x if (x % 3 == 0) || (x % 5 == 0)
x += 1
end
puts sum
end
def second_way
sum = 0
multiple_of_3 = 0
multiple_of_5 = 0
while multiple_of_3 < 1000 || multiple_of_5 < 1000
multiple_of_3 += 3
multiple_of_5 += 5
sum += multiple_of_3 if multiple_of_3 < 1000
sum += multiple_of_5 if multiple_of_5 < 1000
end
puts sum
end
end
solution = EulerProblem1.new
solution.first_way
solution.second_way
Thoughts on software testing
Software testing is an amazing topic.
There are several different testing approaches that can be helpul in a software lifecycle.
Acceptance tests are great for ensure you are building the right thing
They can levarage to specifications maturity, providing great aid on development guidance.
The software behavior must be specified, so why not execute theses specifications, ensuring things work well during the entire lifecycle.
Unit and integration tests are great for ensure you are building software in the right way
With great unit tests coverage, developers will enhance their engineering practices, improving code quality and providing an agile development process.
This is because you can not unit test a poorly structured software. And this is very handful.
Tests will be your best friend when changes start to appear, and we know changes happen.
There is some new requirement?
Great, all you need is some specification, so developers can implement and test it.
By the way, changes or new requirements will never break existing code, because the test base is not going to left this happen.
Testing is also a great way to improve coding skills, so if you are a software developer and you don’t know how to test your software,
this is something you should be learning right now.
So please tell me you are doing tests, or at least you intend to.
(Portuguese) Migrations em .Net
Sorry, this entry is only available in Portuguese.