instruction
stringlengths
0
30k
Why can't a forward declaration be used for a std::vector?
|c++|
If I create a class like so: // B.h #ifndef _B_H_ #define _B_H_ class B { private: int x; int y; }; #endif // _B_H_ and use it like this: // main.cpp #include <iostream> #include <vector> class B; // Forward declaration. class A { public: A() { std::cout << v.size() << std::endl; } private: std::vector<B> v; }; int main() { A a; } The compiler fails when compiling `main.cpp`. Now the solution I know is to `#include "B.h"`, but I'm curious as to why it fails. Neither `g++` or `cl`'s error messages were very enlightening in this matter.
Here is an implementation of Bayesian filtering in C#: [A Naive Bayesian Spam Filter for C#][1] (hosted on CodeProject). [1]: http://www.codeproject.com/KB/recipes/BayesianCS.aspx
Exceptions in C++
|c++|exception|
<p>Exceptions in C++ don't need to be catched (no compile time errors) by the calling function. So its up to developer's judgment whether to catch it using try/catch (unlike in Java). </p> <p>Is there a way one can ensure that the exceptions thrown are always caught using try/catch by the calling function?</p>
No; see [A Pragmatic Look at Exception Specifications](http://www.gotw.ca/publications/mill22.htm) for reasons why not. The only way you can "help" this is to document the exceptions your function can throw, say as a comment in the header file declaring it. This is not enforced by the compiler or anything. Use code reviews for that purpose.
**AppDomain.UnhandledException** is an **event**, not a global exception handler. This means, by the time it is raised, your application is already on its way down the drain, and there is nothing you can do about it, except for doing cleanup and error logging. What happened behind the scenes is this: The framework detected the exception, walked up the call stack to the very top, found no handlers that would recover from the error, so was unable to determine if it was safe to continue execution. So, it started the shutdown sequence, and fired up this event as a courtesy to you so you can pay your respects to your already-doomed process. This happens when an exception is left unhandled in the main thread. There is no single-point solution to this kind of error. You need to put a real exception handler (a catch block) upstream of all places where this error occurs and forward it to (for example) a global handler method/class that will determine if it is safe to simply report and continue, based on exception type and/or content. Edit: It is possible to disable (=hack) the error-reporting mechanism built into Windows so the mandatory "crash and burn" dialog does not get displayed when your app goes down. However, this becomes effective for *all* the applications in the system, not just your own.
I've just set up Sandcastle again. Try installing it (the May 2008 release) and search for SandcastleGui.exe or something similar (it's in the examples folder or so). Click Add Assembly and add your Assembly or Assemblies, add any .xml Documentation files (the ones generated by the compiler if you enabled that option) and then Build. It will take some time, but the result **will** be worth the effort. It will actually look up stuff from MSDN, so your resulting documentation will also have the Class Inheritance all the way down to System.Object with links to MSDN and stuff. Sandcastle seems a bit complicated at first, especially when you want to use it in an automated build, but I am absolutely sure it will be worth the effort. Also have a look at [Sandcastle Help File Builder][1], this is a somewhat more advanced GUI for it. [1]: http://www.codeplex.com/SHFB
<p>Follow <a href="http://saftsack.fs.uni-bayreuth.de/~dun3/archives/integrate-xml-code-comments-into-visual-studio-20052008-using-sandcastle-and-html-help-20/150.html">this simple 5 step article</a> and you are pretty much done. As a bonus you can use <a href="http://www.helpware.net/mshelp2/h2viewer.htm">H2Viewer</a> to view Html Help 2.x files.</p>
User authentication on Resin webserver
|apache|configuration|webserver|resin|caucho|
I'm currently tasked with replacing an Apache + Resin Java web server with a Resin-only configuration. Currently in our apache setup, we use .htaccess and a small user database to provide passwording at a directory level. Does anyone know the equivalent setup when using just Resin as the web server?
If it's just a few tables you could probably script this in your preferred scripting langauge and have it all done by the time it'd take to read all the replies or track down a suitable tool. I would any way. :)
The main application that my division sells does something very similar to provide client customisations (which means that I can't post any source). We have a C# application that loads dynamic VB.Net scripts (although any .Net language could be easily supported - VB was chosen because the customisation team came from an ASP background). Using .Net's CodeDom we compile the scripts from the DB, using the VB `CodeDomProvider` (annoyingly it defaults to .Net 2, if you want to support 3.5 features you need to pass a dictionary with "CompilerVersion" = "v3.5" to its ctor). Use the `CodeDomProvider.CompileAssemblyFromSource` method to compile it (you can pass settings to force it to compile in memory only. This would result in hundreds of assemblies in memory, but you could put all the dynamic classes' code together into a single assembly, and recompile the whole lot when any change. This has the advantage that you could add a flag to compile on disk with a PDB for when you're testing, allowing you to debug through the dynamic code.
We use CruiseControl with NUnit, NCover, FxCop, SVN and some custom tools we wrote ourselves to produce the reports. In my opinion it has proven (over the last few years) to be an excellent combination. It's frustrating that MS restricts *all* of its integration tools to VSTS. Its test framework is as good as NUnit, but you can't use its code coverage tools or anything else. I'd check out XNuit - it's looking pretty promising (but currently lacking UI). We automate nightly builds, and you could automate UAT and manual test builds, but I'm not sure that we'd ever want to automate the release to our production servers. Even if it were any change would be important enough that someone would have to watch over it anyway.
[This is the Firebug Lite][1] that @John was referring to that works on IE, Safari and Opera. [1]: http://getfirebug.com/lite.html "Firebug Lite"
Change the width of a scrollbar
|vb.net|
Is it possible to change the width of a scroll bar on a form. This app is for a touch screen and it is a bit too narrow.
The width of the scrollbars is controlled by Windows. Tou can adjust the scrollbar width in Display Properties and it will affect all windows on the terminal.
I will have to check-out Hoard, Google Perftools and jemalloc sometime. For now we are using scalable_malloc from Intel Threading Building Blocks and it performs well enough. For better or worse, we're using C++ on Windows, though much of our code will compile with gcc just fine. Unless there's a compelling reason to move to redhat (the main linux distro we use), I doubt it's worth the headache/political trouble to move. I would love to use Erlang, but there way to much here to redo it now. If we think about the requirements around the development of Erlang in a telco setting, the are very similar to our world (electronic trading). Armstrong's book is on my to read stack :) In my testing to scale out from 4 cores to 16 cores I've learned to appreciate the cost of any locking/contention in the parallel portion of the code. Luckily we have a large portion that scales with the data, but even that didn't work at first because of an extra lock and the memory allocator.
I believe the simple version is that they drop the server connection and replace it with the P2P connection. Something along the lines of: 1. Machine1 connects to copilot's servers. 2. Machine1 connects to copilot's servers. 3. Machine1 connects to copilot's servers. 4. Machine2 subsequently connects, and they begin screen sharing. 5. Machine2 opens a port intended for Machine1 to connect to. 6. Machine1 tries to connect to the now open port on Machine2. If this connection is established: 1. The connection to copilot's servers is severed. 2. Data is instead transfered over the direct (P2P) connection between the two machines.
There will be such a formula as soon as computers can start generating *all* code themselves. Until then you are stuck with human developers who all have different levels of skill and development speed.
In addition to what Simon said, you may want to read the [CSV how-to guide][1] and make sure your output doesn't run across any of the gotchas. To clarify something Simon said: > Then surround this by quotes if you want Fields that contain doubled up double quotes ("") will need to be completely surrounded with double quotes. There shouldn't be any harm in just wrapping all fields with double quotes, unless you specifically want the parser to strip out leading and trailing whitespace (instead of trimming it yourself). [1]: http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm
You can use JDeveloper and try to find some tutorials for it (I actually had some from my university). It integrates well with rest of Oracle stack (db and application server). Down site is that although you can download some developers editions to run for personal usage, running Oracle db + Oracle application server + JDeveloper on a machine that has less then 4GB of ram and one core is not really peasant experience.
cmd defaults to F: drive
|windows|cmd|
When I open cmd on my laptop it is defaulting to the F: drive. This is troubling me does anyone know how it got that way or how to get it back to where it opens to the C: drive by default?
In terms of allocations, it'd be better to look at [this blogpost][1]. It shows in exactly in what circumstances an enumerator is allocated on the heap. [1]: http://blogs.msdn.com/etayrien/archive/2007/03/17/foreach-garbage-and-the-clr-profiler.aspx
quick answer: cmd /k c: long answer to make it "automagical": <http://windowsxp.mvps.org/autoruncmd.htm>
There's no set formula out there that I've seen that would really work. Fogbugz has its monte carlo simulator which has somewhat of a concept for this, but really, experience is going to be your best point of reference. Every developer and every project will be different!
[http://blog.stevienova.com/2007/04/08/change-your-default-cmd-prompt-path/][1] [1]: http://blog.stevienova.com/2007/04/08/change-your-default-cmd-prompt-path/
Generally those variables are stored in the program's memory space, which you should (theoretically) should not be able to access. You'll need to find out how to initiate interprocess communication with the other instances and trade data. Named pipes are one good option, but you might want to start a new stackoverflow question to get good options on this. -Adam
The latest Sun Java VM actually have multiple GC algorithms which you can tweak. The Java VM specifications intentionally omitted specifying actual GC behaviour to allow different (and multiple) GC algorithms for different VMs. For example, for all the people who dislike the "stop-the-world" approach of the default Sun Java VM GC behaviour, there are VM such as [IBM's WebSphere Real Time][1] which allows real-time application to run on Java. Since the Java VM spec is publicly available, there is (theoretically) nothing stopping anyone from implementing a Java VM that uses CPython's GC algorithm. [1]: http://www-01.ibm.com/software/webservers/realtime/
If you need to take the curvature of the earth into account, the Great-Circle distance is what you're looking for. The Wikipedia [article][1] probably does a better job of explaining how the formula works than me, and there's also [this][2] aviation formulary page that covers this in detail. The formulas are only the first part of the puzzle though, if you need to make this work for arbitrary cities, you'll need a location database to get the lat/long from. Luckily you can get this for free from [Geonames.org][3], although there are commercial db's available (ask google). Last but not least, Joel wrote an article about this problem a while back, so here you go:[link text][4] [1]: http://en.wikipedia.org/wiki/Great-circle_distance [2]: http://williams.best.vwh.net/avform.htm [3]: http://www.geonames.org/ [4]: http://www.joelonsoftware.com/oldnews/pages/October2006.html
If you need to take the curvature of the earth into account, the Great-Circle distance is what you're looking for. The Wikipedia [article][1] probably does a better job of explaining how the formula works than me, and there's also [this][2] aviation formulary page that covers that goes into more detail. The formulas are only the first part of the puzzle though, if you need to make this work for arbitrary cities, you'll need a location database to get the lat/long from. Luckily you can get this for free from [Geonames.org][3], although there are commercial db's available (ask google). So, in general, look up the two cities you want, get the lat/long co-orinates and plug them into the formula as in the Wikipedia [example][4]. Last but not least, Joel wrote an article about this problem a while back, so here you go:[http://www.joelonsoftware.com/oldnews/pages/October2006.html][5] [1]: http://en.wikipedia.org/wiki/Great-circle_distance [2]: http://williams.best.vwh.net/avform.htm [3]: http://www.geonames.org/ [4]: http://en.wikipedia.org/wiki/Great-circle_distance#A_worked_example [5]: http://www.joelonsoftware.com/oldnews/pages/October2006.html
You do not need domain admin rights to *look* at the active directory. By default, any (authenticated?) user can read the information that you need from the directory. If that wasn't the case, for example, a computer (which has an associated account as well) could not verify the account and password of its user. You only need admin rights to *change* the contents of the directory. I think it is possible to set more restricted permissions, but that's not likely the case.
Advantage: * Only one place to update your assemblys * You use a little less hard drive space Disadvantage: * If you need to update only one website, you can't. You may end with the other websites in the webserver broken. Recommendation: Leave the GAC to MS and friends. The gigabyte is very cheap now.
I highly recommend [HostRocket][1]. I have been with them for about 6 or 7 years now with multiple domains and have found uptime and database availability flawless. The only reason I'm leaving them is because I'm doing some .NET web apps now and HostRocket is purely LAMP based. But without making things an ongoing ad. I will put in two "gotchas" that you'll want to be wary of when searching: 1. "Free" hosting services. Most of these will make you subdomain on them and worse, they'll put a header and a footer on your page (sometimes in gaudy frame format) that they advertise heavily on. I don't care how poor you are, this will not help attract traffic to your app. 2. A lot of the cheaper rates depend on pre-payment. HostRocket will give you $4.99 a month in hosting, but you have to pre-pay for 3 years. If you go month to month, it is $8.99. There are definitely advantages to the pre-payment, but you don't want to get caught with close to twice the monthly payment if you weren't expecting it. I recently found a site called [WebHostingStuff][2] that seems to have a decent list of hosts and folks that put in their reviews. While I wouldn't consider it "the final authority" I have been using it as of late for some ideas when looking for a new host. I hope this helps and happy hunting! [1]: http://www.hostrocket.com [2]: http://www.webhostingstuff.com/
AWStats and Webalizer are both good and free (I think both free speech as well as free beer). I generally prefer the look of AWStats - it has a nice modern look whereas Webalizer looks like something created in about 1992. They both give roughly the same information which includes: - Most frequently accessed pages - Which hosts (IPs and Domain Names) visitors come from - Proportion of users using different browsers - Proportion of downloads of different file types All of this information is usually viewable on a hour by hour, day by day, month by month and year by year basis. Normally the raw data is available but also with bar charts and pie charts. Both AWStats and Webalizer will (I think) try and work out where your visitors come from by using services such as GeoIP, although I never bothered to set this up. Some also try to work out what order people have visited pages in and things like that - but that is very difficult to do so the results are guesses at the best. I generally find them both useful - even if just to get an overview of what is going on with my server and who is accessing it. They are both relatively easy to install - although I seem to remember Webalizer being a little easier than AWStats, and they both have varied configuration options to let you decide exactly what you want to get out of them. For more information see their sites at [awstats.sourceforge.net/][1] and [http://www.webalizer.org/][2]. Hope that helps. Robin [1]: http://awstats.sourceforge.net/ [2]: http://www.webalizer.org/
I am a big fan of [Thrift][1] an interoperability stack from Facebook. You said they code will probably run on the same machine so it could be overkill but you can still use it. [1]: http://developers.facebook.com/thrift/
I used JNBridge (<http://www.jnbridge.com/jnbpro.htm>) on a relatively simple project where we had a .NET client app using a relatively significant jar file full of business object logic that we didn't want to port. It worked quite nicely, but I wouldn't say we fully exercised the capabilities of JNBridge.
HTML would be the next best choice, ONLY IF you would serve them from a public web server. If you tried to bundle it with your app, all the files (and images (and stylesheets (and ...) ) ) would make CHM look like a gift from gods. That said, when actually bundled in the installation package, (instead of being served over the network), I found the CHM files to work nicely. OTOH, another pitfall about CHM files: Even if you try to open a CHM file on a **local** disk, you may bump into the security block if you initially downloaded it from somewhere, because the file could be marked as "came from external source" when it was obtained.
Is the question how to generate your own help files, or what is the best help file format? Personally, I find CHM to be excellent. One of the first things I do when setting up a machine is to download the PHP Manual in CHM format (<http://www.php.net/download-docs.php>) and add a hotkey to it in [Crimson Editor][1]. So when I press F1 it loads the CHM and performs a search for the word my cursor is on (great for quick function reference). [1]: http://crimsoneditor.com/
In French, but you should be able to find the download link :) [PHP Naive Bayesian Filter][1] [1]: http://xhtml.net/scripts/PHPNaiveBayesianFilter
Our software is both distributed locally to the clients and served from a network share. We opted for generating both a CHM file and a set of HTML files for serving from the network. Users starting the program locally use the CHM file, and users getting their program served from a network share has to use the HTML files. We use [Help and Manual](http://www.helpandmanual.com/) and can thus easily produce both types of output from the same source project. The HTML files also contain searching capabilities and doesn't require a web server, so though it isn't an optimal solution, works fine. So far all the single-file types for Windows seems broken in one way or another: * WinHelp - obsoleted * HtmlHelp (CHM) - obsoleted on Vista, doesn't work from network share, other than that works really nice * Help 2 (HXS) - unsure about the right name, but this seems to work right up until the point when it doesn't, corrupted indexes or similar
Our software is both distributed locally to the clients and served from a network share. We opted for generating both a CHM file and a set of HTML files for serving from the network. Users starting the program locally use the CHM file, and users getting their program served from a network share has to use the HTML files. We use [Help and Manual](http://www.helpandmanual.com/) and can thus easily produce both types of output from the same source project. The HTML files also contain searching capabilities and doesn't require a web server, so though it isn't an optimal solution, works fine. So far all the single-file types for Windows seems broken in one way or another: * WinHelp - obsoleted * HtmlHelp (CHM) - obsoleted on Vista, doesn't work from network share, other than that works really nice * Microsoft Help 2 (HXS) - this seems to work right up until the point when it doesn't, corrupted indexes or similar, this is used by Visual Studio 2005 and above, as an example
Just a shot in the dark because I haven't tried it yet but when you realloc it returns the pointer much like malloc. Because realloc can move the pointer if needed you are most likely operating on an invalid pointer if you don't do the following: input = realloc(input, strlen(input) + delta);
Combined answers from @adam-wright and pix0r will work the best IMHO: <pre><code> using System.IO; string path = Path.GetTempPath() + Path.GetRandomFileName(); while (Directory.Exists(path)) path = Path.GetTempPath() + Path.GetRandomFileName(); File.Delete(path); Directory.CreateDirectory(path); </code></pre>
Alternatively, you could just programmatically save the current state of autoplay and turn it off when your program starts, then restore the original state when your program closes. This would be a lot simpler. Check out [the NoDriveTypeAutoRun key](http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/regentry/93502.mspx?mfr=true).
The advantage to using System.IO.Path.GetTempFileName is that it will be a file in the user's local (i.e., non-roaming) path. This is exactly where you would want it for permissions and security reasons.
I would propose to use three databases. One production database, one development database (filled with some meaningful data for each developer) and one testing database (with empty tables and maybe a few rows that are always needed). A way to test database code is: 1. Insert a few rows (using SQL) to initialize state 2. Run the function that you want to test 3. Compare expected with actual results. Here you could use your normal unit testing framework 4. Clean up the rows that were changed (so the next run won't see the previous run) The cleanup could be done in a standard way (of course, only in the testing database) with `DELETE * FROM table`.
How are the Eclipse settings saved? Perhaps you could simply adapt [this macro](http://xona.com/2005/08/02.html) and load the resulting file into Eclipse?
I've heard good things about [IKVM](http://www.ikvm.net/), the JVM that's made with .NET.
Whether you choose XSD and/or Schematron depends on what you are trying to validate. XSD is probably the most common validation strategy, but there are limits on what it can validate. If all you want to do is ensure that the right type of data is in each field, XSD should work for you. If you need to assert, for example, that the value of the &lt;small> element is less than the value of the &lt;big> element, or even more complex business rules involving multiple fields, you probably want Schematron or a hybrid approach.
We found out this morning why our code was mishandling the extender. Since the db was handling the date as a date/time it was returning the date in this format 99/99/9999 99:99:99 but we had the extender mask looking for this format 99/99/9999 99:99 <pre><code>Mask="99/99/9999 99:99:99"</code></pre> the above code fixed the problem. thanks to everyone for their help.
The google maps sample is using this code... var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); var lngSpan = northEast.lng() - southWest.lng(); var latSpan = northEast.lat() - southWest.lat(); ...which is putting the SouthWest/NorthEast bounds into a variable before attempting to get the individual lng/lat coordinates. Maybe there is something with the "nested" evaluations causing problems. Have tried the granular approach to see if you get the data you need?
|c++|stl|
This is how I was able to solve the issue: - strongly sign the custom assembly in question - modify the rssrvpolicy.config file to add permissions for the assembly <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="Test" Description="This code group grants the Test code full trust. "> <IMembershipCondition class="StrongNameMembershipCondition" version="1" PublicKeyBlob="0024000004800000940100000602000000240000575341310004000001000100ab4b135615ca6dfd586aa0c5807b3e07fa7a02b3f376c131e0442607de792a346e64710e82c833b42c672680732f16193ba90b2819a77fa22ac6d41559724b9c253358614c270c651fad5afe9a0f8cbd1e5e79f35e0f04cb3e3b020162ac86f633cf0d205263280e3400d1a5b5781bf6bd12f97917dcdde3c8d03ee61ccba2c0" /> </CodeGroup> Side note: here is a great way to get the public key blob of your assembly [VS trick for obtaining the public key token and blob of a signed assembly][1]. [1]: http://www.andrewconnell.com/blog/archive/2006/09/15/4587.aspx
Datasets/tables aren't so bad are they? Best advise I can give is to use it as much as you can in your own code, and hopefully through peer reviews and bugfixes, the other developers will see how code becomes more readable. (make sure to push the point when these occurrences happen). Ultimately if the code works, then the rest is semantics is my view.
In short, yes. Protected member variables allow access to the variable from any sub-classes as well as any classes in the same package. This can be highly useful, especially for read-only data. I don't believe that they are ever necessary however, because any use of a protected member variable can be replicated using a private member variable and a couple of getters and setters.
The consumer of your service doesn't care what's underneath your service. To really test your service layer, I think your layer needs to go down to DLLs and the database and write at least [CRUD][1] test. [1]: http://en.wikipedia.org/wiki/Create,_read,_update_and_delete
i think when you do step 2 and install the documentation just tell direct it to the usb key drive letter. easy peasy.
A quick look at [http://www.update.uu.se/~ams/slask/emacs/src/frame.h](http://www.update.uu.se/~ams/slask/emacs/src/frame.h) returns: List of buffers that were viewed, then buried in this frame. The most recently buried buffer is first. So in theory you can use cdr to obtain the same list as Ben Collins said.
Arithmetic with Arbitrarily Large Integers in PHP
|php|integer|
Ok, so PHP isn't the best language to be dealing with arbitrarily large integers in, considering that it only natively supports 32-bit signed integers. What I'm trying to do though is create a class that could represent an arbitrarily large binary number and be able to perform simple arithmetic operations on two of them (add/subtract/multiply/divide). My target is dealing with 128-bit integers. There's a couple of approaches I'm looking at, and problems I see with them. Any input or commentary on what you would choose and how you might go about it would be greatly appreciated. **Approach #1:** Create a 128-bit integer class that stores its integer internally as four 32-bit integers. The only problem with this approach is that I'm not sure how to go about handling overflow/underflow issues when manipulating individual chunks of the two operands. **Approach #2:** Use the bcmath extension, as this looks like something it was designed to tackle. My only worry in taking this approach is the scale setting of the bcmath extension, because there can't be any rounding errors in my 128-bit integers; they must be precise. I'm also worried about being able to eventually convert the result of the bcmath functions into a binary string (which I'll later need to shove into some mcrypt encryption functions). **Approach #3:** Store the numbers as binary strings (probably LSB first). Theoretically I should be able to store integers of any arbitrary size this way. All I would have to do is write the four basic arithmetic functions to perform add/sub/mult/div on two binary strings and produce a binary string result. This is exactly the format I need to hand over to mcrypt as well, so that's an added plus. This is the approach I think has the most promise at the moment, but the one sticking point I've got is that PHP doesn't offer me any way to manipulate the individual bits (that I know of). I believe I'd have to break it up into byte-sized chunks (no pun intended), at which point my questions about handling overflow/underflow from Approach #1 apply.
Advantage: - Only one place to update your assemblys - You use a little less hard drive space Disadvantage: - If you need to update only one website, you can't. You may end with the other websites in the webserver broken Recommendation: Leave the GAC to MS and friends. The gigabyte is very cheap now.
Your best bet would be putting Apache httpd in front of port 80 and relay requests meant for other servers through Apache by using modules. Most popular scenario would be Tomcat behind Apache where you'll be able to run both php and jsp applications. I'm not familiar with CherryPy, so I can only suggest you look for an Apache module for CherryPy. Edit: This looks promising: <http://tools.cherrypy.org/wiki/BehindApache>
Alternatively, to Ishmaeel's correct answer, if you have a server with 2 network cards, you could have each server answer requests on different IP addresses.
Help me live - I can't believe all of the people that say using it is a "best practice" and such - I hope I never work in your code... Use "this" when there is ambiguity, as in Corey's example or when you need to pass the object as a parameter, as in Ryan's example. There is no reason to use it otherwise because being able to resolve a variable based on the scope chain should be clear enough that qualifying variables with it should be unnecessary.
Help me live - I can't believe all of the people that say using it is a "best practice" and such - I hope I never work in your code... Use "this" when there is ambiguity, as in Corey's example or when you need to pass the object as a parameter, as in Ryan's example. There is no reason to use it otherwise because being able to resolve a variable based on the scope chain should be clear enough that qualifying variables with it should be unnecessary. EDIT: The C# documentation on "this" indicates one more use, besides the two I mentioned, for the "this" keyword - for declaring indexers: http://msdn.microsoft.com/en-us/library/dk1507sz(VS.71).aspx
Help me live - I can't believe all of the people that say using it is a "best practice" and such - I hope I never work in your code... Use "this" when there is ambiguity, as in Corey's example or when you need to pass the object as a parameter, as in Ryan's example. There is no reason to use it otherwise because being able to resolve a variable based on the scope chain should be clear enough that qualifying variables with it should be unnecessary. EDIT: The C# documentation on "this" indicates one more use, besides the two I mentioned, for the "this" keyword - for declaring indexers: http://msdn.microsoft.com/en-us/library/dk1507sz(VS.71).aspx EDIT: @Juan: Huh, I don't see any inconsistency in my statements - there are 3 instances when I would use the "this" keyword (as documented in the C# documentation), and those are times when you actually *need* it. Sticking "this" in front of variables in a constructor when there is no shadowing going on is simply a waste of keystrokes and a waste of my time when reading it, it provides no benefit.
I can't believe all of the people that say using it always is a "best practice" and such. Use "this" when there is ambiguity, as in Corey's example or when you need to pass the object as a parameter, as in Ryan's example. There is no reason to use it otherwise because being able to resolve a variable based on the scope chain should be clear enough that qualifying variables with it should be unnecessary. EDIT: The C# documentation on "this" indicates one more use, besides the two I mentioned, for the "this" keyword - for declaring indexers: http://msdn.microsoft.com/en-us/library/dk1507sz(VS.71).aspx EDIT: @Juan: Huh, I don't see any inconsistency in my statements - there are 3 instances when I would use the "this" keyword (as documented in the C# documentation), and those are times when you actually *need* it. Sticking "this" in front of variables in a constructor when there is no shadowing going on is simply a waste of keystrokes and a waste of my time when reading it, it provides no benefit.
I believe it defaults to <code>%HOMEDRIVE%\%HOMEPATH%</code> so if you can muck about with those environment variables that might be an option. I can't edit these environment variables on my company's network, so I had to use the <a href="http://technet.microsoft.com/en-us/library/cc756720.aspx">AutoRun</a> to change it to something sane.
If you are opening it from a shortcut change the working dir for the shortcut.
[Expert Oracle JDBC Programming][1] is a book aimed directly at developers who want to use Java with Oracle. Before you make even that small monetary investment though, you might want to check out the [JDBC tutorial][2] published by Sun. [1]: http://www.amazon.com/Expert-Oracle-JDBC-Programming-Menon/dp/159059407X/ref=pd_bxgy_b_text_b [2]: http://java.sun.com/docs/books/tutorial/jdbc/index.html
Mike Taulty's Blog: <http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/category/1024.aspx> A great EF intro deck: <http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/13/10235.aspx> And these ADO.NET Data Services screencasts are nice too: <http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/01/25/10152.aspx> ADO.NET Entity Framework in VS 2008 SP1 docs: <http://vs2008sp1docs.msdn.microsoft.com/en-us/ms439009.aspx> Entity Data Model Tools in VS 2008 SP1 docs: <http://vs2008sp1docs.msdn.microsoft.com/en-us/ms436973.aspx> ADO.NET Entity Framework forums: <http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=533&SiteID=1> ADO.NET team blog: <http://blogs.msdn.com/adonet/archive/tags/Entity+Framework>/default.aspx Programming LINQ and the ADO.NET Entity Framework Webcast: <http://blogs.msdn.com/adonet/archive/2008/01/28/programming-linq-and-the-ado-net-entity-framework-webcast.aspx>
Mike Taulty's Blog: <http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/category/1024.aspx> A great EF intro deck: <http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/03/13/10235.aspx> And these ADO.NET Data Services screencasts are nice too: <http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/01/25/10152.aspx> ADO.NET Entity Framework MSDN: <http://msdn.microsoft.com/en-us/library/bb399572.aspx> ADO.NET Entity Framework forums: <http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=533&SiteID=1> ADO.NET team blog: <http://blogs.msdn.com/adonet/archive/tags/Entity+Framework/default.aspx> Programming LINQ and the ADO.NET Entity Framework Webcast: <http://blogs.msdn.com/adonet/archive/2008/01/28/programming-linq-and-the-ado-net-entity-framework-webcast.aspx>
[@Ravi](http://stackoverflow.com/questions/44190?sort=newest#44250) Here's working example of your code <html> <head> <title>Font Detect please</title> <script src="prototype.js" type="text/javascript"></script> <script type="text/javascript"> function changeTD() { $('Myanmar3').innerHTML = 'False'; } </script> </head> <body> <table border="1"> <tr><td>Font</td><td>Installed</td></tr> <tr><td>Myanmar3</td><td id="Myanmar3">True</td></tr> </table> <a href="javascript:void(0);" onclick="changeTD();">Click Me</a> </body> </html> You'll notice that I added a little link that you have to click to actually make the change. I thought this might make it easier to try out for real.
**Note, try to edit your code to get rid of the html escape codes.** Well, though it has been a while since I used C/C++, realloc that grows only reuses the memory pointer value if there is room in memory after your original block. For instance, consider this: (xxxxxxxxxx..........) If your pointer points to the first x, and . means free memory location, and you grow the memory size pointed to by your variable by 5 bytes, it'll succeed. This is of course a simplified example as blocks are rounded up to a certain size for alignment, but anyway. However, if you subsequently try to grow it by another 10 bytes, and there is only 5 available, it will need to move the block in memory and update your pointer. However, in your example you are passing the function a pointer to the character, not a pointer to your variable, and thus while the strrep function internally might be able to adjust the variable in use, it is a local variable to the strrep function and your calling code will be left with the original pointer variable value. This pointer value, however, has been freed. In your case, input is the culprit. However, I would make another suggestion. In your case it looks like the *input* variable is indeed input, and if it is, it shouldn't be modified, at all. I would thus try to find another way to do what you want to do, without changing *input*, as side-effects like this can be hard to track down.
As a general rule, you should **never** do a free or realloc on a user provided buffer. You don't know where the user allocated the space (in your module, in another DLL) so you cannot use any of the allocation functions on a user buffer. Provided that you now cannot do any reallocation within your function, you should change a little its behavior like doing only one replacement, so the user will be able to compute the resulting string max length and provide you with a buffer long enough for this one replacement to occur. Then you could create another function to do the multiple replacements, but you will have to allocate the whole space for the resulting string and copy the user input string. Then you must provide a way to delete the string you allocated. Resulting in: void strrep(char *input, char *search, char *replace); char* strrepm(char *input, char *search, char *replace); void strrepmfree(char *input);
My quick hints. Instead of: `void strrep(char *input, char *search, char *replace)` try: `void strrep(char *&input, char *search, char *replace)` and than in the body: `input = realloc(input, strlen(input) + delta);` Generally read about passing function arguments as values/reference and realloc() description :).
How do I index a database field
|sql|database|indexing|
Hopefully, I can get answers for each database server. For an outline of how indexing works check out: <http://stackoverflow.com/questions/1108/how-does-database-indexing-work>
Why am I getting a malloc: double free error with realloc()?
|c|malloc|
I've tried to write a string replace function in C, which works on a char * which has been allocated using malloc(). It's a little different in that it will find and replace strings, rather than characters in the starting string. It's trivial to do if the search and replace strings are the same length (or the replace string is shorter than the search string), since I have enough space allocated. If I try to use realloc(), I get an error that tells me I am doing a double free - which I don't see how I am, since I am only using realloc(). Perhaps a little code will help: void strrep(char *input, char *search, char *replace) { int searchLen = strlen(search); int replaceLen = strlen(replace); int delta = replaceLen - searchLen; char *find = input; while (find = strstr(find, search)) { if (delta > 0) { realloc(input, strlen(input) + delta); find = strstr(input, search); } memmove(find + replaceLen, find + searchLen, strlen(input) - (find - input)); memmove(find, replace, replaceLen); } } The program works, until I try to realloc() in an instance where the replaced string will be longer than the initial string. (It still kind of works, it just spits out errors as well as the result). If it helps, the calling code looks liks: #include <stdio.h> #include <string.h> #include <stdlib.h> void strrep(char *input, char *search, char *replace); int main(void) { char *input = malloc(81); while ((fgets(input, 81, stdin)) != NULL) { strrep(input, "Noel", "Christmas"); } }
DotNetOpenId available at [http://code.google.com/p/dotnetopenid][1] [1]: http://code.google.com/p/dotnetopenid
You will have to mark the CLR as EXTERNAL_ACCESS in order to get access to the System.IO namespace, however as things go that is not a bad way to go about it. >SAFE is the default permission set, but it’s highly restrictive. With the SAFE setting, you can access only data from a local database to perform computational logic on that data. >EXTERNAL_ACCESS is the next step in the permissions hierarchy. This setting lets you access external resources such as the file system, Windows Event Viewer, and Web services. This type of resource access isn’t possible in SQL Server 2000 and earlier. This permission set also restricts operations such as pointer access that affect the robustness of your assembly. >The UNSAFE permission set assumes full trust of the assembly and thus imposes no "Code Access Security" limitations. This setting is comparable to the way extended stored procedures function—you assume all the code is safe. However, this setting does restrict the creation of unsafe assemblies to users who have sysadmin permissions. Microsoft recommends that you avoid creating unsafe assemblies as much as possible.
I'm considering the same thing. On the Open ID site, there's a link 'For Developers' @ http://openid.net/developers/ and from there is a link to 'Open Libraries' @ http://wiki.openid.net/Libraries and finally from there is one called 'DotNetOpenID' @ http://dotnetopenid.googlecode.com/ which is probably what you're looking for. Good luck.
how to get locale information on a GWT application
|url|gwt|locale|
In GWT I have to specify what locales are supported in my application. The code get compiled in various files, one for each locale (beside other versions), but I have to give my clients one only URL. This URL is supposed to be a page that should be displayed according to the locale preferred by the browser. I dont't want to have an HTTP parameter for the locale since I want to forse the locale preferred by the browser. How can this be coded in GWT? Should I try to to this using apache rewrite rules? I thied it, but I think I cannot access such parameter easely in a rewrite rule. Thanks a lot, Giuseppe
You should check out the [DotNetNuke][1] codebase as well, they have been using OpenID for the last several revisions, and you'll find working code for implementing it there. [1]: http://www.dotnetnuke.com
> 1. Does anyone know of anyway to > reduce/optimize the PDF export phase > and or the size of the PDF without > lowering the total page count? I have a few ideas and questions: 1. Is this a graphics-heavy report? If not, do you have tables that start out as text but are converted into a graphic by the SSRS PDF renderer (check if you can select the text in the PDF)? 41K per page might be more than it should be, or it might not, depending on how information-dense your report is. But we've had cases where we had minor issues with a report's layout, like having a table bleed into the page's margins, that resulted in the SSRS PDF renderer "throwing up its hands" and rendering the table as an image instead of as text. Obviously, the fewer graphics in your report, the smaller your file size will be. 2. Is there a way that you could easily break the report into pieces? E.g., if it's a 10-location report, where Location 1 is followed by Location 2, etc., on your final report, could you run the Location 1 portion independent of the Location 2 portion, etc.? If so, you could join the 10 sub-reports into one final PDF using [PDFSharp][1] after you've received them all. This leads to some difficulties with page numbering, but nothing insurmountable. > 3\. Does anyone else have any other > theories as to why this runs on the > server but not through the API? My guess would be the sheer size of the report. I don't remember everything about what's an IIS setting and what's SSRS-specific, but there might be some overall IIS settings (maybe in Metabase.xml) that you would have to be updated to even allow that much data to pass through. You could isolate the question of whether the time is the problem by taking one of your working reports and building in a long wait time in your stored procedures with WAITFOR (assuming SQL Server for your DBMS). Not solutions, per se, but ideas. Hope it helps. [1]: http://pdfsharp.com/
Do it by example and tread lightly. Anything stronger will just alienate you from the rest of the team. Remember to consider the possibility that they're onto something you've missed. Being part of a team means taking turns learning & teaching. No single person has all the answers.