Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

Using JavaScript you can do check working jsfiddle
***
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode == 27) {
alert('Esc key pressed.');
}
};
***
Using jQuery you can do check working jsfiddle
***
jQuery(document).on('keyup',function(evt) {
if (evt.keyCode == 27) {
alert('Esc key pressed.');
}
});
***
4 years ago
You could use the ajax method:
***
$.ajax({
url: '/script.cgi',
type: 'DELETE',
success: function(result) {
// Do something with the result
}
});
***
4 years ago
Use the jQuery functions .live() and .die(). Available in jQuery 1.3.x

From the docs:

To display each paragraph's text in an alert box whenever it is clicked:
***
$("p").live("click", function(){
alert( $(this).text() );
});
***
4 years ago
In the specific case in your example, I'd use the STL algorithms to accomplish this.
***
#include

sum = std::accumulate( polygon.begin(), polygon.end(), 0 );
***
For a more general, but still fairly simple case, I'd go with:
***
#include
#include

using namespace boost::lambda;
std::for_each( polygon.begin(), polygon.end(), sum += _1 );
***
4 years ago
In C++11 you can do now:
***
class A {
private:
static constexpr const char* STRING = "some useful string constant";
};
***
4 years ago
The only other difference is the default inheritance of classes and structs, which, unsurprisingly, is private and public respectively.
4 years ago
A double is 64 and single precision (float) is 32 bits.
The double has a bigger mantissa (the integer bits of the real number).
Any inaccuracies will be smaller in the double.
4 years ago
The Boost tokenizer class can make this sort of thing quite simple:
***
#include
#include
#include
#include

using namespace std;
using namespace boost;

int main(int, char**)
{
string text = "token, test string";

char_separator sep(", ");
tokenizer< char_separator > tokens(text, sep);
BOOST_FOREACH (const string& t, tokens) {
cout << t << "." << endl;
}
}
***
Updated for C++11:
***
#include
#include
#include

using namespace std;
using namespace boost;

int main(int, char**)
{
string text = "token, test string";

char_separator sep(", ");
tokenizer> tokens(text, sep);
for (const auto& t : tokens) {
cout << t << "." << endl;
}
}
***
4 years ago
You don't have to call the external basename command. Instead, you could use the following commands:
***
$ s=/the/path/foo.txt
$ echo "${s##*/}"
foo.txt
$ s=${s##*/}
$ echo "${s%.txt}"
foo
$ echo "${s%.*}"
foo
***
Note that this solution should work in all recent (post 2004) POSIX compliant shells, (e.g. bash, dash, ksh, etc.).
4 years ago
I am a VIMer. I can do some rare Hex edits with:
***
:%!xxd to switch into hex mode

:%!xxd -r to exit from hex mode
***
But I strongly recommend ht
***
apt-cache show ht

Package: ht
Version: 2.0.18-1
Installed-Size: 1780
Maintainer: Alexander Reichle-Schmehl <tolimar@debian.org>
***
4 years ago
Print all columns:
***
awk '{print $0}' somefile
***
Print all but the first column:
***
awk '{$1=""; print $0}' somefile
***
Print all but the first two columns:
***
awk '{$1=$2=""; print $0}' somefile
***
4 years ago
Use:
***
tr -d "\r" < file
***
Take a look here for examples using sed:
***
# In a Unix environment: convert DOS newlines (CR/LF) to Unix format.
sed 's/.$//' # Assumes that all lines end with CR/LF
sed 's/^M$//' # In Bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # Works on ssed, gsed 3.02.80 or higher

# In a Unix environment: convert Unix newlines (LF) to DOS format.
sed "s/$/`echo -e \\\r`/" # Command line under ksh
sed 's/$'"/`echo \\\r`/" # Command line under bash
sed "s/$/`echo \\\r`/" # Command line under zsh
sed 's/$/\r/' # gsed 3.02.80 or higher
***
Use sed -i for in-place conversion, e.g., sed -i 's/..../' file.
4 years ago