Monday, 19 August 2013

C# Showing Buttons on taskbar thumbnails

C# Showing Buttons on taskbar thumbnails

In WMP, I have been shown buttons on the taskbar thumbnail. How can I make
them for my winforms app in C#?

KineticJS afterFrame doesn't run on loop

KineticJS afterFrame doesn't run on loop

I tried to have a reloading animation change values for my character. I
want player.shots to go up by 1 every time the animation loops. However,
it runs once and the animation continues Here is the code I have.
gun.setAnimation('reload');
gun.afterFrame(6,function(){
console.log('reload');
player.shots++;
if(player.shots > 5){
gun.setAnimation('idle');
}
}
Interestingly, if an error occurs in the function it works like expected.
gun.setAnimation('reload');
gun.afterFrame(6,function(){
console.log('reload');
player.shots++;
if(player.shots > 5){
gun.setAnimation('idle');
}
console(y) //this is an intentional error
}
This leads me to believe that afterFrame determines if it should run on
the next iteration or not based on a return value.
Is there any nice workaround or parameter I need to add, or should I just
keep intentionally causing an error to get the desired behavior?

How to make your own properties, eg. "devise :authenticable" in ruby / rails

How to make your own properties, eg. "devise :authenticable" in ruby / rails

I was wondering how I could have various properties in my models. Eg:
Property < ActiveRecord::Base
locatable, saleable ...
Would these be mixins? Or is there another way of implementing this? eg.
the way devise has:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end

Spritely div .click not working

Spritely div .click not working

I am using the JS plugin called "Spritely" to animate background images.
Everything works (backgrounds are moving). But I can't get a function to
be active when clicked on a div(sprite).
(I have the script.js, jquery and spritely included in the ).
HTML is just 2 divs (#container and #hills)
css
#container
{
width:100%;
height:100%;
margin-left:auto;
margin-right:auto;
background-image:url(clouds.jpg);
background-repeat:repeat-x;
z-index:-3;
position:absolute;
}
#hills
{
width:100%;
height:250px;
background-image:url(hills.png);
background-repeat:repeat-x;
background-position:bottom;
z-index:1;
position:absolute;
bottom:0px;
}
javascript
$(document).ready(function() {
$(hills).click(function(){
alert("hey");
});
});
var hills;
$(document).ready(function(){
var hills = document.getElementById('hills');
$(hills).pan({fps: 30, speed: 2, dir: 'left'});
});

Logic between rounding decimals to 2 digits c++

Logic between rounding decimals to 2 digits c++

I recently came across the following piece of code to display 2 decimal
digits.
val = (val*100.0)/100.0
The result was as told, but I don't get the logic behind the functioning
of it. Can anyone please explain. Thank you.

Sunday, 18 August 2013

Application Design - Validation and efficiency

Application Design - Validation and efficiency

I have an ASP.Net application which has a lot of business rules with
regards to if an object is OK to be commited to the database.
On a basic level, a person is part of a sprint, which is part of a project.
The basic rules are:
A person is assigned to a sprint, but maybe not the full duration of a
sprint (Which has a start and end date). So, when they assign the person,
his start date and end date must be between (inclusivly) the start and end
date of a sprint.
A project can have many sprints, but none can be outside of the project
start/end dates.
My solution has a UI project, Service layer, business layer and data
access layer.
I am building in the validation now, but am not sure at what level in my
app, the calidation should occur. I don't believe it's at the UI, as then
I need to duplciate the validation rules on my ASP.Net project ... maybe
my WinForms front end...
I think it should be in the busines logic, as it has business rules. So, I
was going to make a class called "Validations", and for each of my
business objects that get stored to the database, I have a method in my
Validations called "IsObjectOK", taking in the object type I want to
validate, and returning a List of errors.
So:
public List<String> IsObjectOK(SprintDto source)
{
// Do validations, and return list of errors, or NULL if none
}
An example then of a validation rule might be:
var Project = BusinessLayer.GetProject(source.ProjectId);
// check if Start/End dates fall between Project.Start and Project.End dates
If there's an issue, add it to the error list.
This seems like a good way to go. I am looking for confirmation on my
method of handling validation, and any tips and tricks? Should I not worry
about the database hits? I mean, for a sprint, there may be around 6 or 7
'rules' I need to validate, all of which may take data from different
tables. So, that's 7 database queries (Plus the connection overhead), for
a single save. (SQL Server 2012). I think that's not a worry, as it's all
confided to the Business and data layers.

python http request equivalent in node

python http request equivalent in node

I am having trouble sending post request in node.js http.request. I send
similar requests in python to same endpoint and it works.
PYTHON Request works:
def updateData (self, context, query):
params = { 'update': query, 'context' : context }
endpoint = self.getEndpointStatements(params)
headers = {
'content-type': 'application/x-www-form-urlencoded',
'accept': 'application/sparql-results+json'
}
(response, content) = httplib2.Http().request(endpoint, 'POST',
urllib.urlencode(params), headers=headers)
def getEndpointStatements (self, params):
endpoint = 'http://example.com/statements?%s" %
(urllib.urlencode(params))
return endpoint
This works
Howver, I try to create a node HTTP request, I keep getting "socket hangup
error". I upgraded to 0.10.x
var querystring = require('querystring');
var data = querystring.stringify({
update: sparqlQ
});
console.log(data)
var options = {
host: process.env['SESAME_HOST'],
port: process.env['SESAME_PORT'],
method: 'POST',
path: '/openrdf-sesame/repositories/repo/statements/',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
},
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log("body: " + chunk);
});
});
req.write(data);
req.end();
Please help me fix request in node.js. Python request works.