C++ Template Restriction on having a method
I want to learn whether there is a way to restrict templates such that
instances have a specific method. For example, think of a generic isLess
function which needs operator< or operator>. Is there a way to control
that?
template <Class T>
bool isLess(T first,T second){ return first < second; }
When we use this with a class not having operator< it will give an error.
How can I deal with it?
Bombaci
Thursday, 3 October 2013
Wednesday, 2 October 2013
C++ and returning a reference
C++ and returning a reference
Can any one explain to me the difference between these two functions:
int& test(int a)
{
return a;
}
and
int test(int a)
{
return a;
}
and tell me what the purpose when we use '&' operator after return type of
a function? When should we use it because I've rarely seen it before.
Can any one explain to me the difference between these two functions:
int& test(int a)
{
return a;
}
and
int test(int a)
{
return a;
}
and tell me what the purpose when we use '&' operator after return type of
a function? When should we use it because I've rarely seen it before.
Get value from string array index
Get value from string array index
I have following string [,] called School. It has values like:
[0,0] = Class1
[0,1] = Class1
[0,2] = Class1
[0,3] = Class1
[0,4] = Class2
[0,5] = Class2
[0,6] = Class3
All the Classes are in order. Like Class2 will come after Class1 and so
on. I need to know index of Class3. In above scenario it will be 6. First
part will always be 0. So i need only the second array value which is 6.
Is there easier way in C# to get that value?
I have following string [,] called School. It has values like:
[0,0] = Class1
[0,1] = Class1
[0,2] = Class1
[0,3] = Class1
[0,4] = Class2
[0,5] = Class2
[0,6] = Class3
All the Classes are in order. Like Class2 will come after Class1 and so
on. I need to know index of Class3. In above scenario it will be 6. First
part will always be 0. So i need only the second array value which is 6.
Is there easier way in C# to get that value?
Form processing in PHP
Form processing in PHP
I have three questions about some code. Heres the code and questions.
Questions:
1.How does isset($_POST['submit']) know when the submit button has been
clicked. I dont get the the mechanics behind this? 2. Why is each input
element using a name with a value of "artist[]" with the square brackets
like that? Are we defining and array inside HTML? 3. I was told that the
value of name given to an input element has to match the name given to the
$_POST variable. But in this case $_POST is using "artist" with without
the square brackets. Whats going on here?
<html>
<head></head>
<body>
<?php
// check for submit
if (!isset($_POST['submit'])) {
// and display form
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="artist[]" value="Bon Jovi">Bon Jovi
<input type="checkbox" name="artist[]" value="N'Sync">N'Sync
<input type="checkbox" name="artist" value="Boyzone">Boyzone
<input type="checkbox" name="artist" value="Britney Spears">Britney Spears
<input type="checkbox" name="artist" value="Jethro Tull">Jethro Tull
<input type="checkbox" name="artist" value="Crosby, Stills & Nash">Crosby,
Stills & Nash
<input type="submit" name="submit" value="Select">
</form>
<?php
}
else {
// or display the selected artists
// use a foreach loop to read and display array elements
if (is_array($_POST['artist'])) {
echo 'You selected: <br />';
foreach ($_POST['artist'] as $a) {
echo "<i>$a</i><br />";
}
}
else {
echo 'Nothing selected';
}
}
?>
</body>
</html>
I have three questions about some code. Heres the code and questions.
Questions:
1.How does isset($_POST['submit']) know when the submit button has been
clicked. I dont get the the mechanics behind this? 2. Why is each input
element using a name with a value of "artist[]" with the square brackets
like that? Are we defining and array inside HTML? 3. I was told that the
value of name given to an input element has to match the name given to the
$_POST variable. But in this case $_POST is using "artist" with without
the square brackets. Whats going on here?
<html>
<head></head>
<body>
<?php
// check for submit
if (!isset($_POST['submit'])) {
// and display form
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="artist[]" value="Bon Jovi">Bon Jovi
<input type="checkbox" name="artist[]" value="N'Sync">N'Sync
<input type="checkbox" name="artist" value="Boyzone">Boyzone
<input type="checkbox" name="artist" value="Britney Spears">Britney Spears
<input type="checkbox" name="artist" value="Jethro Tull">Jethro Tull
<input type="checkbox" name="artist" value="Crosby, Stills & Nash">Crosby,
Stills & Nash
<input type="submit" name="submit" value="Select">
</form>
<?php
}
else {
// or display the selected artists
// use a foreach loop to read and display array elements
if (is_array($_POST['artist'])) {
echo 'You selected: <br />';
foreach ($_POST['artist'] as $a) {
echo "<i>$a</i><br />";
}
}
else {
echo 'Nothing selected';
}
}
?>
</body>
</html>
How to disable "snap to grid" from jQuery UI draggable?
How to disable "snap to grid" from jQuery UI draggable?
Anyone know how we can disable "Snap to Grid" from jQuery UI Draggable
base on checkbox.
I m using below code to enable snap to grid dynamically.
$(".WidgetCl").draggable({containment: '#editorWindow',scroll: true, snap:
".gridCol", snapMode: "both", stop :function()
{$(this).trigger("stopdrag");}})
$(".WidgetCl").draggable("option", "grid", [ gridSize,
gridSize ]);
Thanks, Sonal
Anyone know how we can disable "Snap to Grid" from jQuery UI Draggable
base on checkbox.
I m using below code to enable snap to grid dynamically.
$(".WidgetCl").draggable({containment: '#editorWindow',scroll: true, snap:
".gridCol", snapMode: "both", stop :function()
{$(this).trigger("stopdrag");}})
$(".WidgetCl").draggable("option", "grid", [ gridSize,
gridSize ]);
Thanks, Sonal
Tuesday, 1 October 2013
SDWebImage check if UIImage get from the cache
SDWebImage check if UIImage get from the cache
I am using SDWebImage to download and cache image in the device. I would
like to show some animation after the download process but the cache
image.
Here is my code:
__weak typeof(self) weakSelf = self;
//SDWebImage Method
[self.imageView setImageWithURL:imageUrl
placeholderImage:[UIImage
imageNamed:@"imageview_placeholder.png"]
completed:^(UIImage *image, NSError *error,
SDImageCacheType cacheType) {
if (!error && image)
{
if (weakSelf.spinner) [weakSelf.spinner
removeFromSuperview];
// if downloaded from server, add animation
if (isDownloadedFromServer])
{
[weakSelf.imageView setAlpha:0.0];
[weakSelf.imageView setImage:image];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[weakSelf.imageView setAlpha:1.0];
[UIView commitAnimations];
}
else
{
[weakSelf.imageView setImage:image];
}
}
}];
Is there any way to distinguish between cache or download?
Thanks!
I am using SDWebImage to download and cache image in the device. I would
like to show some animation after the download process but the cache
image.
Here is my code:
__weak typeof(self) weakSelf = self;
//SDWebImage Method
[self.imageView setImageWithURL:imageUrl
placeholderImage:[UIImage
imageNamed:@"imageview_placeholder.png"]
completed:^(UIImage *image, NSError *error,
SDImageCacheType cacheType) {
if (!error && image)
{
if (weakSelf.spinner) [weakSelf.spinner
removeFromSuperview];
// if downloaded from server, add animation
if (isDownloadedFromServer])
{
[weakSelf.imageView setAlpha:0.0];
[weakSelf.imageView setImage:image];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[weakSelf.imageView setAlpha:1.0];
[UIView commitAnimations];
}
else
{
[weakSelf.imageView setImage:image];
}
}
}];
Is there any way to distinguish between cache or download?
Thanks!
Forcing ASP.NET WebAPI client to send a client certificate even when no CA match
Forcing ASP.NET WebAPI client to send a client certificate even when no CA
match
I have a specific application that requires the use of client certificates
for mutual authentication of HTTPS requests. The server has a flexible
certificate validation policy that allows it to accept self-signed client
certificates that are not present in the server's certificate store. This
is known to work just fine using curl as a client.
What I've determined via testing and packet sniffing is that Microsoft's
ASP.NET HttpClient tries to be overly smart during the SSL handshake. This
particular client will only use a client certificate (from the
WebRequestHandler.ClientCertificates collection) if it has chain of trust
to one of the server's trusted roots. What I've observed is that if there
are no certificates with chain of trust then the client simply won't send
a certificate at all during the handshake.
This is understandable default behavior but is overly restrictive and
there appears to be no way to turn it off. I have experimented with
various other WebRequestHandler properties, including AuthenticationLevel
and ClientCertificateOptions but to no avail.
Is there a way to force HttpClient to send a client certificate when it is
available in the ClientCertificates collection, even though it appears
that it will not validate on the server side? I'm open to both
straightforward and dirty (reflection hacks) solutions as I really need
this client to work.
match
I have a specific application that requires the use of client certificates
for mutual authentication of HTTPS requests. The server has a flexible
certificate validation policy that allows it to accept self-signed client
certificates that are not present in the server's certificate store. This
is known to work just fine using curl as a client.
What I've determined via testing and packet sniffing is that Microsoft's
ASP.NET HttpClient tries to be overly smart during the SSL handshake. This
particular client will only use a client certificate (from the
WebRequestHandler.ClientCertificates collection) if it has chain of trust
to one of the server's trusted roots. What I've observed is that if there
are no certificates with chain of trust then the client simply won't send
a certificate at all during the handshake.
This is understandable default behavior but is overly restrictive and
there appears to be no way to turn it off. I have experimented with
various other WebRequestHandler properties, including AuthenticationLevel
and ClientCertificateOptions but to no avail.
Is there a way to force HttpClient to send a client certificate when it is
available in the ClientCertificates collection, even though it appears
that it will not validate on the server side? I'm open to both
straightforward and dirty (reflection hacks) solutions as I really need
this client to work.
Subscribe to:
Comments (Atom)