instruction stringlengths 0 30k ⌀ |
|---|
I think the ordinal suffix is hard to get... you basically have to write a function that uses a switch to test the numbers and add the suffix.
There's no reason for a language to provide this internally, especially when it's locale specific.
You can do a bit better than that link when it comes to the amount of co... |
Object Mocking is a way to create a "virtual" or mocked object from an interface, abstract class, or class with virtual methods. It allows you to sort of wrap one of these in your own definition for testing purposes. It is useful for making an object that is relied on for a certain code block your are testing.
A p... |
The way you worded the question leads me to believe that the int in the Dictionary contains the item's "position" on the Dictionary. Judging from the assertion that the keys aren't stored in the order that they're added, if this is correct, that would mean that keys.Count (or .Count - 1, if you're using zero-based) sho... |
Another use is it will let you test against other parts of your system that aren't built yet. For example, if your class depends on some other class that is part of a feature that someone else is working on, you can just ask for a mostly complete interface, program to the interface and just mock the details as you exp... |
Like everything else it is environmental and depends on the use of the system. The question you need to ask your self is:
1. Will this be actively developed
2. Is this going to be used over the course of many years and expanded on
3. Is the expansion of the application unknown and thus infinite
Really it co... |
A mock object lets you test against just what you are writing, and abstract details such as accessing a resource (disk, a network service, etc). The mock then lets you pretend to be that external resource, or class or whatever.
You don't really need a mock object framework, just extend the class of the functionalit... |
A mock object lets you test against just what you are writing, and abstract details such as accessing a resource (disk, a network service, etc). The mock then lets you pretend to be that external resource, or class or whatever.
You don't really need a mock object framework, just extend the class of the functionalit... |
As an aside: When using functions instead of methods, you could also use functools.partial:
import functools
def foo(arg, **kwargs):
...
bar = functools.partial(foo, "argvalue")
The last line will define a function "bar" that, when called, will call foo with the first argument s... |
Macro to test weather an integer type is signed or unsigned |
|c|c++| |
How would you write (in C/C++) a macro which tests if an integer type (given as a parameter) is signed or unsigned?
<pre><code>
#define is_this_type_signed (my_type) ...
<code></pre>
|
Macro to test whether an integer type is signed or unsigned |
|c++|c| |
FDT (or more precicely mtasc for as2 or flex for as3) can't take a .fla file as input.
Fla files are for design, timeline animation etc though, if you're doing to do programming only you don't need fla files or the Flash IDE.
FDT is an amazing tool for coding, although there are other alternatives too (FDT is pret... |
Seems like you've implemented a JMX service and tried to install it on your server.xml file but forgot to add the apache commons modeler jar to the server/lib directory (therefore the ClassNotFoundException for org.apache.commons.modeler.Registry). Check your server.xml file for anything you might have added, and try t... |
One more vote for Lua. It's small, it's fast, it doesnt consume much memory (for games your best bet is to allocate big buffer at the initialization and re-direct all Lua memory allocations there). We used tolua to generate bindings, but there are other options, most of them much smaller/easier to use (IMO) than boost.... |
Thanks Owen and Groky, but the Single-Form interface is just not going to work. First, I already have the display code in the MDI format, so that rewrite would require a very, very large rewrite of the code. It took me about three weeks to write the basics of the app a while ago; these aren't jpgs I'm showing here, t... |
**Some websites that address web design patterns are listed below**. They do not specifically provide the HTML and/or CSS in order to achieve the desired results, but they do provide examples of live sites that you can, of course, *view source* (or, even better, use [Firebug][1]) on.
[UI-patterns][2]
--------------... |
**Some websites that address web design patterns are listed below**. They do not specifically provide the HTML and/or CSS in order to achieve the desired results, but they do provide examples of live sites that you can *view source* on (or, even better, use [Firebug][1]).
[UI-patterns][2]
----------------
This is ... |
Team System notification of unassociated checkins. |
|visual-studio-team-system| |
How can I be notified when someone checks a file into Team System and doesn't associate it with a work item? |
I would seriously reconsider this approach. E-mail hasn't got very high reliability. There's all kinds of spamfilters that might intercept e-mails with links thereby rendering the "command" half-finished, not to mention the security risks.
It's very easy to spoof the sender-address on an e-mail. You are basically op... |
If you have access to some profiling tools (such as those in the Team Suite edition of Visual Studio) you can try to set up a testing server and running some synthetic requests against it and see if there's any specific part of the code taking unreasonably long to run.
You should probably check some graphs of CPU and ... |
Wilco Bauwer wrote a webdev server that will support https. He is one of the developers that worked on cassini visual studio 2005 built in web server. [WebDev.WebServer2][1]
[1]: http://www.wilcob.com/Wilco/Toolbox/WebDevWebServer2.aspx |
How to escape text for regular expression in Java |
|java|regex|escaping| |
Does Java have a built-in way to escape arbitrary text so that it can be included in a regular expression? For example, if my users enter "$5", I'd like to match that exactly rather than a "5" after the end of input. |
What you need is some info on [Capacity Planning][1]..
[1]: http://msdn.microsoft.com/en-us/library/ms979198.aspx |
What you need is some info on [Capacity Planning][1]..
Capacity planning is the process of planning for growth and forecasting peak usage periods in order to meet system and application capacity requirements. It involves extensive performance testing to establish the application's resource utilization and transactio... |
Yes:
<http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html#quote(java.lang.String)>
Pattern.quote("$5"); |
I think what you're after is \Q$5\E. Also see Pattern.quote(s) introduced in J5.
See [Pattern][1] javadoc for details.
[1]: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html |
No, you can't execute it directly. You could probably unpack it to a temporary directory and execute it from there. |
Difference between Pattern.quote and Matcher.quoteReplacement was not clear to me before I saw following example
`s.replaceFirst(Pattern.quote("text to replace"),
Matcher.quoteReplacement("replacement text"));` |
I'd recommend using [PDO][1] (PHP Data Objects) to run parameterized SQL queries. Not only does this protect against SQL injection, it also speeds up queries. And by using PDO rather than mysql_, mysqli_, and pgsql_ functions, you make your app a little more abstracted from the database, in the rare occurence that yo... |
You lose the ability to make incremental changes (code refactorings) and still feel warm and fuzzy that the code does what it is supposed to. You lose practically free and painless motivation to structure your code with minimal explicit dependencies. IOW, you'll be able to embed lots of dependencies without noticing. W... |
This [EmacsWiki][1] article explains some issues with copy & pasting under X and how to configure it to work.
[1]: http://www.emacswiki.org/cgi-bin/wiki/CopyAndPaste |
You will lose large classes with multiple responsibilities.
You will also likely lose large methods with multiple responsibilities.
You may lose some ability to refactor, but you will also lose some of the need to refactor.
Jason Cohen said something like:
TDD requires a certain organization for your code. This m... |
I haven't tried it personally (so not sure if it's the 'best' solution), but http://www.codeproject.com/KB/audio-video/WmaCompressor.aspx looks like it should meet your requirements... |
non-correlated sub queries are fine. you should go with what describes the data you're wanting. as has been noted, this likely gets rewritten into the same plan, but isn't guaranteed to! what's more, if table A and B are not 1:1 you will get duplicate tuples from the join query (as the IN clause performs an implicit DI... |
.Net NNTP implementation |
|.net|nntp| |
Is there a good .Net implementation of the NNTP protocol? |
The easiest way would seem to be to hash each line on the way in, storing the hash and the original data, and then compare each new hash with your collection of existing hashes. If you get a positive, you could compare the actual data, to make sure it's not a false positive - though this would be extremely rare, you co... |
I'd write them to a file - and maybe set a monitoring system up to check for changes to the filesize or last-modified date. Webmin is one easy way, but there are more complete software solutions.
If you know its a one-off error, then emailing a notice can be fine. However, with a many hits per minute website, do n... |
iPhone browser tag and optimized web site |
|html|iphone|mobile|mobile-website| |
What is iPhone's browser tag and how iPhone optimized web site is different from a usual mobile web site?
Thanks! |
Remap Left-Ctrl and Caps-Lock so they are where they should be:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] "Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,3a,00,1d,00,1d,00,3a,00,00,00,00,00
|
I've never seen anything. Really, C++ templates are the enabling technology for STL and much of boost, and C doesn't have them. I've seen many C-interface libraries for things like image processing, 3D graphics, networking, etc., but never a real general-purpose library like boost. You can find pieces though - threadin... |
Some years back Javaworld had [an article on determining the size of composite and potentially nested Java objects][1], they basically walk through creating a sizeof() implementation in Java. The approach basically builds on other work where people experimentally identified the size of primitives and typical Java objec... |
The fun thing about optimization is that speed gains are found in the unlikeliest of places.
It's also the reason you need a profiler, rather than guessing where the speed problems are.
I recommend starting with a profiler (`gperf` if you're using GCC) and just start poking around the results of running your appl... |
Nettuts has a great introduction to web-developement for iPhone. You find it [here][1]
This is the specific code you asked for (taken from that article):
<!--#if expr="(${HTTP_USER_AGENT} = /iPhone/)"-->
<!--
place iPhone code in here
-->
<!--#else -->
... |
As earlier answers have stated it evaluates all statements but uses the last one as the value of the expression. Personally I've only found it useful in loop expressions:
for (tmp=0, i = MAX; i > 0; i--) |
Subversion **does** have a [per-user, global ignore setting][1], which sounds like what you want. Look in your .subversion directory (found in your home directory) and locate the Miscellany section of the config file. There should be an entry called global-ignores.
For Windows users, this setting is found in the reg... |
Event.observe(window, 'load', function() {
Event.observe(element, 'click', function() {
alert("Hello World!");
});
});
Of course you need to "select" the elements first in Prototype. |
Since you already declared the sizes, the two declarations are exactly equal. However, if you do not specify the sizes, you can see that the first declaration makes a larger string:
char a[] = "a\0";
char b[] = "a";
printf("%i %i\n", sizeof(a), sizeof(b));
prints
3 2
This is because a ends with ... |
Unless I'm mistaken, the first will initialize 2 chars to 0 (the '\0' and the terminator that's always there, and leave the rest untouched, and the last will initialize only 1 char (the terminator).
|
Nant <copy> and maintain directory structure |
|nant|build-automation| |
How do you use the nant <copy> command and maintain the directory structure? This is what I am doing, but it is copying all the files to a single directory.
<copy todir="..\out">
<fileset>
<includes name="..\src\PrecompiledWeb\**\*" />
</fileset>
</copy>
|
I have used the [pop3 php class](http://www.phpclasses.org/browse/file/3.html) with great success (there is also a [Pear POP3 module](http://pear.php.net/package/Net_POP3)).
Using the pop3 class looks something like this:
require ('pop3.php');
$pop3 = new pop3_class();
$pop3->hostname = MAILHO... |
I have used the [pop3 php class](http://www.phpclasses.org/browse/file/3.html) with great success (there is also a [Pear POP3 module](http://pear.php.net/package/Net_POP3)).
Using the pop3 class looks something like this:
require ('pop3.php');
$pop3 = new pop3_class();
$pop3->hostname = MAILHO... |
Just because the tool (Visual Studio) you are using has decided that each folder needs a new Namespace doesn't mean you do.
I personally tend to leave my "Data" projects as a single Namespace. If I have a subfolder called "Model" I don't want those files in the Something.Data.Model Namespace, I want them in Somethi... |
ctrl + space is the best tool ever in Eclipse. It is the auto-complete feature. It can complete variable names, method declarations, user defined templates, and a ton more.
Go Eclipse. Tons of my code is generated by ctrl + space. |
I would do :
$(document).ready(function() {
$('.validateEmail').keyup(function(){Update_Email_Validate_Status(this)});
});
Then add class='validateEmail' to all your email inputs.
Alternatively look into [Form Validation Plugin][1] i have used this a lot and it is very fl... |
You might be able to pull this off with [Google's Chart API][1]. It is very easy to get started with.
[1]: http://code.google.com/apis/chart/ |
You *can* do this in one line! Use [array_shift()](http://us.php.net/array_shift).
<?php
echo array_shift(i_return_an_array());
function i_return_an_array() {
return array('foo', 'bar', 'baz');
}
When this is executed, it will echo "`foo`". |
If you need control over the XML that gets generated, I recommend taking a look at Betwixt (<http://commons.apache.org/betwixt/>) - it adds a lot of functionality to Apache's digester (Digester is good for building object graphs from XML, but is not so good for generating them).
If you really don't care about the XM... |
Dynamically hiding columns in a NSTableView |
|cocoa| |
I want to dynamically hide/show some of the columns in a NSTableView, based on the data that is going to be displayed - basically, if a column is empty I'd like the column to be hidden. I'm currently populating the table with a controller class as the delegate for the table.
Any ideas? I see that I can set the colum... |
|macos|cocoa| |
This has already been covered but I'm unsure how to link to it. Here is the code snippit:
public static string Ordinal(this int number)
{
var work = number.ToString();
if (number == 11 || number == 12 || number == 13)
{
return work + "th";
}
swi... |
Thanks for the responses so far, but I've found my own solution. I did try a lot of different things, from writing a vbs script as suggested to a standalone program called hstart. hstart worked...but it creates a separate process which I didn't like very much because then I can't kill it in the normal way. But I found ... |
Thanks for the responses so far, but I've found my own solution. I did try a lot of different things, from writing a vbs script as suggested to a standalone program called hstart. hstart worked...but it creates a separate process which I didn't like very much because then I can't kill it in the normal way. But I found ... |
Thanks for the responses so far, but I've found my own solution. I did try a lot of different things, from writing a vbs script as suggested to a standalone program called hstart. hstart worked...but it creates a separate process which I didn't like very much because then I can't kill it in the normal way. But I found ... |
TDD requires you to plan out how your classes will operate before you write code to pass those tests. This is both a plus and a minus.
I find it hard to write tests in a "vacuum" --before any code has been written. In my experience I tend to trip over my tests whenever I inevitably think of something while writing... |
The correct answer involves use of setting the HTTP Cache-Control header on the response. If you want to ensure that they <b>never</b> cache the output, you can do Cache-Control: no-cache.
Other options, if you want limited caching, include setting an expires time and must-revalidate, but these could potentially al... |
The correct answer involves use of setting the HTTP Cache-Control header on the response. If you want to ensure that they <b>never</b> cache the output, you can do Cache-Control: no-cache. This is often used in coordination with no-store as well.
Other options, if you want limited caching, include setting an expir... |
Peter Cooper has a [good list][1] of Ruby tricks. Perhaps my favorite of his is allowing both single items and collections to be enumerated. (That is, treat a non-collection object as a collection containing just that object.) It looks like this:
[*items].each do |item|
# ...
end
[1]: http:... |
If you're writing a native compiled app in Visual C++, there are two methods:
1. Use the `__asm { }` block and write your assembler in there.
2. Write your functions in [MASM][1] assembler, assemble to .obj, and link it as an static library. In your C/C++ code, declare the function with an `extern "C"` declarati... |
Prototyping can be very difficult with TDD - when you're not sure what road you're going to take to a solution, writing the tests up-front can be difficult (other than very broad ones). This can be a pain.
Honestly I don't think that for "core development" for the vast majority of projects there's any real downside... |
I prefer to think of Django applications as reusable modules or components than as "applications".
This helps me encapsulate and decouple certain features from one another, improving re-usability should I decide to share a particular "app" with the community at large, and maintainability.
My general approach is ... |
I have used the [pop3 php class](http://www.phpclasses.org/browse/file/3.html) with great success (there is also a [Pear POP3 module](http://pear.php.net/package/Net_POP3)).
Using the pop3 class looks something like this:
require ('pop3.php');
$pop3 = new pop3_class();
$pop3->hostname = MAILHO... |
problems with mouseout event |
|javascript|html|events|scriptaculous| |
I'm using javascript to hide an image and show some text thats hidden under it. But, when the text is shown if you scroll over it, it fires the mouseout event on the container, that then hides the text and shows the image again, and it just goes into a weird loop.
The html looks like this
<div onmouseover="js... |
Use Visual SVN to setup your server and then use Tortoise to access your repository. Both are free to use and we have been successfully using it for quite sometime now. |
Passing column-values to a table-valued user-defined function is not supported in SQL Server 2000, you can only use constants, so the following (simpler version) would also fail:
SELECT *, (SELECT TOP 1 val FROM dbo.fnSplitStringToInt(usertable.legacyCSVVarcharCol, ','))
FROM usertable
It will work on SQ... |
Use the very cool team foundation server event subscription tool. You can find the tool here: http://www.codeplex.com/tfseventsubscription. Once installed, setup a subscription with the following parameters:
- XPath: PolicyOverrideComment <> ''
- Event: CheckinEvent
|
If you load each frame into an ImageList, you can use a loop to update to each frame.
Example:
> bool runThrobber = true;
> private void AnimateThrobber(TreeNode animatedNode)
> {
> BackgroundWorker bg = new BackgroundWorker();
> bg.DoWork += new DoWorkEventHandl... |
In the simpler case, what happens if a record is deleted from Child and it has a referencing Uncle? That's unspecified, so the constraints fail for that anyway.
If deleting a Child does not delete its Uncles, then what happens instead? Uncle.childid cannot be null.
What you want is one of these three things:
1... |
Public Function TopTen(Club As String, Scores As Range)
Dim i As Long
Dim vaScores As Variant
Dim bLady As Boolean
Dim lCnt As Long
Dim lTotal As Long
vaScores = FilterOnClub(Scores.Value, Club)
vaScores = SortOnScore(vaScores)
For i = LBound(vaScores, 2) To... |
i believe you can counter the overflow with a negative margin. ie
margin: -1em; |
We used [JNBridge][1] for this, and it worked great. It handles Java->.NET and vice versa, all in-proc.
[1]: http://jnbridge.com |
OK, if you're under X11 and you want to get the kbd, you need to do a grab.
If you're not, my only good answer is ncurses from a terminal.
Here's how you grab everything from the keyboard and release again:
<pre>
/* Demo code, needs more error checking, compile
* with "gcc nameofthisfile.c -lX11".
/* extra s... |
I have a client-server app where the client is on a Windows Wobile 6 device, written in C++ and the server is on full Windows and written in C#. Originally, I only needed it to send messages from the client to the server, with the server only ever sending back an acknowledgment that it received the message. Now, I wou... |
|c#|c++|sockets| |
How do you minimize the number of threads used in a tcp server application? |