I am very familiar with self executing functions from working with jQuery.
(function($) { /* do stuff */ })(jQuery);
Today I was reading the backbone.js source and noticed that they do this:
(function() { /* do stuff */ }).call(this);
Is this achieving the same thing? Would the following 2 lines of code do the same thing?
(function($) { /* do stuff */ })(jQuery);
(function($) { /* do stuff */ }).call(jQuery);
I have a Win32 console program that I wrote and it works fine. The program takes input from the user and performs some calculations and displays the output - standard stuff. For fun, I am trying to get the program to work on my Fedora box but I am running into an issue with clearing cin when the user inputs something that does not match my variable type. Here is the code in question:
void CParameter::setPrincipal() {
double principal = 0.0;
cout << endl << "Please enter the loan principal: ";
cin >> principal;
while(principal <= 0)
{
if (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
}
else
{
cout << endl << "Plese enter a number greater than zero. Please try again." << endl;
cin >> principal;
}
}
m_Parameter = principal;
}
This code works in Windows. For example, if the user tries to enter a char data type (versus double) then the program informs the user of the error, resets cin, and allows the user another opportunity to enter a valid value.
When I move this code to Fedora, it compiles fine. When I run the program and enter an invalid data type, the while loop never breaks to allow the user to change the input.
My questions are; how do I clear cin when invalid data is inputted in the Fedora environment? Also, how should I write this code so it will work in both environments (Windows & Linux)?
Thanks in advance for your help!
Hello,
Im using opensource library called wxFreeChart to draw some XY charts. In example there is code which uses static array as a serie :
double data1[][2] = {
{ 10, 20, },
{ 13, 16, },
{ 7, 30, },
{ 15, 34, },
{ 25, 4, },
};
dataset-AddSerie((double *) data1, WXSIZEOF(dynamicArray));
WXSIZEOF ismacro defined like: sizeof(array)/sizeof(array[0])
In this case everything works great but in my program Im using dynamic arrays (according to users input).
I made a test and wrotecode like below:
double **dynamicArray = NULL;
dynamicArray = new double *[5] ;
for( int i = 0 ; i < 5 ; i++ )
dynamicArray[i] = new double[2];
dynamicArray [0][0] = 10;
dynamicArray [0][1] = 20;
dynamicArray [1][0] = 13;
dynamicArray [1][1] = 16;
dynamicArray [2][0] = 7;
dynamicArray [2][1] = 30;
dynamicArray [3][0] = 15;
dynamicArray [3][1] = 34;
dynamicArray [4][0] = 25;
dynamicArray [4][1] = 4;
dataset-AddSerie((double *) *dynamicArray, WXSIZEOF(dynamicArray));
But it doesnt work correctly. I mean point arent drawn. I wonder if there is any possibility that I can "cheat" that method and give it dynamic array in way it understands it and will read data from correct place
thanks for help
This is either trivial or runs counter to the philosophy of how make should be used, but I'd like to have a command line that reads as "make debug" rather than "make DEBUG=1". I tried creating a phony target called debug that did nothing except set the DEBUG variable, but then there was a difference between "make debug build" and "make build debug"--namely that in one case, the variable got set after the build happened.
Is there a way to give certain targets precedence?
Thanks for your help.
Hi
dispite some posts on this forum and others i cannot find something that tells me how to set the focus on a text box.
I have a userControl with many labels and textBoxes.When the form is loaded I want the a particular textBox to have the focus.
I have set the tabIndex but that didnt seem to work.
Any suggestions
I have a table of purchases containing a user_id and a date_of_purchase.
I need to be able to select all the users who have made 2 purchases within 12 months of each other. The dates can be any point in time as long as they are less than 12 months apart.
e.g.
user_id date_of_purchase
123 01/Jan/2010
124 01/Aug/2010
123 01/Feb/2010
124 05/Aug/2008
In this example i want user_id 123
input:
string1="this is a joke.this is not life.";
string2="this is not a joke. this is life.";
by comparing string1&string 2 we found
output:
pos8 deleted 4 chars " not"
pos28 inserted 4 chars " not"
Assume we have 3 physical servers and let's say we are only interested in performance, and not reliability. Is it better to give each server a specific function or make them all duplicates and split the traffic between them?
In other words dedicate 1 as DB server, 1 as web server, and 1 as reporting server/data warehouse, or better to put all three services on each server and use them as web farm?
I have two applications, one of which is a store and is located under the virtual directory "store", while the main "application" is the parent website/application. However, when visiting the the top-level website address, I would like to start people in /store/default.aspx (technically "/store/home") but this is not allowed in the entry box in IIS.
Currently I am doing the redirect manually in code, but was wondering if there was a way to do this in IIS or something. Thanks for any help.
I want to do following things:
If recipient address not exist in exchange ,redirect to [email protected]
If recipient address meet specific pattern , redirect to [email protected]
Thank in advance!
I know that C++ has the concept of objects but C doesn't. I also know that pretty much all there is to know about C fits into K & R but the C++ library is vastly more complex. There have got to be other big differences though.
What are the major differences between C and C++?
In my project I observed that in a FormClosed method (that handles FormClosed event)
is set MdiParent = Nothing (null).
This code makes (? no idea why) that OnLoad(method) on some child panels is raised.
Is there any sense to set MdiParent to null (Nothing) in FormClosed?
Hi,
I want to set the width and height of alert box ,i tried it by fixing the width and height but showing error ,and also i want to set the width and height as 100%
Thank's in advance
This is a past exam paper i am attempting and have no way to check if the out put is correct as i am not capable of building one of these things
the question is in the title
class Tree{
Tree left;
Tree right;
int key;
public static int span(Tree tree)
{
if ( tree == null ){
return null;
}
if( tree.left != null)
int min = span(tree.left);
}
if( tree.right != null){
int max = span(tree.right);
}
return max - min;
}
}
Could anyone suggest what i need to change to get 5/5 marks :D - the only thing we have to do is write the span method, the header was given for us
Thanks
Can any one please let me know, that, i need to fetch last 4 rows from a result-set using mysql. The result-set returns totally 6 records.
but, i need the records to be fetch from last4...i.e,
Record-3
Record-4
Record-5
Record-6
Hi,
I have been unable to find a definition that clearly explains the differences between a closure and an anonymous function.
Most references I have seen clearly specify that they are distinct "things" yet I can't seem to get my head around why.
Could someone please simplify it for me? What are the specific differences between these two language features? Which one is more appropriate in what scenarios?
I was studying the legacy API's in the Java's Collection Framework and I learnt that classes such as Vector and HashTable have been superseded by ArrayList and HashMap.
However still they are NOT deprecated, and deemed as legacy when essentially, deprecation is applied to software features that are superseded and should be avoided, so, I am not sure when is a API deemed legacy and when it is deprecated.
i wonder if there are tutorials that go through the syntax differences for ruby and python?
i have seen a comparison between ruby and php but not between ruby and python.
i have looked at both ruby and python but it would be very useful with this side-by-side comparison for deciding which one to choose.
thanks
I have a little $PATH problem: I just reinstalled MacPorts, and my path contains the MacPorts directories as it should at the beginning of $PATH. However, despite me having no such setting in my ~/.bashrc, ~/.bash_profile or ~/.profile, /Library/Frameworks/Python.framework/Versions/2.6/bin is somehow getting appended to the beginning of my $PATH:
0 07:15:11pm ~ $ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.6/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I'd like to remove it as the MacPorts version of Python is newer. This must be appended after all the above-listed files are read, but I can't think of where. There is no mention of this in /etc/profile, /etc/bashrc or /etc/paths. Any assistance would be greatly appreciated. Thanks!
The SRC and HREF attributes are used to include some external entities like an image, a CSS file, a html file, any other web page or a javascript file.
Is there a clear differentiation between SRC and HREF? where/when to use SRC or HREF? I think they can't be used interchangeably.
I'm giving below few examples where these attributes are used:
To refer a CSS file: href="cssfile.css" inside the link tag
To refer a js file: src="myscript.js" inside the script tag
To refer an image file: src="mypic.jpg" inside an image tag
To refer another webpage: href="http://www.webpage.com" inside an anchor tag