instruction
stringlengths
0
30k
You should not add a default to the constructor; this will mean that in the creation of the object the property will have to be assigned to twice (once as null, then again in the constructor). If you require a default value for a property it should broken out as a normal property (or possibly deferred to a builder in a...
I believe that this tutorial on jQuery has an example that might help you: [http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery][1] [1]: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery
If you're looking at joining two private networks (two networks of machines behind a NAT), the best way to do this is with a [VPN][1]. There are many pieces of equipment available to accomplish this. [1]: http://en.wikipedia.org/wiki/Virtual_private_network
Comparing two byte arrays in .NET
|c#|
How can I do this fast? Sure I can do this: static bool ByteArrayCompare(byte[] a1, byte[] a2) { if(a1.Length!=a2.Length) return false; for(int i=0; i<a1.Length; i++) if(a1[i]!=a2[i]) return false; return true; } but I'm looking for either a BC...
How can I do this fast? Sure I can do this: static bool ByteArrayCompare(byte[] a1, byte[] a2) { if(a1.Length!=a2.Length) return false; for(int i=0; i<a1.Length; i++) if(a1[i]!=a2[i]) return false; return true; } but I'm looking for either a BC...
Overriding the equals method is necessary if you want to test equivalence in standard library classes (for example, ensuring a java.util.Set contains unique elements or using objects as keys in java.util.Map objects). Note, if you override equals, ensure you honour the API contract as described in the documentation....
Slightly oversimplified a lambda function is one that can be passed round to other functions and it's logic accessed. In C# lambda syntax is often compiled to simple methods in the same way as anonymous delegates, but it can also be broken down and its logic read. For instance: LinqToSqlContext.Where( x =>...
Slightly oversimplified: a lambda function is one that can be passed round to other functions and it's logic accessed. In C# lambda syntax is often compiled to simple methods in the same way as anonymous delegates, but it can also be broken down and its logic read. For instance: LinqToSqlContext.Where( ...
Slightly oversimplified: a lambda function is one that can be passed round to other functions and it's logic accessed. In C# lambda syntax is often compiled to simple methods in the same way as anonymous delegates, but it can also be broken down and its logic read. For instance: LinqToSqlContext.Where( ...
Since it is an Identity column and you haven't saved it to the database yet it is -1. I am assuming here that this is before you save the table back to the database, correct? You need to perform the insert before that value will be set correctly.
In our [JBoss Seam in Action presentation][1] at the Javapolis conference last year, my colleague and I said that 'Seam is the next Struts'. This needed some explanation, which I later wrote-up as [Seam is the new Struts][2]. Needless to say, we like Seam. One indication popularity is the level of traffic on the [Se...
In our [JBoss Seam in Action presentation][1] at the Javapolis conference last year, my colleague and I said that 'Seam is the next Struts'. This needed some explanation, which I later wrote-up as [Seam is the new Struts][2]. Needless to say, we like Seam. One indication of Seam's popularity is the level of traffic ...
BTree files are often much faster than relational databases. SQLite contains within it a BTree library which is in the public domain (as in genuinely 'public domain', not using the term loosely). Frankly though, if I wanted a multi-user system I would need a lot of persuading not to use a decent server relational d...
@DrPizza - this is a very good question, and one that strikes right to the heart of the problem. There are a few reasons why QueueUserWorkItem and the Windows NT thread pool was ruled out (although the Vista one does look interesting, maybe in a few years). Firstly, we wanted to have greater control over when it sta...
Thread pool for executing arbitrary tasks with different priorities
|c++|multithreading|windows|
|c++|windows|multithreading|
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 ...
*string* is an alias for *System.String*. So technically, there is no difference. It's like *int* vs. *System.UInt32*. As far as guidelines, I think it's generally recommended to use *string* any time you would you're referring to an object. e.g. string place = "world"; Likewise, I think it's generally ...
`string` is an alias for `System.String`. So technically, there is no difference. It's like `int` vs. `System.UInt32`. As far as guidelines, I think it's generally recommended to use `string` any time you would you're referring to an object. e.g. string place = "world"; Likewise, I think it's generally ...
`string` is an alias for `System.String`. So technically, there is no difference. It's like `int` *vs.* `System.Int32`. As far as guidelines, I think it's generally recommended to use `string` any time you're referring to an object. e.g. string place = "world"; Likewise, I think it's generally recommend...
This [post on the IE Blog][1] explains different options for script debugging in IE. Here is the [Apple Dev FAQ][2] on debugging Javascript in Safari. [1]: http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx [2]: http://developer.apple.com/internet/safari/faq.html#anchor14
Safari 3.0 and 3.1 include the [Drosera][1] JavaScript debugger, which you can enable on the Mac by following the instructions at that link. There's also the Safari [Web Inspector][2].. [1]: http://trac.webkit.org/wiki/Drosera "Drosera" [2]: http://trac.webkit.org/wiki/Web%20Inspector "Safari Web Inspector"
For Safari you need to enable the "Develop" menu via Preferences (in Safari 3.1; see [the entry in Apple's Safari development FAQ][1]) or via $ defaults write com.apple.Safari IncludeDebugMenu 1 at the terminal in Mac OS X. Then from the Develop menu choose Show Web Inspector and click on the Console link. Yo...
Slightly oversimplified: a lambda function is one that can be passed round to other functions and it's logic accessed. In C# lambda syntax is often compiled to simple methods in the same way as anonymous delegates, but it can also be broken down and its logic read. For instance (in C#3): LinqToSqlContext.W...
ArgumentNullException for Integer
|.net|
In .NET, is it more appropriate to throw an argument null exception for an Integer if the value is Integer.MinValue or Integer = 0 (assuming that 0 is not a valid value)?
Throwing an ArgumentNullException isn't appropriate unless the argument is actually **null**. Throw an ArgumentOutOfRangeException instead (preferably with a message informing the user what values of int are actually acceptable). > **ArgumentOutOfRangeException** is thrown when a method is invoked and at least one o...
We've got complex requirements like: 1. Only certain users can create folders in parts of the SVN tree, but everyone can edit files there 2. Certain file extensions cannot contain certain text in the file 3. Certain file extensions can only be stored in a subset of directories 4. As well as several simpler on...
well, based on the documentation (http://msdn.microsoft.com/en-us/library/ms682411(VS.85).aspx) it looks like 1. security attributes (can pass null) 2. whether it's initially owned (can pass false) 3. the name of it HTH
The VB code looks something like this: hMutex = CreateMutex(ByVal 0&, 1, ByVal 0&) The first parameter is a pointer to an SECURITY_ATTRIBUTES structure. If you don't know what it is, you don't need it. Pass NULL (0). The second parameter is TRUE (non-zero, or 1) if the calling thread should take ownership ...
IP to Country?
|ip|lookup|country|iso-3166-1-alpha-2|
Does anyone know of a simple way to retrieve the country for a given IP Address? Preferably in ISO_3166-1 format?
Here's a nice free service with a public API: <http://www.hostip.info/use.html>
You can use this program, [Handle](http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx), to find which process has the lock on your file. It's a command-line tool, so I guess you use the output from that... I'm not sure about finding it programmatically. If deleting the file can wait, you could specify it ...
Killing other processes is not a healthy thing to do. If your scenario involves something like uninstallation, you could use the **MoveFileEx** api function (<http://msdn.microsoft.com/en-us/library/aa365240(VS.85).aspx>) to mark the file for deletion upon next reboot. If it appears that you really need to delete a ...
Quoting a much-replicated help page about Indexing Service query language: > To use specially treated characters such as &, |, ^, #, @, $, (, ), in a query, enclose your query in quotation marks (“). As far as I know, full text search in MSSQL is also done by the Indexing Service, so this might help.
|wordpress|php|mysql|wiki|lamp|
I am running a WordPress blog right now on my own LAMP hosting. I really want to add some basic Wiki functionality to my site. Ideally just the ability to have some posts or pages that users with certain roles / capabilities could edit. The latest version of WordPress has edit revisions, so it would seem like I coul...
|php|mysql|wiki|lamp|wordpress|
Wordpress MediaWiki Integration
On the other end of the spectrum I would be happy if I could install a Wiki and share the login credentials between WordPress and the Wiki. I hacked MediaWiki a while ago to share logins with another site (in Classic ASP) via session cookies and it was a pain to do and even worse to maintain. Ideally I would like to ...
|php|mysql|wordpress|lamp|mediawiki|
Yeah, I admit the requirement is a bit unusual. Some of the information that the users will be entering into this application exists in scans of old documents that are in a couple of different repositories. The buttons facilitate finding and opening these old docs. It's difficult to predict where the users will be o...
Use [Linq Join][1] operator: var q = from a in tableA join b in tableB on a.Key equals b.Key select a; [1]: http://www.hookedonlinq.com/JoinOperator.ashx
Use [Linq Join][1] operator: var q = from d in Dealer join dc in DealerConact on d.DealerID equals dc.DealerID select dc; [1]: http://www.hookedonlinq.com/JoinOperator.ashx
A .NET event isn't actually an object, it's an endpoint represented by two functions -- one for adding and one for removing a handler. That's why the compiler won't let you do anything other than += (which represents the add) or -= (which represents the remove). The only way to refer to an event for metaprogramming...
|c#|.net|j#|
How can I do this fast? Sure I can do this: static bool ByteArrayCompare(byte[] a1, byte[] a2) { if(a1.Length!=a2.Length) return false; for(int i=0; i<a1.Length; i++) if(a1[i]!=a2[i]) return false; return true; } but I'm looking for either a BC...
How can I do this fast? Sure I can do this: static bool ByteArrayCompare(byte[] a1, byte[] a2) { if(a1.Length!=a2.Length) return false; for(int i=0; i<a1.Length; i++) if(a1[i]!=a2[i]) return false; return true; } but I'm looking for either a BC...
The union answer is _almost_ correct, depending on overlapping values: SELECT distinct ColumnA FROM Table1 UNION SELECT distinct ColumnA FROM Table2 If 'd' appeared in Table1 or 'c' appeared in Table2 you would have multiple rows with them.
If the argument is not null, don't throw an ArgumentNullException. It would probably be more reasonable to throw an ArgumentException, explained here http://msdn.microsoft.com/en-us/library/system.argumentexception.aspx. edit: ArgumentOutOfRangeException is probably even better, as suggested above by Avenger546.
You will be able to validate your XML with either an XML Schema or a DTD using C#. DTDs are older standards as compared to XML Schemas. So, I recommend an XML Schema approach.
I think several of the answers hit around the possible solution to your problem. I agree the easiest (and best solution for SEO purposes) is the 301 redirect. In IIS this is fairly trivial, you'd create a site for subdomain.hostone.com, after creating the site, right-click on the site and go into properties. Click...
I started with LabVIEW about 2 years ago and now use it all the time so may be biased but find it ideal for applications where data acquisition and control are involved. We use LabVIEW mainly for testing where we take continuous measurements and control gas valves and ATE enclosures. This involves both digital and a...
I'd recommend being defensive for data that enter a "component" or framework. Within a "component" or framework one should think that the data is "correct". Thinking like this. It is up to the caller to supply correct parameters otherwise ALL functions and methods have to check every incomming parameter. But if the ...
The short answer is: No. In ASP.NET MVC Preview 3 there's no first-class way for including an anchor in an action link. Unlike Rails' url_for :anchor, UrlHelper.GenerateUrl (and ActionLink, RedirectToAction and so on which use it) don't have a magic property name that lets you encode an anchor. As you point out, you...
The player itself has a [Javascript API][1] that might be useful for syncing the video if you choose to make your own annotation-thingamajig. [1]: http://code.google.com/apis/youtube/js_api_reference.html
I am very much of the opinion that correct programming will protect against these risks. Things like avoiding deprecated functions, which (in the Microsoft C++ libraries at least) are commonly deprecated because of security vulnerabilities, and validating everything that crosses an external boundary. Functions that ...
You could match the property names up to the keys and use reflection to get the name for the lookup.
You could match the property names up to the keys and use reflection to get the name for the lookup. Hmm.. hopefully someone can prove me wrong, but I don't think this is possible so never mind. I don't think you can use reflection to find the current method.
You could match the property names up to the keys and use reflection to get the name for the lookup. public string FirstProperty { get { return Dictionary[PropertyName()]; } set { Dictionary[PropertyName()] = value; } private string PropertyName() { retu...
There is a technique called "[Hole Punching][1]" that works well with "Cone" NAT (Cone is a technical familly of router). That's not an 100% sure technique, today, it works well with UDP on about 80% of the router. There is some implementations of library to realize Hole Punching: [STUN][2] ([wikipedia][3]) [...
A more specific question might give more helpful results, but here's a simple pair of snippets that shows and later updates text in a status container element. <pre> // give some visual cue that you're waiting container.appendChild( document.createTextNode( "Getting stuff from remote server..." ) ); // then lat...
Best way to use a property to reference a Key-Value pair in a dictionary
|dictionary|
This is a fairly trivial matter, but I'm curious to hear people's opinions on it. If I have a Dictionary<string, string> which I'm access through properties, which of these formats would you prefer for the property? /// <summary> /// This class's FirstProperty property /// </summary> [DefaultVa...
I started with LabVIEW about 2 years ago and now use it all the time so may be biased but find it ideal for applications where data acquisition and control are involved. We use LabVIEW mainly for testing where we take continuous measurements and control gas valves and ATE enclosures. This involves both digital and a...
Is FindFirstChangeNotification the best API to use for file system change notification on windows?
|windows|notifications|
I'm new to windows programming and I'm trying to get notified of all changes to the file system (similar to the information that FileMon from SysInternals displays, but via an API). Is a FindFirstChangeNotification for each (non-network, non-substed) drive my best bet or are there other more suitable C/C++ APIs?
|windows|notifications|winapi|
|windows|c|file|winapi|notifications|
Well, I think if you are using an int, then it would be better to say InvalidArgumentException. Alternatively, you could make your INTs nullable by declaring them as *int?* (especially if you expect null values for your int.
Well, I think if you are using an int, then it would be better to say InvalidArgumentException. Alternatively, you could make your INTs nullable by declaring them as *int?* (especially if you expect null values for your int.)
What is the best method for checking if a file exists from a SQL Server 2005 stored procedure?
|sql-server|
We used the "undocumented" xp_fileexist stored procedure for years in SQL Server 2000 and had no trouble with it. In 2005, it seems that they modified the behavior slightly to always return a 0 if the executing user account is not a sysadmin. It also seems to return a zero if the SQL Server service is running under the...
You should also check hardware connectivity to the database. Perhaps this thread will be helpful: [http://channel9.msdn.com/forums/TechOff/234271-Conenction-forcibly-closed-SQL-2005/][1] [1]: http://channel9.msdn.com/forums/TechOff/234271-Conenction-forcibly-closed-SQL-2005/
If you want to do it programatically. I'm not sure... and I'd really recommend against it. If you're just troubleshooting stuff on your own machine, [SysInternals Process Explorer](http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) can help you Run it, use the Find Handle command (I think it's either in...
Oh, one big hack I employed years ago, is that windows won't let you *delete* files, but it does let you *move* them. Pseudo-sort-of-code: mv %WINDIR%\System32\mfc42.dll %WINDIR\System32\mfc42.dll.old Install new mfc42.dll Tell user to save work and restart applications Upon restart, the apps loa...
try [libpcre](http://www.pcre.org/) If you're stuck on windows they have a windows port which should work. I know [e-texteditor](http://e-texteditor.com) uses it, so at least that's proof it works :-)
A lot of people (including my company) seem to use MaxMind GeoIP. They have a free version [GeoLite](http://www.maxmind.com/app/geoip_country) which is not as accurate as the paid version, but if you're just after something simple, it may be good enough.
The typical method is as follows. You've said you want to do this in C# so here goes... 1. If you don't know which process has the file locked, you'll need to examine each process's handle list, and query each handle to determine if it identifies the locked file. Doing this in C# will likely require P/Invoke or an ...
The typical method is as follows. You've said you want to do this in C# so here goes... 1. If you don't know which process has the file locked, you'll need to examine each process's handle list, and query each handle to determine if it identifies the locked file. Doing this in C# will likely require P/Invoke or an ...
I am also having a number of problems with VS 2008. Who would guess that I don't ever need to select multiple controls on a web form... Anyway, a lot has been fixed in Service Pack 1, which is in Beta currently. Might be worth installing that. It has gone a little way to fixing absolute positioning. This isn't y...
The funny thing is i wrote a php media gallery for all my music 2 days ago. I had a similar problem. Im using http://musicplayer.sourceforge.net/ for the player. and the playlis are built via php. all music request go there a script called xfer.php?file=WHATEVER $filename = base64_url_decode($_REQUEST[...
The funny thing is i wrote a php media gallery for all my music 2 days ago. I had a similar problem. Im using http://musicplayer.sourceforge.net/ for the player. and the playlis are built via php. all music request go there a script called xfer.php?file=WHATEVER $filename = base64_url_decode($_REQUEST[...
We've had problems when trying to add large numbers of files to repositories through the client which I assume created orphaned processes on the server when we killed the crashed client. We had to kill the server processes too and restart the subversion service (we run SVN as a windows service). Our SVN machine is dedi...
Animation in .Net
|dictionary|constants|property|
|dictionary|constants|property|.net|
|.net|dictionary|properties|constants|
Looking for a simple JavaScript example that updates DOM.
|javascript|
The question says it all. :)