instruction
stringlengths
0
30k
Here is a simple static method to do this in C#: public static string ToTitleCaseInvariant(string targetString) { return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(targetString); }
In what language? In PHP it is: [ucwords()][1] example: $HelloWorld = ucwords('hello world'); [1]: http://us2.php.net/manual/en/function.ucwords.php
What I was thinking of can be achieved using list comprehensions, but I thought that there was a function that did this in a slightly neater way. i.e. 'bar' is a list of objects, all of which have the attribute 'id' The mythical functional way: <pre><code>foo = 12 foo in iter&#95;attr(bar, 'id')</code></pre> ...
Without using a ready-made function, a super-simple low-level algorithm to convert a string to title case: <pre><code> convert first character to uppercase. for each character in string, if the previous character is whitespace, convert character to uppercase. </pre></code> This asssumes the "conv...
Get a new object instance from a Type in C#
|c#|.net|reflection|
One may not always know the Type of an object at compile-time, but may need to create an instance of the Type. How do you get a new object instance from a Type?
Lucene Score results
|lucene|
In Lucence why does the same search on diffrent partitions return results with different scores? The results from the differnt servers match exactly.
In Lucence if you had an multiple indexes that covered only one partition each. Why does the same search on different indexes return results with different scores? The results from the different servers match exactly. i.E If I searched for: - Name - John Smith - DOB - 11/11/1934 Partition 0 would return a sc...
In Lucence if you had an multiple indexes that covered only one partition each. Why does the same search on different indexes return results with different scores? The results from the different servers match exactly. i.e If I searched for: - Name - John Smith - DOB - 11/11/1934 Partition 0 would return a sc...
Use a normalised colour histogram. (Read the section on applications [here](http://en.wikipedia.org/wiki/Color_histogram)), they are commonly used in image retrieval/matching systems and are a standard way of matching images that is very reliable, relatively fast and very easy to implement. Essentially a colour hist...
Should you run one or multiple applications per tomcat cluster?
|tomcat|6|cluster-analysis|
Currently I am setting up an application that can deploy other web apps to Tomcat 6 clusters. It is set up right now to have a one to one relationship between deployed web application and a cluster. My current reasoning for this is so that I can change the JVM args of the Tomcat server without disrupting other applic...
|tomcat|cluster-analysis|
How do you use **ssh** in a shell script?
|ssh|shell|ksh|bash|rsh|
**Warning**: I'm going to answer my own question in a minute or two. I just answered this question for a co-worker. When I try to use an **ssh** command in a shell script, the command just sits there. Do you have an example of how to use **ssh** in a shell script?
How do you use ssh in a shell script?
When I try to use an **ssh** command in a shell script, the command just sits there. Do you have an example of how to use **ssh** in a shell script?
|bash|shell|ssh|ksh|rsh|
How would you use Java to handle various XML documents?
|java|xml|sax|stax|
I'm looking for the best method to parse various XML documents using a Java application. I'm currently doing this with SAX and a custom content handler and it works great - zippy and stable. I've decided to explore the option having the same program, that currently recieves a single format XML document, receive tw...
|c++|winapi|usb|device|hid|
[Mastering Regular Expressions][1], devotes the last 4 chapters to Java, PHP, Perl, and .Net. One chapter for each. From what I know the [pocket edition][2] contains just those final four chapters. [1]: http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/ref=pd_bbs_sr_1?ie=UTF8&s...
For my own future reference, I'll offer the [Regexp Syntax Summary][1] page which contrasts the syntax for `grep`, `egrep`, Emacs, Perl, Python, and Tcl. As expected, Perl supports the greatest variety of operators, but Python looks equally capable, if not more so. [1]: http://www.greenend.org.uk/rjk/2002/06/reg...
I think it's because it's a creator method (not sure if there's a better name). All it does is take what you give it and return a single string object. It doesn't operate on an existing object. If it was non-static, you would need a string to begin with.
Because the Format method has nothing to do with a string's current value. The value of the string isn't used. It takes a string and returns one.
I am no authority in JavaScript, and perhaps more of a dunce than the asker, but AFAIK, the difference is that the "javascript:" prefix is preferred/required in URI-contexts, where the argument may be as well a traditional HTTP URL as a JavaScript trigger. So, my intuitive answer would be that, since onChange expect...
I don't know if the "javascript:" prefix means anything within the onevent attributes but I know they are annoying in anchor tags when trying to open the link in a new tab. The href should be used as a fall back and **never** to attach javascript to links.
IE Securty Zone Issues
|internet-explorer|security-zone|ntlm|jcifs|intranet|
I'm developing a website which will be used in the corporate intranet which uses JCIFS and NTLM to automatically authenticate the users without asking them to log on. Everything seems to be working in IE 6, but some users are being prompted for their passwords in IE 7. We've had some success by getting the users ...
You could try to encode the image as base64 and reference it directly in an img tag within the email ( `<img src="data:image/png;base64[your encoded image here...]` ) but i think most email clients correlate this technique with spam. I think you're better off referencing hosted images or simply attaching it to the emai...
In case anyone is interested, a co-worker replied to this question to me via email: Artem wrote: There is a flag to MiniDumpWriteDump() that can do better crash dumps that will allow seeing full program state, with all global variables, etc. As for call stacks, I doubt they can be better because of optimizations...
In case anyone is interested, a co-worker replied to this question to me via email: Artem wrote: > There is a flag to MiniDumpWriteDump() > that can do better crash dumps that > will allow seeing full program state, > with all global variables, etc. As for > call stacks, I doubt they can be > better because o...
A few months back, Dustin Sallings wrote a [fork][1] of GitNub that uses Mercurial. It's Leopard-only, but lovely. On Tiger, the "view" exension mentioned in the other comments works okay, as does [hgview][2]. [1]: http://github.com/dustin/gitnub/wikis [2]: http://www.logilab.org/project/hgview
It would also help if you had a target language in mind as not all data structures and interactions are equally efficient and effective in all languages.
How expensive is ST_GeomFromText
|gis|postgis|
In postgis, is the "ST_GeomFromText" call very expensive? I ask mostly because I have a frequently called query that attempts to find the point that is nearest another point that matches some criteria, and which is also within a certain distance of that other point, and the way I currently wrote it, it's doing the sam...
|c#|winforms|textbox|
I have a user that want to be able to select a textbox and have the current text selected so that he doesn't have to highlight it all in order to change the contents. The contents need to be handle when enter is pushed. That part I think I have figured out but any suggections would be welcome. The part I need help wi...
I have a user that want to be able to select a textbox and have the current text selected so that he doesn't have to highlight it all in order to change the contents. The contents need to be handle when enter is pushed. That part I think I have figured out but any suggestions would be welcome. The part I need...
I think your best best is to run the VNC server with a different geometry on a different port. I would try based on the <a href="http://www.realvnc.com/products/free/4.1/man/vncserver.html">man page</a> > $vncserver :0 -geometry 1600x1200 > $vncserver :1 -geometry 1440x900 Then you can connect from work ...
I think your best best is to run the VNC server with a different geometry on a different port. I would try based on the <a href="http://www.realvnc.com/products/free/4.1/man/vncserver.html">man page</a> > $vncserver :0 -geometry 1600x1200 > $vncserver :1 -geometry 1440x900 Then you can connect from work ...
Hook into the KeyPress event on the TextBox, and when it encounters the Enter key, run your hardware setting code, and then highlight the full text of the textbox again (see below) - Windows will take care of clearing the text with the next keystroke for you. TextBox1.Select(0, TextBox1.Text.Length);
> Right-click the toolbox, click "Choose > Items" from the context menu, browse > to your DLL, and select it. To extend on Greg's answer... Just to clarify, you cannot add a user control to the tool box if the code for it is in the same project that you want to use it in. For some reason MS has never added this ...
[Splunk >][1] is great, and free. It allows you to visualize and search all of your logs in real time. And it's all web based, so you can view your logs from just about anywhere. [1]: http://www.splunk.com/
No it is a side effect of Crystal Reports. If you don't need it, remove it from your computer it is nothing but a headache. It is safe to delete the aspnet_client folder.
Your python interpreter is correct. One (Stupid) way of calculating a modulus is to subtract or add the modulus until the resulting value is between 0 and modulus -1. e.g 13 mod 5 = (13 - 5) mod 5 = (13 - 10) mod 5 = 3 or in your case -2 mod 5 = (-2 + 5) mod 5 = 3
Well, -2 divided by 5 would be 0 with a remainder of 3. I don't believe that should be very platform dependent, but I've seen stranger things.
It is indeed 3. In [modular arithmetic][1], a modulus is simply the remainder of a division, and the remainder of -2 divided by 5 is 3. [1]: http://en.wikipedia.org/wiki/Modular_arithmetic
The result of the modulus operation on negatives seems to be programming language dependent and here is a listing http://en.wikipedia.org/wiki/Modulo_operation
Well, 0 % 5 should be 0, right? -1 % 5 should be 4 because that's the next allowed digit going in the reverse direction (i.e., it can't be 5, since that's out of range). And following along by that logic, -2 must be 3. The easiest way to think of how it will work is that you keep adding or subtracting 5 until ...
Your question seems similar to [this one][1], which has some additional answers. [1]: http://stackoverflow.com/questions/41424/how-do-you-implement-a-did-you-mean
I'm not sure about origin of *message* terminology. Most ofter I encounter *messages* in UML design. Objects (Actors in UML terminology) can communicate with each other by means of *messages*. In real-world code *message* is just a function call usually. I think of message as of attempt to communicate with some object....
You could also do it roughly the same as discussed [here][1]: (translated to AS3) var age:int = (new Date()).fullYear - bDay.fullYear; if ((new Date()) < (new Date((bDay.fullYear + age), bDay.month, bDay.date))) age--; [1]: http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c "...
Usually, "Method" seems to be the proper name for Functions. However, each language has it's own keywords. Delphi for example even makes a difference between Methods that return something ("Functions") and Methods that return Nothing ("Procedures") whereas in C-Type languages, there is no difference.
Troubleshoot Java Lucene ignoring Field
|java|lucene|
We're currently using Lucene 2.1.0 for our site search and we've hit a difficult problem: one of our index fields is being ignored during a targeted search. Here is the code for adding the field to a document in our index: // Add market_local to index contactDocument.add( new Field( "m...
[MSDN][1]: > There is a very low probability that the value of the new Guid is all zeroes or equal to any other Guid. [1]: http://msdn.microsoft.com/en-us/library/system.guid.newguid.aspx
On this post on [Upgrading TFS 2005 to 2008 ][1] I mentioned that the SharePoint upgrade to 3.0 was the main difficulty. I thought it was performed as part of the upgrade, but it in fact is a separate upgrade process. You should also install Team Explorer 2008 before installing Visual Studio 2008 Service Pack 1 on deve...
> Is a GUID unique 100% of the time? Not guaranteed, since there are several ways of generating one. However, you can try to calculate the chance of creating two GUIDs that are identical and you get the idea: a GUID has 128 bits, hence, there are 2<sup>128</sup> distinct GUIDs – **much** more than there are stars in...
Both Subversion and CVS call them `Keywords`. [Have a look in the SVN manual here][1] (scroll down to **svn:keywords**) or [here for CVS][2]. [1]: http://svnbook.red-bean.com/en/1.0/ch07s02.html#svn-ch-7-sect-2.3 [2]: http://badgertronics.com/writings/cvs/keywords.html
Guids are statistically unique. The odds of two different clients generating the same Guid are infinitesimally small (assuming no bugs in the Guid generating code). You may as well worry about your processor glitching due to a cosmic ray and deciding that 2+2=5 today. Multiple threads allocating new guids will get...
Yeah. What I ended up doing is I converted to varchar(max) on the fly, and the replace took care of the rest. -- PREPARE SET NOCOUNT ON -- VARIABLES DECLARE @tblName NVARCHAR(150) DECLARE @colName NVARCHAR(150) DECLARE @tblID int DECLARE @first bit DECLARE @lookFor nvarchar(250) DECLARE @...
Well, I figured it out myself, right after posting, which is the most embarassing way. :) It seems every member of a StackPanel will simply fill it's minimum requested size. In the DockPanel, I had docked things in the wrong order. If the TextBox or ListBox is the only docked item without an alignment, or if they...
How do you make a post request into a new browser tab using JavaScript / XUL?
|xul|firefox|ubiquity|javascript|
I'm trying to open a new browser tab with the results of a POST request. I'm trying to do so using a function containing the following code: var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interface s.nsIWindowMediator); var b...
|javascript|firefox|xul|ubiquity|
I'm trying to open a new browser tab with the results of a POST request. I'm trying to do so using a function containing the following code: var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interface s.nsIWindowMediator); var b...
Best Versioning Tools to use for Photoshop/Illustrator and related binary files?
|versioning|photoshop|
I previously asked about Version Cue 3 vs Subversion. I think this is a better question and someone suggested [http://www.gridironsoftware.com/Flow/][1] I hope this question will allow others to join in and suggest other tools or give specific recommendation to using Version Que versus other tools. [1]: http://w...
|internet-explorer|ntlm|intranet|security-zone|jcifs|
I'm developing a website which will be used in the corporate intranet which uses JCIFS and NTLM to automatically authenticate the users without asking them to log on. Everything seems to be working in IE 6, but some users are being prompted for their passwords in IE 7. We've had some success by getting the users ...
I see nothing wrong with it being static.. The semantics of the static method seem to make a lot more sense to me. Perhaps it is because it is a primitive. Where primitives are used to often, you want to make the utility code for working with them as light as possible.. Also, I think the semantics are a lot better w...
I think that what makes pointers tricky to learn is that until pointers you're comfortable with the idea that "at this memory location is a set of bits that represent an int, a double, a character, whatever". When you first see a pointer, you don't really get what's at that memory location. "What do you mean, it ho...
> It should only be used in the href tag. That's ridiculous. The accepted way is this: <a href="/non-js-version/" onclick="someFunction(); return false">Blah</a> But to answer the OP, there is generally no reason to use "javascript:" anymore. In fact, you should attach the javascript event from your scr...
Instance methods are good when you have an object that maintains some state; the process of formatting a string does not affect the string you are operating on (read: does not modify its state), it creates a new string. With extension methods, you can now have your cake and eat it too (i.e. you can use the latter sy...
`String.Format` takes at least one String and returns a different String. It doesn't need to modify the format string in order to return another string, so it makes little sense to do that (ignoring your formatting of it). On the other hand, it wouldn't be that much of a stretch to make `String.Format` be a member func...
I think it looks better in general to use String.Format, but I could see a point in wanting to have a non-static function for when you already have a string stored in a variable that you want to "format". As an aside, all functions of the string class don't act on the string, but return a new string object, becaus...
In SVN a tag and branch are really similar. **Tag** = a defined slice in time, usually used for releases **Branch** = also a defined slice in time that development can continue on, usually used for major version like 1.0, 1.5, 2.0, etc, then when you release you tag the branch. This allows you to continue to s...
They don't really have any formal meaning. A folder is a folder to SVN. They are a generally accepted way to organize your project. The trunk is where you keep your main line of developmemt. The branch folder is where you might create, well, branches, which are hard to explain in a short post. A branch is a copy o...
The trunk directory is the directory that you're probably most familiar with, because it is used to hold the most recent changes. You main code base should be in trunk. The branches directory is for holding your branches, whatever they may be. The tags directory is basically for tagging a certain set of files. Yo...
Making one interface overwrite a method it inherits from another interface in PHP
|php|oop|interface|extends|
*The "Question":* **Is there a way in PHP to overwrite a method declared by one interface in an interface extending that interface?** *The "Example":* I'm probably doing something wrong, but here is what I have: interface iVendor{ public function __construct($vendors_no = null); public funct...
|search|lucene|
If the language you are using has a supported method/function then just use that (as in the C# ToTitleCase method) If it does not, then you will want to do something like the following: (1) Read in the string (2) Take the first word (3) Capatilise the first letter of that word* (4) Go forward and find th...
The Activator class within the root System namespace is pretty powerful. There are a lot of overloads for passing parameters to the constructor and such. Check out the documentation at: <http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx> Here are some simple examples: ObjectType inst...
No, there are many applications built with VS2005 that have to support Windows XP, 2000, NT, the whole stack. The issue is that (by default) VS2005 wants to use libraries/exports not present on NT. See [this thread](http://www.mombu.com/microsoft/windows-programmer-win32/t-vs2005-and-nt4-392831.html) for some backgr...
Here is my current method. Any suggestions? Regex singleMToDoubleRegex = new Regex("(?<!m)m(?!m)"); Regex singleDToDoubleRegex = new Regex("(?<!d)d(?!d)"); CultureInfo currentCulture = CultureInfo.CurrentUICulture; // If the culture is netural there is no date pattern to use, so use the defa...
How about giving the format (mm/dd/yyyy or dd/mm/yyyy) followed by a printout of today's date in the user's culture. MSDN has an article on [formatting a DateTime for the person's culture][1], using the CultureInfo object that might be helpful in doing this. A combination of the format (which most people are familiar w...