Tuesday, 17 September 2013

using and overloading a template member function of a base class?

using and overloading a template member function of a base class?

In the following, struct Y overloads X's member function f. Both overloads
are template functions, but take different arguments (typename and int),
to be explicitly specified:
struct X
{
template <typename> static bool f() { return true; }
};
struct Y : public X
{
using X::f;
template <int> static bool f() { return false; }
};
int main()
{
std::cout << Y::f <void>() << " " << Y::f <0>() << std::endl;
}
This prints 1 0 using gcc, as expected. However, clang (3.3) complains that
[...] error: no matching function for call to 'f'
std::cout << Y::f <void>() << " " << Y::f <0>() << std::endl;
^~~~~~~~~~~
[...] note: candidate template ignored: invalid explicitly-specified argument
for 1st template parameter
template <int> static bool f() { return false; }
^
i.e., can only see Y's version. I've tried
using X::template f;
instead, with no success. The same happens for non-static (template)
member functions. So is this a bug?

Adding callback to jquery .submit() to read error responses from uploads

Adding callback to jquery .submit() to read error responses from uploads

I've got an iframe #uploadTarget which I'm using for image uploads:
function uploadImage(){
if ($('#imageUploader').val().length > 0){
$('#uploadingIndicator').show();
// set form params such that it uploads image
$('#uploadForm').attr("action", uploadUrl);
$('#uploadForm').attr("enctype", "multipart/form-data");
$('#uploadForm').attr("target", 'uploadTarget');
// submit for image upload
$('#uploadForm').submit();
resetFormAttributes();
//console.log($('#uploadTarget').contents().find('body').text());
} else {
resetFormAttributes();
$('#uploadForm').submit();
}
}
When image upload is done, the page inside the iframe executes javascript
which calls doneUploading outside the iframe.
In the event where the file is too big or an error occurred and an error
page is displayed in the iframe, the doneUpload function is not called.
Is it possible to have some sort of a callback function that triggers
after $('#uploadForm').submit() completed (in which case I'll read the
page for error responses)?
If not, how would I read error responses being returned inside the iframe?

With a JS Regex matching exact word but not hypenated words starting with said word

With a JS Regex matching exact word but not hypenated words starting with
said word

I could not find a match to this question.
I have a string like so
var s="one two one-two one-three one one_for"
and my function is as follows
function replaceMatches( str, word )
{
var pattern=new RegExp( '\\b('+word+')\\b','g' )
return str.replace( pattern, '' )
}
the problem is if I run the function like
var problem=replaceMatches( s,'one' )
it
returns two -two -three one_four"
the function replaces every "one" like it should but treats words with a
hyphen as two words replacing the "one" before the hyphen.
My question is not about the function but about the regex. What literal
regex will match only the words "one" in my string and not "one-two" or
"one-\w"<--you know what I mean lol
basically
var pat=/\b(one)\b/g
"one one-two one".replace( pat, '')
only replace the exact match "one" and not the one in "one-two" the "one"
on the end is important to, the regex must work if the match is at the
very end Thank you, sorry if my question is relatively confusing. I am
just trying to get my learn on, and expand my personal library.

Specific PhpStorm and XAMPP configuration?

Specific PhpStorm and XAMPP configuration?

I want to move from Netbeans 7 to PhpStorm 6 (Windows7 x64) due to some
reasons but cannot arrange in the same 'netbeans' manner my configuration,
in which my source files live outside of htdocs folder of XAMPP and every
time I change sources I expect them to be immdediately uploaded to htdocs
for preview in browser at localhost. Up to this time I have seen only
those PhpStorm+XAMPP configurations, which define source folder inside of
c:\xampp\htdocs, which is not my preferred style, sorry. Articles I have
seen so far:
http://wiki.jetbrains.net/intellij/Installing_and_configuring_XAMPP ,
http://confluence.jetbrains.com/display/PhpStorm/Installing+and+Configuring+XAMPP+with+PhpStorm+IDE
, Setting up phpstorm 4 with XAMPP on Windows 7

Sunday, 15 September 2013

Prevent double submission of form using jQuery

Prevent double submission of form using jQuery

Problem:
I have a script where the user can press the keys C or M to choose an
option. Once either key is pressed the form will be submitted. Since there
is a strict rule that each option can be submitted once, some press
multiple times.
Question:
How can I prevent users from submitting the form again after they have
pressed the C or M key? I want them to be able to press either key once
the page refresh after submission.
Code in PHP / jQuery:
if (in_array($checkstring, $footer))
{
echo '
<script type="text/javascript">
$(document).ready(function()
{
$(window).keypress(function(e)
{
if (e.which == 99)
{
$("input#left").val( 1 );
$("form").submit();
}
else if (e.which == 109)
{
$("input#right").val( 1 );
$("form").submit();
}
});
'.$warning.'
});
</script>
';
}

Chess moving in Java

Chess moving in Java

for(y=0;y
grid[x][y]=new JButton(" ");
grid[x][y].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((JButton)e.getSource()).setBorder(border);;
System.out.println("Where do you want to move this piece");
}
});
grid[x][y].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent r){
grid[x][y]=grid[x][y-1];
((JButton)r.getSource()).setBorder(border);;
System.out.println("Derp");
}
});
frame.add(grid[x][y]);
}
} I want to click a piece and then when you click a different square, the
piece will move up one. I know this is wrong and I will show the legal
moves but for right now I need to get the pieces moving. Please help!!
I want e(the JButton I originally selected) to go to r(the JButton that I
selected second)

How I can make a Sqlite Database in PC for use in my app?

How I can make a Sqlite Database in PC for use in my app?

Sorry for my english, i'm trying to improve it.
Im new in the Android develpment world but i know the basics.
My question is, How I can make a Sqlite Database in my PC for use in my app?
For example: I would like to make a table whit many names, second names,
adress, and fill those field in my pc for before use that database in my
app for find my contacts, for example. I want to make something like this
for another purpose.
Where should I start?