instruction
stringlengths
0
30k
> Should I build a C# pre-processor? Is there one available that does the simple things I want to do? You can always use the C pre-processor -- C# is close enough, syntax-wise. M4 is also an option.
A neato trick with groupby is run length encoding in one line: [(c,len(list(cgen))) for c,cs in groupby(some_string)] will give you a list of 2-tuples where the first element is the char and the 2nd is the number of repetitions.
If you are running in Vista, you may find that the elevation is getting in the way. You may need to ensure your task runs as a proper administrator, not as a restricted user.
The obvious solution to developers familiar to Java is to use the LinkedList class already provided in java.util. Say, however, you wanted to make your own implementation for some reason. Here is a quick example of a linked list that inserts a new link at the beginning of the list, deletes from the beginning of the lis...
Extending the User model with custom fields in Django
|authentication|django|
What's the best way to extend the User model (bundled with Django's authentication app) with custom fields? I would also possibly like to use the email as the username (for authentication purposes). I've already seen a [few][1] [ways][2] to do it, but can't decide on which one is the best. [1]: http://scottba...
You can also use the GetGenericParameters() method on that type. myNullableObject.GetType().GetGenericParameters()[0] should give you the type of nullable it is (so Guid, Int32, etc.)
In theory, HTML should be as "semantic" as possible - meaning that every element should indicate something about its content. <h1>s should enclose the most important headline; <p>s should surround paragraphs; <em> should indicate emphasis, etc. That way the code makes sense when you - or a screen r...
In theory, HTML should be as "semantic" as possible - meaning that every element should indicate something about its content. <h1>s should enclose the most important headline; <p>s should surround paragraphs; <em> should indicate emphasis, etc. That way the code makes sense when you - or a screen r...
* The **Delphi 7 IDE** for Delphi projects * **VS2005** for .net projects * **Notepad** for any quick stuff (I know it sucks, but it's quick)
I agree with @Glenn for a purely nit-picky point of view. The answer is whatever works for you. All this code takes place in 10 lines (if you include the omitted last curly brace). Nobody is going to get lost and the chance of mistyping is pretty slim (not impossible but very slim). On the other hand, if you used ...
IE6 and XML prolog
|internet-explorer-6|standards|
With an XML prolog like <?xml version="1.0" encoding="iso-8859-1"?> and a Doctype like <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> I can get my page to render as expected. However, in IE7 the same page does not render correctly. (a ...
Cool, thank you Mark, I had forgotten that CreateFile opens things too. I was looking at the volume management API and not seeing how to open things. Here is a little class that wraps things up. It might also be possible/correct to just pass the SafeFileHandle into a FileStream. using System; using S...
While studying for my degree, my dissertation project was the creation of a Java based modular synthesizer, and the University at which I studied saw fit to make my report publicly available: [A Software Based Modular Synthesiser in Java][1] [1]: http://www.dcs.shef.ac.uk/intranet/teaching/projects/archive/ug...
Note that you don't want to persist their session, just their identity. You'll create a fresh session for them when they return to your site. Generally you just assign a GUID to the user, write that to their cookie, then use it to look them up when they come back. Don't use their login name or user ID for the token ...
Make a recursive function that takes the string and an integer offset, and "reads" out an array. That is, have it return an array or string (that it has read) and an integer offset pointing after the array. For example: s = "[[this, is],[a, nested],[array]]" yourFunc(s, 1) # returns ['this', 'is'] a...
#Java 1.6: recursive, memoized (for subsequent calls) private static Map<BigInteger, BigInteger> _results = new HashMap() public static BigInteger factorial(BigInteger n){ if (0 >= n.compareTo(BigInteger.ONE)) return BigInteger.ONE.max(n); if (_results.containsKey(n)) ...
I still write WS-*&ndash;based services. Somewhat surprisingly, I've had less trouble with them when trying to inter-operate with less capable developers. This is because if I send them a WSDL file, they know how to crank it through their tool and get an API they can call, while being blissfully unaware what is happeni...
I think the judicious use of extension methods put interfaces on a more equatable position with (abstract) base classes. <br/> **Versioning.** One advantage base classes have over interfaces is that you can easily add new virtual members in a later version, whereas adding members to an interface will break implemen...
When making and processing requests with JavaScript, I live and breath [JSON](http://json.org/). It's easy to build on the client side and there are tons of parsers for the server side, so both ends get to use their native tongue as much as possible.
Is cron sending emails with logs? If not, pipe the output of cron to a log file. Make sure to redirect STDERR to the log.
I would get the SQL result set to return the list in the first place, you can easily just take the first letter of the required item, and a count. The quickest way would be to do a join on a table of 26 characters (less string manipulation that way). In CF use the count value to ensure that if there is no result yo...
What's the best way to get started with OSGI?
|osgi|java|spring|
I'm interested in using [OSGi][1] in my applications. We're a Java shop and we use Spring pretty extensively, so I'm leaning toward using [Spring Dynamic Modules for OSGi(tm) Service Platforms][2]. I'm looking for a good way to incorporate a little bit of OSGi into an application as a trial. What makes a module/service...
I'm interested in using [OSGi][1] in my applications. We're a Java shop and we use Spring pretty extensively, so I'm leaning toward using [Spring Dynamic Modules for OSGi(tm) Service Platforms][2]. I'm looking for a good way to incorporate a little bit of OSGi into an application as a trial. What makes a module/service...
|java|spring|osgi|
What makes a module/service/bit of application functionality a particularly good candidate for an OSGi module? I'm interested in using [OSGi][1] in my applications. We're a Java shop and we use Spring pretty extensively, so I'm leaning toward using [Spring Dynamic Modules for OSGi(tm) Service Platforms][2]. I'm loo...
|c#|string|
In C# what is the difference between String and string? (note the case) Also, what are the guidelines for the use of each?
Is your scripting language bytecode generating? Does it generate debug metadata? If so, bytecode instrumentation is probably the way to go. In fact existing tools like will probably work; perhaps with minimal modification (the typical problem is the tools are written to work with Java and assume com.foo.Bar.class corre...
If you are interested in DSLs, [Jeff Moser][1] has written some great articles about them (and the 'meta' frame of mind you need) [here,][2] [here,][3] and [here][4] on his blog. [1]: http://www.moserware.com/ [2]: http://www.moserware.com/2008/04/towards-moores-law-software-part-3-of-3.html [3]: http://ww...
'System.String' is THE .net string class - in C# 'string' is an alias for System.String - so in use they are the same. As for guidelines I wouldn't get too bogged down and just use whichever you feel like - there are more important things in life and the code is going to be the same anyway. If you find yourselves...
Following up on [svrist's answer,][1] depending on your shell, the 2>&1 should go *after* > /dev/null or you will still see the output from stderr. The following will silence both stdout and stderr: 59 23 * * * /usr/sbin/myscript > /dev/null 2>&1 The following silences stdout, but stderr will still appear ...
Lower case string is an alias for System.String. They are the same in C#. There's a debate over whether you should use the System types (System.Int32, System.String, etc.) types or the C# aliases (int, string, etc). I personally believe you should use the C# aliases, but that's just my personal preference.
you will with the above response recieve email with any text written to stderr. Some people redirect that away too, and make sure that the script writes a log instead. > ... 2>&1 ...
you will with the above response recieve email with any text written to stderr. Some people redirect that away too, and make sure that the script writes a log instead. ... 2>&1 ....
You have an ascending list of numbers, what is the most efficient algorithm you can think of to get the list of sums of every two numbers in that list. Duplicates in the resulting list are irrelevant, you can remove them or avoid them if you like.
|language-agnostic|algorithm|
You have an ascending list of numbers, what is the most efficient algorithm you can think of to get the ascending list of sums of every two numbers in that list. Duplicates in the resulting list are irrelevant, you can remove them or avoid them if you like. To be clear, I'm interested in the algorithm. Feel free t...
I've seen it done in a kind of iffy, but pretty reliable way. Basically, an element is set to use a specific font and a string is set to that element. If the font set for the element does not exist, it takes the font of the parent element. So, what they do is measure the width of the rendered string. If it matches ...
How do I most elegantly express left join with aggregate SQL as LINQ query
|linq|c#|
SQL: select u.id, u.name, isnull(MAX(h.dateCol), '1900-01-01') dateColWithDefault from universe u left join history h on u.id=h.id and h.dateCol<GETDATE()-1 group by u.Id, u.name
|c#|linq|
A solution (albeit one that defers handling of the null value to the code) could be DateTime yesterday = DateTime.Now.Date.AddDays(-1); var collection= from u in db.Universe select new { u.id, u.name, MaxDate =(DateTime?) ( ...
A solution (albeit one that defers handling of the null value to the code) could be: DateTime yesterday = DateTime.Now.Date.AddDays(-1); var collection= from u in db.Universe select new { u.id, u.name, MaxDate =(DateTime?) ( ...
You're looking for Sandcastle Project Page: <http://www.codeplex.com/Sandcastle/Release/ProjectReleases.aspx> Blog: <http://blogs.msdn.com/sandcastle/default.aspx> NDoc (<http://ndoc.sourceforge.net/>) used to be the tool of choice, but support has all but stopped.
Have a look at [Sandcastle][1], which does exactly that. [1]: http://blogs.msdn.com/sandcastle/
The obvious solution to developers familiar to Java is to use the **LinkedList** class already provided in **java.util**. Say, however, you wanted to make your own implementation for some reason. Here is a quick example of a linked list that inserts a new link at the beginning of the list, deletes from the beginning of...
The obvious solution to developers familiar to Java is to use the **LinkedList** class already provided in **java.util**. Say, however, you wanted to make your own implementation for some reason. Here is a quick example of a linked list that inserts a new link at the beginning of the list, deletes from the beginning of...
This seems like a perfect scenario for using JSON as a serialization format for the server. If you study a few [examples][1] it is not too difficult to understand. E.g. [1]: http://www.json.org/example.html
The unit tester for VS2008 is only for .NET code as far as I know. I used CppUnit on Vs2005 and found it to be pretty good. As far as I remember, the setup was relatively painless, just make sure that in your testing projects the linker (Linker->Input->Additional Dependencies) includes cppunitd.lib. Then, `#...
Best practice on this dictates that if you are not planning to use the stored data for anything other than recreating the form then the best method is to send it back in some sort of native format (As mentioned above) With this then you can just load the data back in and requires the least processing of any method.
There's a lot of people who will push JSON. It's a lot lighter weight than XML. Personally, I find XML to be a little more standard though. You'll have trouble finding a server side technology that doesn't support XML. And Javascript supports it just fine also. You could also go a completely different route. Sinc...
My RSS feeds have served me well- I found that Javascript roguelike! It's called [The Tombs of Asciiroth](http://www.icculus.org/asciiroth/).
when you throw the error your error handler can then email the user, or better if the list is massive, add the error state to the workflow item - i think this is default functionality though as the error would be mentioned there. http://www.sharepointsecurity.com/blog/sharepoint/sharepoint-2007-development/fault-han...
To generate the navigation bar, you could do something like this: <cfoutput> <cfloop from="#asc('A')#" to="#asc('Z')#" index="i"> <a href="###chr(i)#">#chr(i)#</a> <cfif asc('Z') neq i>|</cfif> </cfloop> </cfoutput> (CFLOOP doesn't work on characters, so you have to convert to ascii...
The Red Gate product is good...but not perfect. I found that I did better when I wrote my own tools to generate the data. I use it when I want to generate say Customers...but it's not great if you wanted to simulate randomness that customers might engage in like creating orders...some with one item some with multip...
How do I make an HTML page print in landscape when the user selects 'print'?
|html|print|landscape|portrait|
We generate web pages that should always be printed in landscape mode. Web browser print dialogs default to portrait, so for every print job the user has to manually select landscape. It's minor, but would be nice for the user if we can remove this unnecessary step. Thanks in advance to all respondents.
|html|printing|landscape|portrait|
In response to [Christian Lescuyer](#37147)'s post, you also need to enable the "svn:keywords" property on the file with that line in it. Subversion won't bother looking in your files for keywords like $Revision$ unless that property is set. Also, if using PHP like in his example, you may want to put $Revision$ insi...
Consider taking a look at an aspect-oriented solution like [PostSharp][1], which injects code after the fact based on custom attributes. It's the opposite of a precompiler but can give you the sort of functionality you're looking for (PropertyChanged notifications etc). [1]: http://www.postsharp.org/
What is the best way to get OS specific information in Java?
|java|
Specifically getting on Windows the "..\Documents & Settings/All Users, the current users My Documents dirctory, and basicaly any path that needs the front end to be dynamically derived based on the OS your software is running on.
1. Specifically getting on Windows the "..\Documents & Settings\All Users, basicaly any path that needs the front end to be dynamically derived based on the OS your software is running on. **(Now I need the answer to this)** 2. the current users My Documents dirctory **(okay this has been answered)** and basicaly...
While not an instant answer for you, I found the book [Learning WCF][1] very useful; in it there's a small section on versioning (which is similar to Craig McMurtry's advice posted by Espo). If you're looking for a general intro book, it's very good. Her website has lots of good stuff too: [Das Blonde][2] [1]:...
While not an instant answer for you, I found the book [Learning WCF][1] very useful; in it there's a small section on versioning (which is similar to Craig McMurtry's advice posted by Espo). If you're looking for a general intro book, it's very good. Her website has lots of good stuff too: [Das Blonde][2] **Edit:*...
One other way to do it is to use: String.valueOf(myInt); This method is overloaded for every primitive type and `Object`. This way you don't even have to think about the type you're using. Implementations of the method will call the appropriate method of the given type for you, e.g. `Integer.toString(myIn...
You can use ImageMagick's convert utility for this, see some examples in http://studio.imagemagick.org/pipermail/magick-users/2002-May/002636.html
I think [Modern Compiler Implementation in ML][1] is the best introductory compiler writing text. There's a [Java version][2] and a [C version][3] too, either of which might be more accessible given your languages background. The book packs a lot of useful basic material (scanning and parsing, semantic analysis, activa...
Regarding security, **you cannot trust what comes from the client**: - The visitor can see all your code (HTML and Javascript, not PHP) and try stuff - The visitor may not even use a browser; it's trivially easy to send a request with a script This means hiding the buttons is good User Interface design (beca...
You should look at the `<Framework/FrameworkErrors.h>` header for whatever framework the method you're using that's returning an error comes from. For example, an `NSError` in the Cocoa domain that you get from a method in the Foundation framework will have its `code` property described in the `<Foundation/Foundatio...
What's a good algorithm to generate a maze?
|algorithm|maze|
Say you want a simple maze on an N by M grid, with one path through, and a good number of dead ends, but that looks "right" (i.e. like someone made it by hand without too many little tiny dead ends and all that). Is there a known way to do this?
> 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.
Strangely enough, by slightly changing the 'canonical' rules and starting from a random configuration, [Conway's Game of Life][1] (I don't know why my Wikipedia link is not working!) seems to generate pretty nice mazes! (I don't remember the exact rule, but it's a very simple modification that tends to 'densify' the...
There used to be some relatively cheap developers network which we used to belong to before the Novell questions all whithered and died away (famous last words, now I bet we will get one tomorrow), there is never any substitute for having the software / hardware, the only alternative is to write a test program and get ...
Returning a tuple is the usual way to do this in Python.
Return a tuple. def f(x): # do stuff return (True, modified_string) success, modified_string = f(something)
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 } ...
def f(in_str): out_str = in_string.upper() return True, out_str # Creates tuple automatically succeeded, b = f("a") # Automatic tuple unpacking
I don't know whether this would work in DB2, but I'll tell you how I'd do this in SQL Server. I *think* the way MSSQL does this is ANSI standard, though the specific collation strings may differ. Anyway, if you can do this without trashing the rest of your application -- are there other places where the "name" column...
I don't know whether this would work in DB2, but I'll tell you how I'd do this in SQL Server. I *think* the way MSSQL does this is ANSI standard, though the specific collation strings may differ. Anyway, if you can do this without trashing the rest of your application -- are there other places where the "name" column...
I've been working in the address processing domain for about 5 years now, and there really is no silver bullet. The correct solution is going to depend on the value of the data. If it's not very valuable, throw it through a parser as the other answers suggest. If it's even somewhat valuable you'll definitely need to ha...
The Equals method is intended to compare references. So it should not be overriden to change its behaviour. You should create a new method to test for equivalence in different instances if you need to (or use the CompareTo method in some .NET classes)
Need help writing a regex statement. [PHP]
|php|regex|regularexpression|regular-expression|
With an XML prolog like <pre> ? xml version="1.0" encoding="iso-8859-1"? > </pre> and a Doctype like <pre> !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> </pre> I can get my page to render as expected. However, in IE7 the same page does...
<(?!\/?a(?=>|\s.*>))\/?.*?> Try this. Had something similar for p tags. Worked for them so don't see why not. Uses negative lookahead to check that it doesn't match a (prefixed with an optional / character) where (using positive lookahead) a (with optional / prefix) is followed by a > or a space, stuff and th...
This isn't answering your question, but I don't think "DefaultValue" means what you think it means. It doesn't set a default value for your property. See [MSDN][1] and [this question][2] for more details. [1]: http://support.microsoft.com/kb/311339 [2]: http://stackoverflow.com/questions/43738/defaultvalu...
Ok, so let me see if I got this straight. You want to take a column that is currently computed and make it a plain-jane data column. Normally this would drop the column but you want to keep the data in the column. 1. Make a new table with the primary key columns from your source table and the generated column. 2....
Not that I know of but here is something you can do add another column to the table update that column with the values of the computed column then drop the computed column