Prompt stringlengths 10 31k | Chosen stringlengths 3 29.4k | Rejected stringlengths 3 51.1k | Title stringlengths 9 150 | Tags listlengths 3 7 |
|---|---|---|---|---|
When attempting to understand how a SQL statement is executing, it is sometimes recommended to look at the explain plan. What is the process one should go through in interpreting (making sense) of an explain plan? What should stand out as, "Oh, this is working splendidly?" versus "Oh no, that's not right." | I shudder whenever I see comments that full tablescans are bad and index access is good. Full table scans, index range scans, fast full index scans, nested loops, merge join, hash joins etc. are simply access mechanisms that must be understood by the analyst and combined with a knowledge of the database structure and t... | This subject is too big to answer in a question like this. You should take some time to read [Oracle's Performance Tuning Guide](http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/toc.htm) | How do you interpret a query's explain plan? | [
"",
"sql",
"database",
"performance",
"oracle",
"sql-execution-plan",
""
] |
I have a form like this:
```
<form name="mine">
<input type=text name=one>
<input type=text name=two>
<input type=text name=three>
</form>
```
When user types a value in 'one', I sometimes want to skip the field 'two', depending on what he typed. For example, if user types '123' and uses Tab to move to ne... | Try to attach tabindex attribute to your elements and then programmaticaly (in javaScript change it):
```
<INPUT tabindex="3" type="submit" name="mySubmit">
``` | You could use the [onfocus](http://www.w3schools.com/jsref/jsref_onfocus.asp) event on field two, which will be called when it receives focus. At that point, field 1's value should be updated and you can perform your check then. | How to skip fields using javascript? | [
"",
"javascript",
"firefox",
"focus",
"skip",
""
] |
**Is there a way to enforce/limit the types that are passed to primitives?** *(bool, int, string, etc.)*
Now, I know you can limit the generic type parameter to a type or interface implementation via the *where* clause. However, this doesn't fit the bill for primitives (AFAIK) because they do not all have a common gro... | Primitives appear to be specified in the [`TypeCode`](http://msdn.microsoft.com/en-us/library/system.typecode.aspx) enumeration:
Perhaps there is a way to find out if an object contains the `TypeCode enum` without having to cast it to an specific object or call `GetType()` or `typeof()`?
**Update** It was right under... | ```
public class Class1<GenericType> where GenericType : struct
{
}
```
This one seemed to do the job.. | Generic type checking | [
"",
"c#",
"generics",
"primitive",
"type-safety",
""
] |
I want to implement a paperless filing system and was looking to use WIA with C# for the image acquisition. There are quite a few sample projects on CodeProject, etc. However, after downloading every one of them that I can find, I have run into a problem.
In each and every one of them, the reference to WIALib is broke... | To access WIA, you'll need to add a reference to the COM library, "Microsoft Windows Image Acquisition Library v2.0" (wiaaut.dll).
add a "using WIA;"
```
const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
CommonDialogClass wiaDiag = new CommonDialogClass();
WIA.ImageFile wiaImage = null;
wiaImage ... | Heres how to target WIA 1.0 also so you can ship your app to Windows Xp. Something I was desperately looking for!!
[How to develop using WIA 1 under Vista?](https://stackoverflow.com/questions/678844/how-to-develop-using-wia-1-under-vista) | Using C#/WIA version 2.0 on Vista to Scan | [
"",
"c#",
".net",
".net-3.5",
"wia",
"image-scanner",
""
] |
We need to add WorkFlow to our Spring managed application. Does anyone have any useful experience in using any of the myriad of OSS Work Flow solutions? Which one is best? Which one integrates with Spring best? Which ones should we avoid? | If you only need some simple process orchestration, Spring's own [Web Flow](http://springframework.org/webflow), despite its name can serve as a orchestration task manager. If you need to preserve state for several days then you will need to become an 'early adopter' of one of the open-source projects. You may want to ... | Like Brian said if you're doing anything of great complexity you might look at using BPEL.
There are a number of open source BPEL engines, one that comes to mind is [Apache Orchestration Director Engine](http://ode.apache.org/) | What OSS project should I look at if I need to do Spring friendly WorkFlow? | [
"",
"java",
"spring",
"workflow",
""
] |
In Visual Studio 2008
* add a new DataGridView to a form
* Edit Columns
* Add a a new DataGridViewImageColumn
* Open the CellStyle Builder of this column (DefaultCellStyle property)
* Change the NullValue from System.Drawing.Bitmap to null
* Try to add a new Row to the DataGridView at runtime
(dataGridView1.Rows.Add... | This may well be a bug in the designer; if you take a look around at the .designer.cs file (maybe doing a diff from before and after you set NullValue to null) you should be able to see the code it generates. | Kronoz is right.
After setting it at designtime it adds this to the .designer.cs:
dataGridViewCellStyle1.NullValue = "null";
If I modify **"null"** to **null** then it works fine. I checked the DataGridViewCellStyle.NullValue set\_NullValue(Object) and get\_NullValue with reflector and I think that a string value sho... | Setting DataGridView.DefaultCellStyle.NullValue to null at designtime raises error at adding rows runtime | [
"",
"c#",
"datagridview",
"null",
""
] |
I am using the webbrowser control in winforms and discovered now that background images which I apply with css are not included in the printouts.
Is there a way to make the webbrowser print the background of the displayed document too?
Edit:
Since I wanted to do this programatically, I opted for this solution:
```
u... | If you're going to go and change an important system setting, make sure to first read the current setting and restore it when you are done.
I consider this *very bad* practice in the first place, but if you must do it then be kind.
```
Registry.LocalMachine
```
Also, try changing `LocalUser` instead of `LocalMachine... | Another registry key would be :
HKEY\_CURRENT\_USER\Software\Microsoft\Internet Explorer\PageSetup\Print\_Background
HKEY\_LOCAL\_MACHINE\Software\Microsoft\Internet Explorer\PageSetup\Print\_Background | How to print css applied background images with WebBrowser control | [
"",
"c#",
".net",
"printing",
"registry",
"webbrowser-control",
""
] |
I'm trying to write a web-app that records WAV files (eg: from the user's microphone). I know Javascript alone can not do this, but I'm interested in the least proprietary method to augment my Javascript with. My targeted browsers are Firefox for PC and Mac (so no ActiveX).
I gather it can be done with Flash (but not ... | Flash requires you to use a media server (note: I'm still using Flash MX, but a quick Google search brings up documentation for Flash CS3 that seems to concur - note that Flash CS4 is out soon, might change then). Macromedia / Adobe aim to flog you their media server, but the Red5 open-source project might be suitible ... | This is an old thread, but the issue remains relevant. It should be noted that there is a way to record audio to the server in Flash without a proprietary back-end. Here's an example project to get you started:
<https://code.google.com/p/wami-recorder/> | How does one record audio from a Javascript based webapp? | [
"",
"javascript",
"audio",
"web-applications",
""
] |
Ran into an “Out of Stack Space” error trying to serialize an ASP.Net AJAX Array object.
Here is the scenario with simplified code:
1. `Default.aspx`
2. `MainScript.js`
```
function getObject(){
return new Array();
}
function function1(obj){
var s=Sys.Serialization.JavaScriptSerializer.ser... | This problem happens because Sys.Serialization.JavaScriptSerializer can't serialize objects from others frames, but only those objects which where instantiated in the current window (which calls serialize() method). The only workaround which is known for me it's making clone of the object from other frame before callin... | I converted your example to a set of static html files, and dowloaded the standalone [Microsoft Ajax Library 3.5](http://msdn.microsoft.com/en-us/asp.net/bb944808.aspx) to test with. It didn't have issue on either Firefox 3 or IE 7, but I did notice the first alert box displayed [] (an array) and the second {} (an obje... | ASP.Net AJAX JavaScript Serialization Error | [
"",
"asp.net",
"javascript",
"asp.net-ajax",
""
] |
Is there any way to create a virtual drive in "(My) Computer" and manipulate it, somewhat like JungleDisk does it?
It probably does something like:
```
override OnRead(object sender, Event e) {
ShowFilesFromAmazon();
}
```
Are there any API:s for this? Maybe to write to an XML-file or a database, instead of a re... | You can use the [Dokan library](https://dokan-dev.github.io/) to create a virtual drive. There is a .Net wrapper for interfacing with C#. | Depending on what type of virtual drive you wish to build, here are some new OS API recently introduced in Windows, macOS and iOS.
Some of the below API is available as managed .NET code on Windows but many are a native Windows / macOS / iOS API. Even though, I was able to consume many of the below API in .NET and Xam... | C#: Create a virtual drive in Computer | [
"",
"c#",
".net",
"virtualization",
"storage",
"virtual-drive",
""
] |
I will elaborate somewhat. Jsf is kind-of extremely painful for working with from designer's perspective, somewhat in the range of trying to draw a picture while having hands tied at your back, but it is good for chewing up forms and listing lots of data. So sites we are making in my company are jsf admin pages and jsp... | To solve this one I'd probably create a JSF fragment that only includes your form, then use a `<c:import>` tag to include it in my JSF page.
That solution is probably a little fragile depending on your environment though.
EDIT: See Chris Hall's answer, `FacesContext` is not available outside the `FacesServlet`. | have you looked into using facelets? It lets you get rid of the whole JSF / JSP differences (it's an alternate and superior view controller).
It also supports great design-time semantics with the jsfc tag...
```
<input type="text" jsfc="#{SomeBean.property}" class="foo" />
```
gets translated internally to the corre... | Mixing jsp and jsf | [
"",
"java",
"jsp",
"jsf",
""
] |
I want to define something like this in *php*:
```
$EL = "\n<br />\n";
```
and then use that variable as an "endline" marker all over my site, like this:
```
echo "Blah blah blah{$EL}";
```
How do I define $EL once (in only 1 file), include it on every page on my site, and *not* have to reference it using the (stra... | Most PHP sites should have a file (I call it a header) that you include on every single page of the site. If you put that first line of code in the header file, then include it like this on every page:
```
include 'header.php';
```
you won't have to use the global keyword or anything, the second line of code you wro... | Sounds like the job of a constant. See the function [define()](https://www.php.net/define). | How to setup site-wide variables in php? | [
"",
"php",
""
] |
In podcast #15, Jeff mentioned he twittered about how to run a regular event in the background as if it was a normal function - unfortunately I can't seem to find that through twitter. Now I need to do a similar thing and are going to throw the question to the masses.
My current plan is when the first user (probably m... | I think developing a custom solution for running background tasks doesn't always worth, so I recommend to use the [Quartz Scheduler](http://www.quartz-scheduler.org/) in Java.
In your situation (need to run background tasks in a web application) you could use the ServletContextListener included in the distribution to ... | As mentioned, Quartz is one standard solution. If you don't care about clustering or persistence of background tasks across restarts, you can use the built in ThreadPool support (in Java 5,6). If you use a [ScheduledExecutorService](http://java.sun.com/javase/6/docs/api/java/util/concurrent/ScheduledExecutorService.htm... | Running a regular background event in Java web app | [
"",
"java",
"events",
""
] |
I have a tomcat instance setup but the database connection I have configured in `context.xml` keeps dying after periods of inactivity.
When I check the logs I get the following error:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was68051 seconds
ago. T... | [Tomcat Documentation](http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html)
DBCP uses the Jakarta-Commons Database Connection Pool. It relies on number of Jakarta-Commons components:
```
* Jakarta-Commons DBCP
* Jakarta-Commons Collections
* Jakarta-Commons Pool
```
This attribute may help yo... | Just to clarify what is actually causing this. MySQL by default terminates open connections after 8 hours of inactivity. However the database connection pool will retain connections for longer than that.
So by setting timeBetweenEvictionRunsMillis=300000 you are instructing the connection pool to run through connectio... | Java+Tomcat, Dying database connection? | [
"",
"java",
"mysql",
"database",
"tomcat",
""
] |
Now that I know `C++` I want to get into desktop application that have a UI instead of `Command Prompt` stuff, where should I start?, and what are some good **online** resources? | [wxWidgets](http://www.wxwidgets.org/) is a cross platform GUI library for C++ (and other languages). The main site should have enough pointers to resources to get going.
You might also want to check out [this](https://stackoverflow.com/questions/4347/where-is-a-good-place-to-start-programming-guis-for-windows) questi... | If cross platform support is important then I would second the suggestion to look at Qt. It supports Windows, Linux and the Mac. For free software it is free (there is a GPL version on Unix but not for Windows) but for comercial software it is not particulary cheap. There are now several books on Programming with Qt.
... | C++ UI resources | [
"",
"c++",
"user-interface",
"resources",
""
] |
Just what the title says, I need to change the password for an existing sql server login and I want to do it via sql script. | ALTER LOGIN
<http://msdn.microsoft.com/en-us/library/ms189828.aspx> | If the user already has the ALTER ANY LOGIN permission (i.e. the user can change any password for any user) then this works:
```
alter login mylogin with password = 'mylogin'
```
Otherwise, if you don't want to make every user in your system a superuser, add a parameter of the old password for the same command:
```
... | How do I script a password change for a SQL server login? | [
"",
"sql",
"sql-server",
"sql-server-2005",
""
] |
I've frequently encountered sites that put all of their JavaScript inside a `namespace` structure along the lines of:
```
namespaces = { com : { example: { example.com's data} }
```
However, setting this up safely with respect to other namespaced frameworks seems to require a relatively hefty amount of code (defined ... | Javascript doesn't have stand-alone namespaces. It has functions, which can provide scope for resolving names, and objects, which can contribute to the named data accessible in a given scope.
Here's your example, corrected:
```
var namespaces = { com: { example: { /* example.com's data */ } } }
```
This is a variabl... | Here was an interesting article by Peter Michaux on [Javascript Namespacing](http://peter.michaux.ca/article/7944). He discusses 3 different types of Javascript namespacing:
1. Prefix Namespacing
2. Single Object Namespacing
3. Nested Object Namespacing
I won't plagiarize what he said here but I think his article is ... | Is there a "concise" way to do namespacing in JavaScript? | [
"",
"javascript",
"namespaces",
""
] |
I'm working on building a development tool that is written in JavaScript.
This will not be an open source project and will be sold (hopefully) as a commercial product.
I'm looking for the best way to protect my investment. Is using an obfuscator (code mangler) enough to reasonably secure the code?
Are there other al... | I'm going to tell you a secret. Once you understand it, you'll feel a lot better about the fact that Javascript obfuscation is only really useful for saving bandwidth when sending scripts over the wire.
Your source-code is not worth stealing.
I know this comes as a shock to the ego, but I can say this confidently wit... | I deeply disagree with most answers above.
It's true that every software can be stolen despite of obfuscation but, at least, it makes harder to **extract and reuse individual parts** of the software and that is the point.
Maybe it's cheaper and less risky to use an obfuscation than leaving the code open and fighting ... | Is using an obfuscator enough to secure my JavaScript code? | [
"",
"javascript",
"obfuscation",
""
] |
I have a base class that represents a database test in TestNG, and I want to specify that all classes extending from this class are of a group "db-test", however I have found that this doesn't seem possible. I have tried the @Test annotation:
```
@Test(groups = { "db-test" })
public class DBTestBase {
}
```
However, ... | The answer is through a custom **org.testng.IMethodSelector**:
Its **includeMethod()** can exclude any method we want, like a public not-annotated method.
However, to register a custom *Java* MethodSelector, you must add it to the **XMLTest** instance managed by any TestRunner, which means you need your own **custom ... | TestNG will run all the public methods from a class with a @Test annotation. Maybe you could change the methods you don't want TestNG to run to be non-public | Can I specify a class wide group on a TestNG test case? | [
"",
"java",
"testng",
""
] |
If I were to want to create a nice looking widget to stay running in the background with a small memory footprint, where would I start building the windows application. It's goal is to keep an updated list of items off of a web service. Similar to an RSS reader.
note: The data layer will be connecting through REST, wh... | re:
> Update: Clarification The above sizes,
> are the memory being used as the
> process is ran, not the executable.
Okay, when you run a tiny C# Win Forms app, the smallest amount of RAM that is reserved for it is around 2 meg, maybe 4 meg. This is just a working set that it creates. It's not actively using all of ... | If you "already have a C# dll" you're intending to use then there must be .net already installed on the target machine.
In that case, a C# win forms app need not be anywhere near 20 meg. The smallest hello world type win form would be 7 kilobytes. | What is best for desktop widgets (small footprint and pretty graphics)? | [
"",
".net",
"c++",
"wpf",
".net-3.5",
""
] |
As the title states, I'd be interested to find a safe feature-based (that is, without using navigator.appName or navigator.appVersion) way to detect Google Chrome.
By feature-based I mean, for example:
```
if(window.ActiveXObject) {
// internet explorer!
}
```
**Edit:** As it's been pointed out, the question doe... | ```
isChrome = function() {
return Boolean(window.chrome);
}
``` | **This answer is very outdated**, but it was very relevant back then in the stone age.
I think feature detect is more usefull than navigator.userAgent parsing, as I googled Opera ambiguosity [here](http://www.javascriptkit.com/javatutors/navigator.shtml "here"). Nobody can know if IE16 will parse the /MSIE 16.0;/ rege... | Safe feature-based way for detecting Google Chrome with Javascript? | [
"",
"javascript",
"browser",
"google-chrome",
""
] |
In a multi-threaded application I'm working on, we occasionally see `ConcurrentModificationExceptions` on our Lists (which are mostly `ArrayList`, sometimes Vectors). But there are other times when I think concurrent modifications are happening because iterating through the collection appears to be missing items, but n... | Your original question seems to be asking for an iterator that sees live updates to the underlying collection while remaining thread-safe. This is an incredibly expensive problem to solve in the general case, which is why none of the standard collection classes do it.
There are lots of ways of achieving partial soluti... | Depending on your update frequency one of my favorites is the CopyOnWriteArrayList or CopyOnWriteArraySet. They create a new list/set on updates to avoid concurrent modification exception. | Detecting concurrent modifications? | [
"",
"java",
"collections",
""
] |
How to implement a website with a recommendation system similar to stackoverflow/digg/reddit? I.e., users submit content and the website needs to calculate some sort of "hotness" according to how popular the item is. The flow is as follows:
* Users submit content
* Other users view and vote on the content (assume 90% ... | You could use something similar to the [Reddit algorithm](http://redflavor.com/reddit.cf.algorithm.png) - the basic principle of which is you compute a value for a post based on the time it was posted and the score. What's neat about the Reddit algorithm is that you only need recompute the value when the score of a pos... | On my own site, I assign each entry a unique integer from a monotonically increasing series (newer posts get higher numbers). Each up vote increases the number by one, and each down vote decreases it by one (you can tweak these values, of course). Then, simply sort by the number to display the 'hottest' entries. | How to implement a Digg-like algorithm? | [
"",
"sql",
"algorithm",
"recommendation-engine",
"digg",
""
] |
Suppose the following:
```
>>> s = set([1, 2, 3])
```
How do I get a value (any value) out of `s` without doing `s.pop()`? I want to leave the item in the set until I am sure I can remove it - something I can only be sure of after an asynchronous call to another host.
Quick and dirty:
```
>>> elem = s.pop()
>>> s.a... | Two options that don't require copying the whole set:
```
for e in s:
break
# e is now an element from s
```
Or...
```
e = next(iter(s))
```
But in general, sets don't support indexing or slicing. | Least code would be:
```
>>> s = set([1, 2, 3])
>>> list(s)[0]
1
```
Obviously this would create a new list which contains each member of the set, so not great if your set is very large. | How to retrieve an element from a set without removing it? | [
"",
"python",
"set",
""
] |
I've got a standard Rails app with Nginx and Mongrel running at <http://mydomain>. I need to run a Wordpress blog at <http://mydomain.com/blog>. My preference would be to host the blog in Apache running on either the same server or a separate box but I don't want the user to see a different server in the URL. Is that p... | I think joelhardi's solution is superior to the following. However, in my own application, I like to keep the blog on a separate VPS than the Rails site (separation of memory issues). To make the user see the same URL, you use the same proxy trick that you normally use for proxying to a mongrel cluster, except you prox... | Actually, since you're using Nginx, you're already in great shape and don't need Apache.
You can run PHP through fastcgi (there are examples of how to do this [in the Nginx wiki](http://wiki.codemongers.com/NginxFcgiExample)), and use a URL-matching pattern in your Nginx configuration to direct some URLs to Rails and ... | What's the best way to run Wordpress on the same domain as a Rails application? | [
"",
"php",
"ruby-on-rails",
"apache",
"wordpress",
"nginx",
""
] |
Is there anyway to configure a WCF service with a failover endpoint if the primary endpoint dies? Kind of like being able to specify a failover server in a SQL cluster.
Specifically I am using the TCP/IP binding for speed, but on the rare occurrence that the machine is not available I would like to redirect traffic to... | You need to use a layer 4 [load balancer](http://en.wikipedia.org/wiki/Load_balancing_%28computing%29#Relationship_with_failover) in front of the two endpoints. Prob best to stick with a dedicated piece of hardware. | Without trying to sound too vague but I think Windows Network Load Balancing (NLB) should handle this for you. | High availability | [
"",
"c#",
".net",
"wcf",
"soa",
""
] |
Any suggestions? Using visual studio in C#.
Are there any specific tools to use or methods to approach this?
### Update:
Sorry, I should have been a little more specific. I am using ASP.Net 2.0 and was looking more for a tool like jUnit for Java. I took a look at NUnit and NUnitAsp and that looks very promising. And... | Boy, that's a pretty general question. I'll do my best, but be prepared to see me miss by a mile.
Assumptions
1. You are using ASP.NET, not plain ASP
2. You don't really want to test your web pages, but the **logic** behind them. Unit testing the actual .ASPX pages is rather painful, but there are frameworks out ther... | These frameworks are useful for *integration* testing, but they can't provide unit testing, that is, testing the View isolated from persistence, business logic, whatever.
For *unit* testing Asp.Net Webforms, as well as MVC, you can use [Ivonna](http://sm-art.biz/Ivonna.aspx). For example, you can mock your database ac... | What is the best way to do unit testing for ASP.NET 2.0 web pages? | [
"",
"c#",
"asp.net",
"visual-studio",
"unit-testing",
""
] |
I'm looking for a good GUI designer for swing in eclipse. My preference is for a free/open-source plugin. | [Window Builder Pro](https://developers.google.com/java-dev-tools/wbpro/) is a great GUI Designer for eclipse and is now offered for free by google. | Here is a quite good but old comparison <http://wiki.computerwoche.de/doku.php/programmierung/gui-builder_fuer_eclipse>
Window Builder Pro is now free at Google Web Toolkit | Best GUI designer for eclipse? | [
"",
"java",
"eclipse",
"swing",
"gui-designer",
""
] |
I am currently calling the following line of code:
```
java.net.URL connection_url = new java.net.URL("http://<ip address>:<port>/path");
```
and I get the exception above when it executes. Any ideas as to why this is happening? | Your code works perfectly fine for me:
```
public static void main(String[] args) {
try {
java.net.URL connection_url = new java.net.URL("http://:/path");
System.out.println("Instantiated new URL: " + connection_url);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
}
... | As a side note, you should be using [URI](http://java.sun.com/javase/6/docs/api/java/net/URI.html) because Java URL class is screwed up. (The equals method I believe) | getting java exception: java.net.MalformedURLException: no protocol | [
"",
"java",
"url",
"io",
""
] |
I'm thinking that the reason I can't do this is because it might be a huge security hole, but here goes...
I want to have a bookmark on my browser (FF3, preferably) that is only a snippet of javascript code. It would merely construct a URL based on the current date and then do a window.location = on that URL.
I know ... | What you want is a [bookmarklet](http://en.wikipedia.org/wiki/Bookmarklet) they are easy to create and should work in most major browsers.
Edit: Stack overflow seems not to allow creating bookmarklets in the context of the site, basically you can create a new bookmark and type the following in the location field
```
... | It is worthy of note that you can put that in a function wrapper as well. imranamajeed nicely illustrated that for us... but apparently I'm too new to the site to up his post. :P
so for clarity:
```
javascript:(function(){
location.href = location.href + "#";
})();
```
(the carriage returns did not affect performa... | Add a bookmark that is only javascript, not a URL | [
"",
"javascript",
"bookmarklet",
"bookmarks",
""
] |
My C# project - we'll call it the SuperUI - used to make use of a class from an external assembly. Now it doesn't, but the compiler won't let me build the project without the assembly reference in place. Let me elaborate.
This project used to throw and catch a custom exception class - the `SuperException` - which was ... | It's likely a transitive reference, where some type method call returns an instance of SuperException boxed ("downcast") as e.g. Exception, but from inspecting the code in the transitively included code, i.e. code from your external method calls, the compiler knows that you need to be able to have information about tha... | I agree with the other comments here.. There is a reference, in plain text *somewhere* !
I have had similar problems in the past where searching through the project files returned nothing, turns out it was in some other file that wasn't automatically picked up in the search.
I don't think that creating a new project i... | Lingering assembly dependency in C# .NET | [
"",
"c#",
".net",
"dependencies",
""
] |
My university doesn't support the POST cgi method (I know, it's crazy), and I was hoping to be able to have a system where a user can have a username and password and log in securely. Is this even possible?
If it's not, how would you do it with POST? Just out of curiosity.
Cheers! | You can actually do it all with GET methods. However, you'll want to use a full challenge response protocol for the logins. (You can hash on the client side using javascript. You just need to send out a unique challenge each time.) You'll also want to use SSL to ensure that no one can see the strings as they go across.... | You could use HTTP Authentication, if supported.
You'd have to add SSL, as all methods, POST, GET and HTTP Auth (well, except Digest HHTP authentication) send plaintext.
GET is basically just like POST, it just has a limit on the amount of data you can send which is usually a lot smaller than POST and a semantic diff... | Can I implement a web user authentication system in python without POST? | [
"",
"python",
"authentication",
"cgi",
""
] |
Is anyone aware of a language feature or technique in C++ to prevent a child class from over riding a particular method in the parent class?
```
class Base {
public:
bool someGuaranteedResult() { return true; }
};
class Child : public Base {
public:
bool someGuaranteedResult() { return false; /* Haha I broke ... | A couple of ideas:
1. Make your function private.
2. Do not make your function virtual. This doesn't actually prevent the function from being shadowed by another definition though.
Other than that, I'm not aware of a language feature that will lock away your function in such a way which prevents it from being overloa... | When you can use the `final` specifier for virtual methods (introduced with C++11), you can do it. Let me quote [my favorite doc site](http://en.cppreference.com/w/cpp/language/final):
> When used in a virtual function declaration, final specifies that the function may not be overridden by derived classes.
Adapted to... | Is there a way to prevent a method from being overridden in subclasses? | [
"",
"c++",
"overriding",
"metrowerks",
""
] |
RPO 1.0 (Runtime Page Optimizer) is a recently (today?) released component for ASP and Sharepoint that compresses, combines and minifies (I can’t believe that is a real word) Javascript, CSS and other things.
What is interesting is that it was developed for ActionThis.com a NZ shop that saw at TechEd last year. They b... | I decided to answer this question again after evalutating it a little.
* The image combining is really amazing
* The CSS and Javascript is nicely minified
* All files are cached on the server meaning that the server isn't cained every time it makes a request
* The caching is performed at a browser level, meaning it wi... | Clarification on the RPO price. Launch price until end of September 2008 is $499 - and this discount is by voucher (email service@getrpo.com to get a voucher). This includes software assurrance for 12 months, after which you can choose to renew for $199 or not - the software still works.
The RPO automates 8 of Steve S... | Runtime Page Optimizer for ASP.net - Any comments? | [
"",
"asp.net",
"javascript",
"optimization",
""
] |
I am using `<input type="file" id="fileUpload" runat="server">` to upload a file in an ASP.NET application. I would like to limit the file type of the upload (example: limit to .xls or .xlsx file extensions).
Both JavaScript or server-side validation are OK (as long as the server side validation would take place befor... | Seems like you are going to have limited options since you want the check to occur before the upload. I think the best you are going to get is to use javascript to validate the extension of the file. You could build a hash of valid extensions and then look to see if the extension of the file being uploaded existed in t... | It's pretty simple using regulare expression validator.
```
<asp:RegularExpressionValidator
id="RegularExpressionValidator1"
runat="server"
ErrorMessage="Only zip file is allowed!"
ValidationExpression ="^.+(.zip|.ZIP)$"
ControlToValidate="FileUpload1"
> </asp:RegularExpressionValidator>
```
[Client-Side Validation o... | How do I Validate the File Type of a File Upload? | [
"",
"asp.net",
"javascript",
"validation",
"file",
"upload",
""
] |
I have been a VB.net developer for a few years now but I am currently applying to a few companies that use C#. I have even been told that at least one of the companies doesn't want VB.net developers.
I have been looking online trying to find real differences between the two and have asked on crackoverflow. The only ma... | I've had to interview people for a few C# positions and this is my general advice for VB.Net developers interviewing for a C# position:
* Make sure you are clear that you have been working VB.Net. This seems obvious but is something that apparently isn't (in my experience).
* Try to give a code sample, if possible. I'... | Some differences (that are more substantial than syntactical) that suitably catch me out sometimes:
* VB.NET does not have anonymous delegates
* Unsafe code blocks aren't in VB.NET | Interview question on C# and VB.net similarities/differences | [
"",
"c#",
"vb.net",
""
] |
I have a directory structure like the following;
> script.php
>
> inc/include1.php
> inc/include2.php
>
> objects/object1.php
> objects/object2.php
>
> soap/soap.php
Now, I use those objects in both `script.php` and `/soap/soap.php`, I could move them, but I want the directory structure like that for a specific r... | This should work
```
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
include "$root/inc/include1.php";
```
---
**Edit:** added imporvement by [aussieviking](https://stackoverflow.com/questions/4369/include-files-requiring-an-absolute-path#4388) | You can use relative paths. Try `__FILE__`. This is a PHP constant which always returns the path/filename of the script it is in. So, in `soap.php`, you could do:
```
include dirname(__FILE__).'/../inc/include.php';
```
> The full path and filename of the
> file. If used inside an include, the
> name of the included ... | How to include PHP files that require an absolute path? | [
"",
"php",
""
] |
I would like to do the equivalent of:
```
object result = Eval("1 + 3");
string now = Eval("System.DateTime.Now().ToString()") as string
```
Following Biri s [link](http://www.codeproject.com/KB/cs/evalcscode.aspx), I got this snippet (modified to remove obsolete method `ICodeCompiler.CreateCompiler()`:
```
priva... | Old topic, but considering this is one of the first threads showing up when googling, here is an updated solution.
You can use [Roslyn's new Scripting API to evaluate expressions](https://github.com/dotnet/roslyn/blob/main/docs/wiki/Scripting-API-Samples.md).
If you are using NuGet, just add a dependency to [Microsof... | I have written an open source project, [Dynamic Expresso](https://github.com/davideicardi/DynamicExpresso/), that can convert text expression written using a C# syntax into delegates (or expression tree). Text expressions are parsed and transformed into [Expression Trees](http://msdn.microsoft.com/en-us/library/bb39795... | How can I evaluate a C# expression dynamically? | [
"",
"c#",
"reflection",
"eval",
""
] |
Java has a convenient split method:
```
String str = "The quick brown fox";
String[] results = str.split(" ");
```
Is there an easy way to do this in C++? | C++ standard library algorithms are pretty universally based around iterators rather than concrete containers. Unfortunately this makes it hard to provide a Java-like `split` function in the C++ standard library, even though nobody argues that this would be convenient. But what would its return type be? `std::vector<st... | The [Boost tokenizer](http://www.boost.org/doc/libs/1_36_0/libs/tokenizer/index.html) class can make this sort of thing quite simple:
```
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
int main(int, char**)
{
string te... | How do I tokenize a string in C++? | [
"",
"c++",
"string",
"split",
"tokenize",
""
] |
I have a set of multiple assemblies (one assembly is to be used as an API and it depends on other assemblies). I would like to merge all assemblies into one single assembly but prevent all assemblies except the API one to be visible from the outside.
I will then obfuscate this assembly with Xenocode. From what I have ... | I know Xenocode can merge assemblies into one but I am not sure if it will internalize other non-primary assemblies.
I have found the /internalize switch in ILMerge that "internalize" all assemblies except the primary one. Pretty useful! | I have used ILMerge from microsoft to internalize DLL's into a single assembled library. There is a useful GUI for using ILMerge called NuGenUnify. You can find it [here](http://www.genetibase.com/cforce/nugenunify.php). | Internalize Class and Methods in .NET Assembly | [
"",
"c#",
".net",
"vb.net",
"assemblies",
""
] |
As a lot of people pointed out in [this question](https://stackoverflow.com/questions/4724/learning-lisp-why), Lisp is mostly used as a learning experience. Nevertheless, it would be great if I could somehow use my Lisp algorithms and combine them with my C# programs.
In college my profs never could tell me how to use ... | Try these .Net implementations of Lisp:
* [IronScheme](https://github.com/leppie/IronScheme)
> IronScheme will aim to be a R6RS
> conforming Scheme implementation based
> on the Microsoft DLR.
* [L Sharp .NET](https://github.com/RobBlackwell/LSharp)
> L Sharp .NET is a powerful Lisp-like
> scripting language for .N... | [Clojure](http://clojure.org "Clojure") is a Lisp-1 that is **compiled** on-the-fly to Java bytecode, leading to very good runtime performance. You can use Clojure, and cross-compile it to a .NET assembly using [IKVM](http://www.ikvm.net "IKVM")'s ikvmc. Of course, when used in .NET, Clojure happily generates .NET IL, ... | Using Lisp in C# | [
"",
"c#",
"lisp",
""
] |
Is there any way to know if I'm compiling under a specific Microsoft Visual Studio version? | `_MSC_VER` and possibly `_MSC_FULL_VER` is what you need. You can also examine [visualc.hpp](https://www.boost.org/doc/libs/master/boost/config/compiler/visualc.hpp) in any recent boost install for some usage examples.
Some values for the more recent versions of the compiler are:
```
MSVC++ 14.30 _MSC_VER == 1933 (Vi... | Yep \_MSC\_VER is the macro that'll get you the compiler version. The last number of releases of Visual C++ have been of the form `<compiler-major-version>.00.<build-number>`, where 00 is the minor number. So `_MSC_VER` will evaluate to `<major-version><minor-version>`.
You can use code like this:
```
#if (_MSC_VER =... | How to Detect if I'm Compiling Code with a particular Visual Studio version? | [
"",
"c++",
"visual-studio",
""
] |
I'm using the .NET CF 3.5. The type I want to create does not have a default constructor so I want to pass a string to an overloaded constructor. How do I do this?
Code:
```
Assembly a = Assembly.LoadFrom("my.dll");
Type t = a.GetType("type info here");
// All ok so far, assembly loads and I can get my type
string s... | ```
MyObj o = null;
Assembly a = Assembly.LoadFrom("my.dll");
Type t = a.GetType("type info here");
ConstructorInfo ctor = t.GetConstructor(new Type[] { typeof(string) });
if(ctor != null)
o = ctor.Invoke(new object[] { s });
``` | Ok, here's a funky helper method to give you a flexible way to activate a type given an array of parameters:
```
static object GetInstanceFromParameters(Assembly a, string typeName, params object[] pars)
{
var t = a.GetType(typeName);
var c = t.GetConstructor(pars.Select(p => p.GetType()).ToArray());
if ... | Compact Framework - how do I dynamically create type with no default constructor? | [
"",
"c#",
"reflection",
"compact-framework",
""
] |
I know I can programatically make the taskbar item for a particular window start flashing when something changes, but is there any way I can stop it from flashing either programatically after a certain period of time or at least is there a keyboard shortcur I can give to my users to somehow stop the flashing? | The [FlashWindowEx](http://msdn.microsoft.com/en-us/library/ms679347%28VS.85%29.aspx) function which controls the flashing takes a [FLASHWINFO](http://msdn.microsoft.com/en-us/library/ms679348%28VS.85%29.aspx) struct which has a uCount field to control how many times it flashes. Also, a possible value for the dwFlags f... | Instead of flashing the tasbar you can consider using the NotifyIcon. This will let you put something on the system tray (something else many consider evil because of the proliferation of apps that do this). Then you can popup a ballon tip with any change that actually describes the change itself.
To use:
(1) Drag the... | Stop the taskbar flashing | [
"",
"c#",
"winforms",
"taskbar",
""
] |
I'm working on getting an Introduction to [Groovy](http://en.wikipedia.org/wiki/Groovy_%28programming_language%29) presentation ready for my local Java User's Group and I've pretty much got it together. What I'd like to see is what you all think I just have to cover.
Remember, this is an introductory presentation. Mos... | I don't know anything about groovy so in a sense I've qualified to answer this...
I would want you to:
* Tell me why I would want to use Scripting (in general) as opposed to Java-- what does it let me do quicker (as in development time), what does it make more readable. Give tantalising examples of ways I can use chu... | I'd go for:
1. Closures
2. Duck typing
3. Builders (XML builder and slurper)
4. GStrings
5. Grails | What is a MUST COVER in my Groovy presentation? | [
"",
"java",
"groovy",
""
] |
It's a bit difficult to implement a deep object copy function. What steps you take to ensure the original object and the cloned one share no reference? | A safe way is to serialize the object, then deserialize. This ensures everything is a brand new reference.
[Here's an article](http://javatechniques.com/blog/low-memory-deep-copy-technique-for-java-objects/) about how to do this efficiently.
Caveats: It's possible for classes to override serialization such that new i... | A few people have mentioned using or overriding `Object.clone()`. Don't do it. `Object.clone()` has some major problems, and its use is discouraged in most cases. Please see Item 11, from "[Effective Java](http://java.sun.com/docs/books/effective/)" by Joshua Bloch for a complete answer. I believe you can safely use `O... | How do you make a deep copy of an object? | [
"",
"java",
"class",
"clone",
""
] |
When I use the default java locale on my linux machine it comes out with the US locale settings, where do I change this so that it comes out with the correct locale? | I believe java gleans this from the environment variables in which it was launched, so you'll need to make sure your LANG and LC\_\* environment variables are set appropriately.
The locale [manpage](http://linux.die.net/man/1/locale) has full info on said environment variables. | With the `user.language`, `user.country` and `user.variant` properties.
Example:
`java -Duser.language=th -Duser.country=TH -Duser.variant=TH SomeClass` | Setting java locale settings | [
"",
"java",
"locale",
""
] |
How do I change font size on the DataGridView? | ```
private void UpdateFont()
{
//Change cell font
foreach(DataGridViewColumn c in dgAssets.Columns)
{
c.DefaultCellStyle.Font = new Font("Arial", 8.5F, GraphicsUnit.Pixel);
}
}
``` | In winform datagrid, right click to view its properties. It has a property called DefaultCellStyle. Click the ellipsis on DefaultCellStyle, then it will present Cell Style Builder window which has the option to change the font size.
Its easy. | WinForms DataGridView font size | [
"",
"c#",
"winforms",
"datagridview",
""
] |
Is it possible to have XML-embedded JavaScript executed to assist in client-side (browser-based) XSL transformations? How is it done and how official is it?
Microsoft's XML DOM objects allow this on the server-side (i.e. in ASP/ASP.NET).
**Clarification:** I do not mean HTML DOM scripting performed *after* the docume... | To embed JavaScript for the aid of transformation you can use <xsl:script>, but [it is limited](http://www.topxml.com/xsl/tutorials/intro/xsl10.asp) to Microsoft's XML objects implementation. Here's an [example](https://oxampleski.googlecode.com/svn/trunk/XSL):
**scripted.xml**:
```
<?xml version="1.0"?>
<?xml-styles... | I don't think you can execute JavaScript code embedded inside XML documents. Like, helios mentioned, you can preform the transformation using JavaScript.
JavaScript is embedded as CDATA in most cases, which is usually used **after** the XSL transformation has taken place. If I understand correctly, you want to have an... | JavaScript in client-side XSL processing? | [
"",
"javascript",
"xslt",
"browser",
""
] |
I have a three-tier application which is installed in corporate environments. With every server version update, all clients have to be updated, too. Currently, I provide an MSI package which is automatically deployed via Active Directory, however my customers (mostly with 20-300 users each) seem to hate the MSI solutio... | You can somewhat replicate what ClickOnce does, just adjust it for your needs.
1. Create a lightweight executable that checks a network/web location for updates.
2. If there are updates, it copies them locally and replaces the "real" application files.
3. It runs the "real" application.
The location for the applicati... | It is really hard to provide you exact answers because critical information about the client side installer is not explicit. Do you install client side files into Program Files? Then you may meet problems when users are restricted.
You don't think Local Application Data is a folder to deploy application, but Google do... | Auto-updating in Corporate Environments (C#) | [
"",
"c#",
".net",
"auto-update",
""
] |
Is the return value of GetHashCode() guaranteed to be consistent assuming the same string value is being used? (C#/ASP.NET)
I uploaded my code to a server today and to my surprise I had to reindex some data because my server (win2008 64-bit) was returning different values compared to my desktop computer. | If I'm not mistaken, GetHashCode is consistent given the same value, but it is NOT guaranteed to be consistent across different versions of the framework.
From the MSDN docs on String.GetHashCode():
> The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common lan... | I had a similar problem where I filled a database table with information which was dependent on String.GetHashCode (Not the best idea) and when I upgraded the server I was working on to x64 I noticed the values I was getting from String.GetHashCode were inconsistent with what was already in the table. My solution was t... | Can I depend on the values of GetHashCode() to be consistent? | [
"",
"c#",
"hash",
""
] |
I've been looking for a *simple* Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would "likely" be unique over `500K+` generation (my needs don't really require anything much more sophisticated).
Ideally, I would be able to speci... | ## Algorithm
To generate a random string, concatenate characters drawn randomly from the set of acceptable symbols until the string reaches the desired length.
## Implementation
Here's some fairly simple and very flexible code for generating random identifiers. *Read the information that follows* for important appli... | Java supplies a way of doing this directly. If you don't want the dashes, they are easy to strip out. Just use `uuid.replace("-", "")`
```
import java.util.UUID;
public class randomStringGenerator {
public static void main(String[] args) {
System.out.println(generateString());
}
public static Str... | How to generate a random alpha-numeric string | [
"",
"java",
"string",
"random",
"alphanumeric",
""
] |
I am looking for a simple way to get a mime type where the file extension is incorrect or not given, something similar to [this question](https://stackoverflow.com/questions/51438/getting-a-files-mime-type-in-java) only in .Net. | In Urlmon.dll, there's a function called `FindMimeFromData`.
From the documentation
> MIME type detection, or "data sniffing," refers to the process of determining an appropriate MIME type from binary data. The final result depends on a combination of server-supplied MIME type headers, file extension, and/or the data... | I did use urlmon.dll in the end. I thought there would be an easier way but this works. I include the code to help anyone else and allow me to find it again if I need it.
```
using System.Runtime.InteropServices;
```
...
```
[DllImport(@"urlmon.dll", CharSet = CharSet.Auto)]
private extern static System.UInt... | Using .NET, how can you find the mime type of a file based on the file signature not the extension | [
"",
"c#",
"mime",
"mime-types",
""
] |
Using reflection, how can I get all types that implement an interface with C# 3.0/.NET 3.5 with the least code, and minimizing iterations?
This is what I want to re-write:
```
foreach (Type t in this.GetType().Assembly.GetTypes())
if (t is IMyInterface)
; //do stuff
``` | Mine would be this in c# 3.0 :)
```
var type = typeof(IMyInterface);
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => type.IsAssignableFrom(p));
```
Basically, the least amount of iterations will always be:
```
loop assemblies
loop types
see if implemented... | This worked for me. It loops though the classes and checks to see if they are derrived from myInterface
```
foreach (Type mytype in System.Reflection.Assembly.GetExecutingAssembly().GetTypes()
.Where(mytype => mytype .GetInterfaces().Contains(typeof(myInterface)))) {
//do stuff
}
``` | Getting all types that implement an interface | [
"",
"c#",
"optimization",
"reflection",
"lambda",
"c#-3.0",
""
] |
I'm looking for a profiler in order to find the bottleneck in my C++ code. I'd like to find a free, non-intrusive, and good profiling tool. I'm a game developer, and I use PIX for Xbox 360 and found it very good, but it's not free. I know the Intel [VTune](https://en.wikipedia.org/wiki/VTune), but it's not free either. | [CodeXL](https://gpuopen.com/archived/legacy-codexl/) has now superseded the End Of Line'd [AMD Code Analyst](https://web.archive.org/web/20120607044224/http://developer.amd.com/tools/CodeAnalyst/Pages/default.aspx) and both are free, but not as advanced as VTune.
There's also [Sleepy](http://www.codersnotes.com/sleep... | [Very Sleepy](http://www.codersnotes.com/sleepy/) is a C/C++ CPU profiler for Windows systems (free). | What's the best free C++ profiler for Windows? | [
"",
"c++",
"windows",
"profiling",
""
] |
I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console (using the PSPSDK toolchain), but I'm having too much trouble with the makefiles (making the proper changes and solving linking issues).
Does anyone know a good text, book or something to get some insight on porting libraries?
The only docume... | Look at other libraries that were ported over to the PSP. Doing diffs between a linux version of a library, and a PSP version should show you.
Also, try to get to know how POSIX compatible the PSP is, that will tell you how big the job of porting the library over is. | The PSP is not UNIX and is not POSIX compliant, however the open source toolchain is composed by gcc 4.3, bintutils 1.16.1 and newlib 1.16.
Most of the C library is already present and can compile most of your code. Lots of libraries have been ported just by invoking the configure script with the following arguments:
... | Help on Porting a SIP library to PSP | [
"",
"c++",
"porting",
"sip",
"playstation-portable",
"pspsdk",
""
] |
From the *Immediate Window* in Visual Studio:
```
> Path.Combine(@"C:\x", "y")
"C:\\x\\y"
> Path.Combine(@"C:\x", @"\y")
"\\y"
```
It seems that they should both be the same.
The old FileSystemObject.BuildPath() didn't work this way... | This is kind of a philosophical question (which perhaps only Microsoft can truly answer), since it's doing exactly what the documentation says.
[System.IO.Path.Combine](http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx)
"If path2 contains an absolute path, this method returns path2."
[Here's the ac... | I wanted to solve this problem:
```
string sample1 = "configuration/config.xml";
string sample2 = "/configuration/config.xml";
string sample3 = "\\configuration/config.xml";
string dir1 = "c:\\temp";
string dir2 = "c:\\temp\\";
string dir3 = "c:\\temp/";
string path1 = PathCombine(dir1, sample1);
string path2 = Path... | Why does Path.Combine not properly concatenate filenames that start with Path.DirectorySeparatorChar? | [
"",
"c#",
".net",
"file",
""
] |
I am a novice programmer who is trying to teach myself to code, specifically in C#. I've taken on a project from a friend of mine and I am not sure what I need to know to get the project done. I suppose the issue is I don't know what I need to know to even get the project started.
I do have many of the basics of objec... | [**Getting started with Visual C#**](http://msdn.microsoft.com/en-us/library/a72418yk(VS.80).aspx). | One of the things I usually recommend to Junior Developers on my projects who are looking for a better picture of how things work is to get familiar with your F10/F11 keys in Visual Studio by stepping through open source projects written in C#.
Pick something you find interesting from Codeplex or Sourceforge or Google... | How do I figure out what I need to know? | [
"",
"c#",
"syntax",
"repository",
""
] |
The DOM method `getChildNodes()` returns a `NodeList` of the children of the current `Node`. Whilst a `NodeList` is ordered, is the list guaranteed to be in document order?
For example, given `<a><b/><c/><d/></a>` is `a.getChildNodes()` guaranteed to return a `NodeList` with `b`, `c` and `d` *in that order*?
The [jav... | In my experience, yes. The [DOM spec](http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1451460987) isn't any clearer. If you're paranoid, try something like
```
current = node.firstChild;
while(null != current) {
...
current = current.nextSibling;
}
``` | A document-ordered node list is the behavior in other implementations of the DOM, such as Javascript's or Python's. And a randomly-ordered node list would be utterly useless. I think it's safe to depend on nodes being returned in document order. | Order of DOM NodeList returned by getChildNodes() | [
"",
"java",
"xml",
"dom",
""
] |
I've been using the YUI Components and want to begin using the Loader Utility to specify my dependencies on my page. From your experience, is the YUI Loader Utility a reliable way to load Javascript dependencies in web pages? | Yes, YUI Loader is reliable on all A-grade browsers. For a list of which browsers Yahoo! considers A-grade, check out the [Graded Browser Support Chart](http://developer.yahoo.com/yui/articles/gbs/). | Generally yes. Nothing should go wrong, and assuredly if it did, yahoo would be on the problem in no time! | Is the YUI Loader Utility reliable? | [
"",
"javascript",
"yui",
""
] |
Given the following example, why do I have to explicitly use the statement `b->A::DoSomething()` rather than just `b->DoSomething()`?
Shouldn't the compiler's overload resolution figure out which method I'm talking about?
I'm using Microsoft VS 2005. (Note: using virtual doesn't help in this case.)
```
class A
{
p... | The two “overloads” aren't in the same scope. By default, the compiler only considers the smallest possible name scope until it finds a name match. Argument matching is done *afterwards*. In your case this means that the compiler sees `B::DoSomething`. It then tries to match the argument list, which fails.
One solutio... | Overload resolution is one of the ugliest parts of C++
Basically the compiler finds a name match "DoSomething(int)" in the scope of B, sees the parameters don't match, and stops with an error.
It can be overcome by using the A::DoSomething in class B
```
class A
{
public:
int DoSomething() {return 0;}
};... | C++ overload resolution | [
"",
"c++",
"function",
"overloading",
"resolution",
""
] |
I have 2 strings that I'd like to compare, and return the positions of the different characters in the second string.
For example, if I have
1. `"The brown fox jumps over the lazy dog"`
2. `"The quick brown fox jumped over the lazy dog"`
I want it to highlight "quick" and "ed". What's the best way to go about this i... | This might do the trick:
[PHP Inline Diff](http://software.zuavra.net/inline-diff/)
[Text\_Diff](http://pear.php.net/package/Text_Diff) | The algorithm you're looking for is the "longest common substring problem". From there it is easy to determine the differences. See Wikipedia:
<http://en.wikipedia.org/wiki/Diff#Algorithm> | How do you find the difference between 2 strings in PHP? | [
"",
"php",
"string",
"comparison",
""
] |
I am using mssql and am having trouble using a subquery. The real query is quite complicated, but it has the same structure as this:
```
select
customerName,
customerId,
(
select count(*)
from Purchases
where Purchases.customerId=customerData.customerId
) as numberTransactions
from customerData... | use the field number, in this case:
```
order by 3
``` | Sometimes you have to wrestle with SQL's syntax (expected scope of clauses)
```
SELECT *
FROM
(
select
customerName,
customerId,
(
select count(*)
from Purchases
where Purchases.customerId=customerData.customerId
) as numberTransactions
from customerData
) as sub
order by sub.numberTransactions
```... | How to reference a custom field in SQL | [
"",
"sql",
"sql-server",
""
] |
We have an Excel 2002/XP based application that interacts with SQL 2000/5 to process fairly complex actuarial calculations. The application performs its function well, but it's difficult to manage.
We're trying to create a "controller" application or service that can manage and monitor these various instances of Excel... | Don't do it!
We tried for weeks to get something like that to work and it simply does not behave as advertised. Don't even start - give up immediately!
The only options that you really have is a heavy server-side MOSS based implementation - Excel (Web) services (they call it something like that). Windows based COM Ex... | Interop works fine except that you always end up with references to Excel objects that aren't released, so Excel instances won't close. The following KB article explains why:
<http://support.microsoft.com/default.aspx/kb/317109/EN-US/>
You can avoid the problem if you have very carefully written code for a limited se... | Does anyone have a good example of controlling multiple Excel instances from a .Net app? | [
"",
"c#",
".net",
"vb.net",
"excel",
""
] |
What are the differences between `htmlspecialchars()` and `htmlentities()`. When should I use one or the other? | From the PHP documentation for [htmlentities](https://www.php.net/htmlentities):
> This function is identical to `htmlspecialchars()` in all ways, except with `htmlentities()`, all characters which have HTML character entity equivalents are translated into these entities.
From the PHP documentation for [htmlspecialch... | `htmlspecialchars` may be used:
1. When there is no need to encode all characters which have their HTML equivalents.
If you know that the page encoding match the text special symbols, why would you use `htmlentities`? `htmlspecialchars` is much straightforward, and produce less code to send to the client.
For ... | htmlentities() vs. htmlspecialchars() | [
"",
"php",
""
] |
I'd like to create a spring bean that holds the value of a double. Something like:
```
<bean id="doubleValue" value="3.7"/>
``` | Declare it like this:
```
<bean id="doubleValue" class="java.lang.Double">
<constructor-arg index="0" value="3.7"/>
</bean>
```
And use like this:
```
<bean id="someOtherBean" ...>
<property name="value" ref="doubleValue"/>
</bean>
``` | It's also worth noting that depending on your need defining your own bean may not be the best bet for you.
```
<util:constant static-field="org.example.Constants.FOO"/>
```
is a good way to access a constant value stored in a class and default binders also work very well for conversions e.g.
```
<bean class="Foo" p:... | How do I create a spring bean for a Java double primitive? | [
"",
"java",
"spring",
"double",
""
] |
I have Carbide.c++ Developer from Nokia and I want to create applications for my S60 phone.
I've looked at the samples that goes with the different SDK's for S60 but I haven't found any simple explanation on how strings, called descriptors, are used in Symbian.
One of the problems are that I'm visually impaired and th... | Here are a few sites on blogspot that may help. They have RSS feeds that will hopefully be easier to consume than paging through PDFs.
* <http://descriptor-tips.blogspot.com/>
* <http://descriptors.blogspot.com/> | Yeah, The strings in Symbian is nightmarish.. atleast when you start with..
Here are few good references to help:
* [Introducing the RBuf Descriptor](http://developer.symbian.com/main/downloads/papers/RBuf/Introduction_to_RBuf_v1.0.pdf) from [Symbian Developer](http://developer.symbian.com)
* [Comparing C strings and... | Tutorial on understanding strings in Symbian | [
"",
"c++",
"symbian",
"carbide",
""
] |
I'm currently working on a ray-tracer in C# as a hobby project. I'm trying to achieve a decent rendering speed by implementing some tricks from a c++ implementation and have run into a spot of trouble.
The objects in the scenes which the ray-tracer renders are stored in a KdTree structure and the tree's nodes are, in ... | Firstly, if you're using C# normally, you can't suddenly get a null reference due to the garbage collector moving stuff, because the garbage collector also updates all references, so you don't need to worry about it moving stuff around.
You can pin things in memory but this may cause more problems than it solves. For ... | What is your static memory manager actually doing? Unless it is doing something unsafe (P/Invoke, unsafe code), the behaviour you are seeing is a bug in your program, and not due to the behaviour of the CLR.
Secondly, what do you mean by 'pointer', with respect to links between structures? Do you literally mean an uns... | Pinning pointer arrays in memory | [
"",
"c#",
"optimization",
"unsafe",
"raytracing",
""
] |
Given the following:
```
List<List<Option>> optionLists;
```
what would be a quick way to determine the subset of Option objects that appear in all N lists? Equality is determined through some string property such as option1.Value == option2.Value.
So we should end up with `List<Option>` where each item appears only... | Ok, this will find the list of Option objects that have a Value appearing in *every* list.
```
var x = from list in optionLists
from option in list
where optionLists.All(l => l.Any(o => o.Value == option.Value))
orderby option.Value
select option;
```
It doesn't do a "distinct" select ... | Here's a much more efficent implementation:
```
static SortedDictionary<T,bool>.KeyCollection FindCommon<T> (List<List<T>> items)
{
SortedDictionary<T, bool>
current_common = new SortedDictionary<T, bool> (),
common = new SortedDictionary<T, bool> ();
foreach (List<T> list in items)
{
if (current_co... | Fastest way to find common items across multiple lists in C# | [
"",
"c#",
""
] |
I have a table similar to this:
```
CREATE TABLE example (
id integer primary key,
name char(200),
parentid integer,
value integer);
```
I can use the parentid field to arrange data into a tree structure.
Now here's the bit I can't work out. Given a parentid, is it possible to write an SQL statement to add u... | There are a few ways to do what you need in PostgreSQL.
* If you can install modules, look at the tablefunc contrib. It has a connectby() function that handles traversing trees. <http://www.postgresql.org/docs/8.3/interactive/tablefunc.html>
* Also check out the ltree contrib, which you could adapt your table to use: ... | Here is an example script using common table expression:
```
with recursive sumthis(id, val) as (
select id, value
from example
where id = :selectedid
union all
select C.id, C.value
from sumthis P
inner join example C on P.id = C.parentid
)
select sum(val) from sumthis
```
The script above... | Is it possible to make a recursive SQL query? | [
"",
"sql",
"postgresql",
"recursive-query",
""
] |
It may not be best practice but are there ways of removing unsused classes from a third party's jar files. Something that looks at the way in which my classes are using the library and does some kind of coverage analysis, then spits out another jar with all of the untouched classes removed.
Obviously there are issues ... | There is a way.
The JarJar project does this AFAIR. The first goal of the JarJar project is to allow one to embed third party libraries in your own jar, changing the package structure if necessary. Doing so it can strip out the classes that are not needed.
Check it out at <http://code.google.com/p/jarjar/>.
Here is ... | There is a tool in Ant called a classfileset. You specify the list of root classes that you know you need, and then the classfileset recursively analyzes their code to find all dependencies.
Alternatively, you could develop a good test suite that exercises all of the functions that you need, then run your tests under ... | How do I strip the fluff out of a third party library? | [
"",
"java",
"optimization",
"size",
""
] |
Drawing a parallelgram is nicely supported with Graphics.DrawImage:
```
Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height);
using (Graphics gr = new Graphics.FromImage(destImage))
{
Point[] destPts = new Point[] { new PointF(x1, y1),
new PointF(x2, y2), new PointF(x4, y4)};
gr.DrawImage(sr... | Closest I can find is [this information](http://vckicks.110mb.com/image-distortion.html), which is extremely laggy. | Normally you would do this with a 3x3 Matrix, but the Matrix class only lets you specify 6 values instead of 9. You might be able to do this in Direct X. | Is there any way to draw an image to use 4 points rather than 3 (perspective warp) | [
"",
"c#",
".net",
"gdi+",
""
] |
What are the best Java example sites? I'm looking for places that you go when you have a specific question and you want a little Java code snippet to solve it with. | [java2s](http://www.java2s.com/) is the best according to me. because -
1) Like mrlinx said "almost always has a sample on common stuff"
2) Stuffs are nicely organized by category, so, you can easily find out what you are looking for.
3) You can find codes for latest version of JDK | I like Java Almanac (now renamed www.exampledepot.com/). It has great examples and very pertinent questions, but it only goes through java 1.4, so unfortunately it's pretty out of date. It has good coverage of simple questions like "Quintessential Regular Expression Search and Replace Program" and "Reading Text from a ... | What are the best Java example sites? | [
"",
"java",
""
] |
I'd like to indicate to the user of a web app that a long-running task is being performed. Once upon a time, this concept would have been communicated to the user by displaying an hourglass. Nowadays, it seems to be an animated spinning circle. (e.g., when you are loading a new tab in Firefox, or booting in Mac OS X. C... | Google **Ajax activity indicator** to find lots of images and image generators (the "spinning" image itself is an animated GIF).
Here is [one link](http://www.ajaxload.info/) to get you started.
With the image in hand, use JQuery to toggle the visibility of the image (or perhaps its parent DIV tag). See [this link](h... | this site will do it for you:
[ajaxload](http://www.ajaxload.info/)
and on OS X it's called the "Beachball" and I like to add "Of Death". | Javascript spinning wait hourglass-type thing | [
"",
"javascript",
"jquery",
""
] |
I just learned about how the Java Collections Framework implements data structures in linked lists. From what I understand, `Iterators` are a way of traversing through the items in a data structure such as a list. Why is this interface used? Why are the methods `hasNext()`, `next()` and `remove()` not directly coded to... | > Why is this interface used?
Because it supports the basic operations that would allow a client programmer to iterate over any kind of collection (note: not necessarily a `Collection` in the `Object` sense).
> Why are the methods... not directly
> coded to the data structure
> implementation itself?
They are, they'... | You ask: "Why are the methods hasNext(), next() and remove() not directly coded to the data structure implementation itself?".
The Java Collections framework chooses to define the Iterator interface as externalized to the collection itself. Normally, since every Java collection implements the `Iterable` interface, a J... | What are the benefits of the Iterator interface in Java? | [
"",
"java",
"oop",
"collections",
"interface",
"iterator",
""
] |
In C++ we acquiring a resource in a constructor and release it in a destructor.
So when an exception rises in a middle of a function there will be no resource leak or locked mutexes or whatever.
AFAIK java classes don't have destructors. So how does one do the resource management in Java.
For example:
```
public in... | Yes you can and should put try/catch/finally block around your code. In C# there is a shorthand "using" statement, but in Java you are stuck with:
```
public int foo() {
Resource f = new Resource();
try {
DoSomething(f);
}
finally {
f.Release();
}
}
``` | This question dates to 2008 and therefore pertains to Java 6. Since then Java 7 has been released, which contains a new feature for Automatic Resource Management. For a more recent question that is relevant to Java 7 see this question:
[java techniques for automatic resource release? "prompt cleanup"?](https://stackov... | Painless resource management in java | [
"",
"java",
"resources",
""
] |
I'm using a Java socket, connected to a server.
If I send a HEADER http request, how can I measure the response time from the server? Must I use a provided java timer, or is there an easier way?
I'm looking for a short answer, I don't want to use other protocols etc. Obviously do I neither want to have a solution that... | I would say it depends on what exact interval you are trying measure, the amount of time from the last byte of the request that you send until the first byte of the response that you receive? Or until the entire response is received? Or are you trying to measure the server-side time only?
If you're trying to measure t... | `curl -s -w "%{time_total}\n" -o /dev/null http://server:3000` | How can I find the response time of a HTTP request through a Socket | [
"",
"java",
"http",
""
] |
I have some strings of xxh:yym format where xx is hours and yy is minutes like "05h:30m". What is an elegant way to convert a string of this type to TimeSpan? | This seems to work, though it is a bit hackish:
```
TimeSpan span;
if (TimeSpan.TryParse("05h:30m".Replace("m","").Replace("h",""), out span))
MessageBox.Show(span.ToString());
``` | `DateTime.ParseExact` or `DateTime.TryParseExact` lets you specify the exact format of the input. After you get the `DateTime`, you can grab the `DateTime.TimeOfDay` which is a `TimeSpan`.
In the absence of `TimeSpan.TryParseExact`, I think an 'elegant' solution is out of the mix.
@buyutec As you suspected, this meth... | Parse string to TimeSpan | [
"",
"c#",
"timespan",
""
] |
I'm looking for a clear, concise and accurate answer.
Ideally as the actual answer, although links to good explanations welcome.
This also applies to VB.Net, but the keywords are different - `ByRef` and `ByVal`. | By default (in C#), passing an object to a function actually passes a copy of the reference to that object. Changing the parameter itself only changes the value in the parameter, and not the variable that was specified.
```
void Test1(string param)
{
param = "new value";
}
string s1 = "initial value";
Test1(s1);
... | One additional note about ref vs. out: The distinction between the two is enforced by the C# compiler. The CLR does not distinguish between between out and ref. This means that you cannot have two methods whose signatures differ only by an out or ref
```
void foo(int value) {}
// Only one of the following would be al... | What do ref, val and out mean on method parameters? | [
"",
"c#",
".net",
"vb.net",
""
] |
## Summary
Hi All,
OK, further into my adventures with custom controls...
In summary, here is that I have learned of three main "classes" of custom controls. Please feel free to correct me if any of this is wrong!
1. **UserControls** - Which inherit from *UserControl* and are contained within an *ASCX* file. These... | I say go ahead with the custom rendered control. I find that in most cases the composite can be easier done and used in a UserControl, but anything beyond that and you'd need to have a finer degree of control (pun unintended) to merit your own rendering strategy.
There maybe controls that are simple enough to merit a ... | Here's another extension method that I use for custom rendering:
```
public static void WriteControls
(this HtmlTextWriter o, string format, params object[] args)
{
const string delimiter = "<2E01A260-BD39-47d0-8C5E-0DF814FDF9DC>";
var controls = new Dictionary<string,Control>();
for(int i =0;... | ASP.NET Custom Controls - Composites | [
"",
"c#",
".net",
"asp.net",
"user-controls",
"controls",
""
] |
I have a DataSet which I get a DataTable from that I am being passed back from a function call. It has 15-20 columns, however I only want 10 columns of the data.
Is there a way to remove those columns that I don't want, copy the DataTable to another that has only the columns defined that I want or is it just better to... | Aside from limiting the columns selected to reduce bandwidth and memory:
```
DataTable t;
t.Columns.Remove("columnName");
t.Columns.RemoveAt(columnIndex);
``` | To remove all columns after the one you want, below code should work. It will remove at index 10 (remember Columns are 0 based), until the Column count is 10 or less.
```
DataTable dt;
int desiredSize = 10;
while (dt.Columns.Count > desiredSize)
{
dt.Columns.RemoveAt(desiredSize);
}
``` | Remove columns from DataTable in C# | [
"",
"c#",
"asp.net",
""
] |
How can I drop all tables whose names begin with a given string?
I think this can be done with some dynamic SQL and the `INFORMATION_SCHEMA` tables. | You may need to modify the query to include the owner if there's more than one in the database.
```
DECLARE @cmd varchar(4000)
DECLARE cmds CURSOR FOR
SELECT 'drop table [' + Table_Name + ']'
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_Name LIKE 'prefix%'
OPEN cmds
WHILE 1 = 1
BEGIN
FETCH cmds INTO @cmd
IF @@f... | ```
SELECT 'DROP TABLE "' + TABLE_NAME + '"'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '[prefix]%'
```
This will generate a script.
Adding clause to check existence of table before deleting:
```
SELECT 'IF OBJECT_ID(''' +TABLE_NAME + ''') IS NOT NULL BEGIN DROP TABLE [' + TABLE_NAME + '] END;'
FROM INF... | Drop all tables whose names begin with a certain string | [
"",
"sql",
"sql-server",
"dynamic-sql",
""
] |
Maybe the need to do this is a 'design smell' but thinking about another question, I was wondering what the cleanest way to implement the **inverse** of this:
```
foreach(ISomethingable somethingableClass in collectionOfRelatedObjects)
{
somethingableClass.DoSomething();
}
```
i.e. How to get/iterate through all th... | this should do the trick:
```
collectionOfRelatedObjects.Where(o => !(o is ISomethingable))
``` | Something like this?
```
foreach (ParentType parentType in collectionOfRelatedObjects) {
if (!(parentType is ISomethingable)) {
}
}
``` | Best way to find out if an (upcast) instance doesn't implement a particular interface | [
"",
"c#",
".net",
"interface",
""
] |
I've seen examples like this:
```
public class MaxSeconds {
public static final int MAX_SECONDS = 25;
}
```
and supposed that I could have a Constants class to wrap constants in, declaring them static final. I know practically no Java at all and am wondering if this is the best way to create constants. | That is perfectly acceptable, probably even the standard.
```
(public/private) static final TYPE NAME = VALUE;
```
where `TYPE` is the type, `NAME` is the name in all caps with underscores for spaces, and `VALUE` is the constant value;
I highly recommend NOT putting your constants in their own classes or interfaces.... | I would highly advise against having a single constants class. It may seem a good idea at the time, but when developers refuse to document constants and the class grows to encompass upwards of 500 constants which are all not related to each other at all (being related to entirely different aspects of the application), ... | What is the best way to implement constants in Java? | [
"",
"java",
"constants",
""
] |
I know how to do this if I iterate through all of the characters in the string but I am looking for a more elegant method. | A regular expression will do the trick with very little code:
```
import re
...
if re.match("^[A-Za-z0-9_-]*$", my_little_string):
# do something here
``` | [Edit] There's another solution not mentioned yet, and it seems to outperform the others given so far in most cases.
Use string.translate to replace all valid characters in the string, and see if we have any invalid ones left over. This is pretty fast as it uses the underlying C function to do the work, with very litt... | How do I verify that a string only contains letters, numbers, underscores and dashes? | [
"",
"python",
"regex",
"string",
""
] |
I've to admin a small website for my alumni group which is hosted by my ISV. The url is something like www.myIsv.com/myWebSite/ which is quite ugly and very forgetable. The main admin of the webserver has registered a domain name www.mysmallwebsite.com and put a index.html with this content:
```
<html>
<head>
<title>w... | Sessions are tied to the server **AND** the domain. Using frameset across domain will cause all kind of breakage because that's just not how it was designed to do.
Try using apache mod rewrite to create a "passthrough redirection", the "**proxy**" flag ([P]) in the rule is the magic flag that you need
Documentation a... | What do you mean?
Are you saying that when you go from www.mysmallwebsite.com to www.myIsv.com/myWebSite/ then the PHP session is lost?
PHP recognizes the session with an ID (alpha-numeric hash generated on the server). The ID is passed from request to request using a cookie called PHPSESSID or something like that (yo... | PHP : session variable aren't usable when site is redirected | [
"",
"php",
"session",
"session-variables",
""
] |
I've been running Tomcat 5.5 with Java 1.4 for a while now with a huge webapp. Most of the time it runs fine, but sometimes it will just hang, with no exception generated, and no apparant way of getting it to run again other than re-starting Tomcat. The tomcat instance is allowed a gigabyte of memory on the heap, but r... | For any jvm process, force a thread dump. In windows, this can be done with CTRL-BREAK, I believe, in the console window.
In \*nix, it is almost always "kill -3 jvm-pid".
This may show if you have threads waiting on db connection pool/thread pool, etc.
Another thing to check out is how many connections you have curr... | It sounds like you're hitting a deadlock.
If you can reproduce it in a dev environment then try attaching a debugger once it's happened. Take a look at your threads and see if you have any deadlocks.
If you can't get a debugger to attach you should be able to generate a thread dump, as Dustin pointed out. | Why does Tomcat 5.5 (with Java 1.4, running on Windows XP 32-bit) suddenly hang? | [
"",
"java",
"windows",
"tomcat",
""
] |
Greetings, I'm trying to find a way to 'unbind' a socket from a particular IP/Port combination. My pseudocode looks like this:
```
ClassA a = new ClassA(); //(class A instantiates socket and binds it to 127.0.0.1:4567)
//do something
//...much later, a has been garbage-collected away.
ClassA aa = new ClassA(); //cr... | (this is what finally got everything to work for me)
Make sure EVERY socket that the socket in A connects to has
```
socket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReuseAddress, true);
```
set upon being initiated. | you can't rely on object being garbage collected in C# (i assume you're using c#, based on tagging) if it holds resources like being bound to the network resource like in your example, or holding some other kind of stream, a file stream would be a common example.
you have to assure to release the resources that the ob... | Can't Re-bind a socket to an existing IP/Port Combination | [
"",
"c#",
".net",
"networking",
"sockets",
""
] |
How do I have two effects in jQuery run in `sequence`, not simultaneously? Take this piece of code for example:
```
$("#show-projects").click(function() {
$(".page:visible").fadeOut("normal");
$("#projects").fadeIn("normal");
});
```
The `fadeOut` and the `fadeIn` run simultaneously, how do I make them run on... | You can supply a callback to the effects functions that run after the effect has completed.
```
$("#show-projects").click(function() {
$(".page:visible").fadeOut("normal", function() {
$("#projects").fadeIn("normal");
});
});
``` | What you want is a queue.
Check out the reference page <http://api.jquery.com/queue/> for some working examples. | How to make jQuery effects run in sequence, not simultaneously? | [
"",
"javascript",
"jquery",
""
] |
What is the best, preferably free/open source tool for auto-generating Java unit-tests? I know, the unit-tests cannot really serve the same purpose as normal TDD Unit-Tests which document and drive the design of the system. However auto-generated unit-tests can be useful if you have a huge legacy codebase and want to k... | Not free. Not opensource. But I have found AgitarOne Agitator (<http://www.agitar.com/solutions/products/agitarone.html>) to be REALLY good for automatically generating unit tests AND looking for unwanted obscure side effects | It is interesting, but such **generated unit tests can actually be useful.** If you're working on a legacy application, it will be often hard to write correct, state-of-the-art unit tests.
Such generated tests (if you have a way of generating them of course) can then make sure that behavior of code stays intact during... | Auto-generating Unit-Tests for legacy Java-code | [
"",
"java",
"unit-testing",
"legacy",
""
] |
I have a webapp that uses JNDI lookups to get a connection to the database.
The connection works fine and returns the query no problems. The issue us that the connection does not close properly and is stuck in the 'sleep' mode (according to mysql administrator). This means that they become unusable nad then I run out ... | > The issue us that the connection does not close properly and is stuck in the 'sleep' mode
This was actually only half right.
The problem I ran into was actually that each app was defining a new connection to the database sever. So each time I closed all the connections App A would make a bunch of new connections as... | You seem to be closing the connection properly - except for the case where prepStmt.close() throws a SQLException, I can't find a connection leak.
What pool implementation are you using? When you close a connection, the pool need not close the underlying MySQL connection immediately - after all that is the point of a ... | Java ConnectionPool connection not closing, stuck in 'sleep' | [
"",
"java",
"database",
"tomcat",
""
] |
In Javascript:
How does one find the coordinates (x, y, height, width) of every link in a webpage? | Using jQuery, it's as simple as:
```
$("a").each(function() {
var link = $(this);
var top = link.offset().top;
var left = link.offset().left;
var width = link.offset.width();
var height = link.offset.height();
});
``` | without jquery:
```
var links = document.getElementsByTagName("a");
for(var i in links) {
var link = links[i];
console.log(link.offsetWidth, link.offsetHeight);
}
```
try this page for a func to get the x and y values:
<http://blogs.korzh.com/progtips/2008/05/28/absolute-coordinates-of-dom-element-within-docu... | Find coordinates of every link in a page | [
"",
"javascript",
"web",
"hyperlink",
"location",
""
] |
Most of our Eclipse projects have multiple source folders, for example:
* src/main/java
* src/test/java
When you right-click on a class and choose New JUnit Test, the default source folder for the new test is "src/main/java" (presumably the first source folder listed in the project properties).
Is there any way to c... | I use [moreUnit](http://moreunit.sourceforge.net/), an Eclipse plugin to assist writing unit tests. Among other features, it lets you configure the default source folder of tests. | No.
Unless you change the plugin code, the default source folder is always the same as that containing the class you right clicked on (not necessarily the first source folder listed). I agree, it would be nice to be able to change it! | How to default the source folder for new JUnit tests in Eclipse? | [
"",
"java",
"eclipse",
"junit",
"usability",
""
] |
I'm using Flash to play an .flv movieclip on my site, but I want to have the .swf send trigger an event in my javascript when it start loading, starts playing and ends playing.
What is the best way to do that in Flash CS3 using Actionscript 3.0 ? | You need to use the "allowScriptAccess" flash variable in the HTML. You probably want to use "sameDomain" as the type. Note that if you go cross-domain, you also need to host a special file on the server called 'crossdomain.xml' which enables such scripting (the flash player will check for this. More info at <http://kb... | A common way to do this is with the **ExternalInterface** class, which you can use to call JavaScript methods.
First define your JavaScript methods, for example:
```
<script language="JavaScript">
function startsPlaying()
{
// do something when the FLV starts playing
}
</script>
```
Then modify y... | How can I make flash cs3, actionscript send events to javascript? | [
"",
"javascript",
"flash",
"actionscript",
""
] |
Do any asynchronous connectors exist for Mysql that can be used within a C or C++ application? I'm looking for something that can be plugged into a [reactor pattern](http://en.wikipedia.org/wiki/Reactor_pattern "reactor pattern") written in [Boost.Asio](http://www.boost.org/doc/libs/release/libs/asio/index.html "Boost.... | I know this is an old question, but consider looking at the new Boost.Mysql library: <https://anarthal.github.io/mysql/index.html> | <http://forums.mysql.com/read.php?45,183339,183339>
enjoy
Updated link to the original article showing how to do async mysql queries:
<http://jan.kneschke.de/projects/mysql/async-mysql-queries-with-c-api/> | Asynchronous Mysql connector | [
"",
"c++",
"mysql",
"c",
"asynchronous",
"boost-asio",
""
] |
How do I cast an `int` to an `enum` in C#? | From an int:
```
YourEnum foo = (YourEnum)yourInt;
```
From a string:
```
YourEnum foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString);
// The foo.ToString().Contains(",") check is necessary for
// enumerations marked with a [Flags] attribute.
if (!Enum.IsDefined(typeof(YourEnum), foo) && !foo.ToString().Con... | Just cast it:
```
MyEnum e = (MyEnum)3;
```
Check if it's in range using [`Enum.IsDefined`](http://msdn.microsoft.com/en-us/library/system.enum.isdefined.aspx):
```
if (Enum.IsDefined(typeof(MyEnum), 3)) { ... }
``` | How do I cast int to enum in C#? | [
"",
"c#",
"enums",
"casting",
"integer",
""
] |
I have a very large code base that contains extensive unit tests (using CppUnit). **I need to work out what percentage of the code is exercised by these tests**, and (ideally) generate some sort of report that tells me on a per-library or per-file basis, how much of the code was exercised.
Here's the kicker: this has ... | ### Which tool should I use?
This [article describes](http://web.archive.org/web/20090527141110/http://www.kimbly.com/blog/000331.html) another developers frustrations searching for C++ code coverage tools. The author's final solution was [Bullseye Coverage](http://www.bullseye.com/).
**[Bullseye Coverage](http://www... | If you can use [GNU GCC](http://gcc.gnu.org/onlinedocs/gcc/index.html) as your complier, then the [gcov](http://gcc.gnu.org/onlinedocs/gcc/Gcov.html) tool works well. It's very easy to fully automate the whole process. | How can I measure CppUnit test coverage (on win32 and Unix)? | [
"",
"c++",
"unit-testing",
"cross-platform",
"code-coverage",
"cppunit",
""
] |
I'm trying to come up with a design for a thread pool with a lot of design requirements for my job. This is a real problem for working software, and it's a difficult task. I have a working implementation but I'd like to throw this out to SO and see what interesting ideas people can come up with, so that I can compare t... | So what are we going to pick as the basic building block for this. Windows has two building blocks that look promising :- I/O Completion Ports (IOCPs) and Asynchronous Procedure Calls (APCs). Both of these give us FIFO queuing without having to perform explicit locking, and with a certain amount of built-in OS support ... | > It needs to run on Windows XP, Server 2003, Vista and Server 2008 (latest service packs).
What feature of the system's built-in thread pools make them unsuitable for your task? If you want to target XP and 2003 you can't use the new shiny Vista/2008 pools, but you can still use QueueUserWorkItem and friends. | Thread pool for executing arbitrary tasks with different priorities | [
"",
"c++",
"windows",
"multithreading",
""
] |
I'm responsible for some test database servers. Historically, too many other poeple have access to them. They run on `SQL Server 2005`.
I've been writing queries and wrapping them in scripts so I can run a regular audit of rights. Finding out which users had Administrator rights on the server itself was fine, as was f... | Here's how to do this. I ended up finding reference to a sproc in the MSDN docs. I pulled this from the sproc and wrapped it in a loop of all the databases known to the instance.
```
select DbRole = g.name, MemberName = u.name
from @NAME.sys.database_principals u, @NAME.sys.database_principals g, @NAME.sys.database_... | Check out this msdn reference article on [Has\_Perms\_By\_Name](http://msdn.microsoft.com/en-us/library/ms189802.aspx). I think you're really interested in examples D, F and G
---
Another idea... I fired up SQL profiler and clicked on the ObjectExplorer->Security->Users. This resulted in (approx) the following query ... | How to write an SQL query to find out which logins have been granted which rights in Sql Server 2005? | [
"",
"sql",
"database",
""
] |
We are looking for a C++ Soap web services framework that support RPC, preferably open source.
Any recommendations? | WSO2 Web Services Framework for C++ (WSO2 WSF/C++), a binding of WSO2 WSF/C into C++ is a C++ extension for consuming Web Services in C++.
<http://wso2.org/projects/wsf/cpp>
Apache Axis is an open source, XML based Web service framework. It consists of a Java and a C++ implementation of the SOAP server, and various u... | <http://code.google.com/p/staff/>
Staff is Web Service Framework for C++ (service/component and client-side)/JavaScript(client-side) based on Apache Axis2/C.
Open-source, released with Apache License V2.0. | C++ web service framework | [
"",
"c++",
"xml",
"web-services",
"frameworks",
"xsd",
""
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.