instruction stringlengths 0 30k ⌀ |
|---|
Are non-generic collections in .NET obsolete? |
|.net|collections| |
This is actually a harder problem than it sounds like, mainly because many mathematically-correct solutions will fail to actually allow you to hit all the possibilities (more on this below).
First, here are some easy-to-implement, correct-if-you-have-a-truly-random-number generator:
(0) Kyle's answer, which is O(... |
This is actually a harder problem than it sounds like, mainly because many mathematically-correct solutions will fail to actually allow you to hit all the possibilities (more on this below).
First, here are some easy-to-implement, correct-if-you-have-a-truly-random-number generator:
(0) Kyle's answer, which is O(... |
Another one from Delphi, which I think is a little more rigorous than the other Delphi example submitted. This can easily turn into a golfing match, but I've tried to make mine readable.
*Edit0: I was curious about the performance characteristics, so I did a little test. On my machine, I ran this function against ... |
Another one from Delphi, which I think is a little more rigorous than the other Delphi example submitted. This can easily turn into a golfing match, but I've tried to make mine readable.
*Edit0: I was curious about the performance characteristics, so I did a little test. On my machine, I ran this function against ... |
This Java code should work inside a **boolean** method:
String test = "madam";
if(!(test.length() % 2 == 0)) {
int mid = test.length() / 2;
for(int i = 0; i < mid; i++) {
if(!(test.substring(i).equalsIgnoreCase(test.substring(test.length() - 1 - i)))) {
return... |
It sounds like you are causing a redirect to happen. You aren't by chance doing a Response.Redirect in order to "get back" to the original page? This would cause the functionality you describe. You would first get the Postback from the Previous button to leave the page, and then you would get a fresh Request (IsPostbac... |
How do you pasted multiple tabed lines into Vi |
|vi|paste| |
I want paste into a file open in Vi something I have cut from my desktop.
But if I paste the tabs embed on top of each other across the page.
I think it is some sort of visual mode change but can find the command.
thanks |
How do you paste multiple tabbed lines into Vi? |
I want to paste something I have cut from my desktop into a file open in Vi.
But if I paste the tabs embed on top of each other across the page.
I think it is some sort of visual mode change but can't find the command. |
|vi| |
I DID have a response.redirect i was using but i removed it. I suppose i can do a thorough check to make sure i didnt have another one anywhere. I will try the autoeventwireup property as well. |
See the [question][1] about 'Mutex' in C#. And then look at [these][2] [two][3] questions regarding use of the 'lock(Object)' statement specifically.
[1]: http://stackoverflow.com/questions/34524/what-is-a-mutex
[2]: http://stackoverflow.com/questions/42505/thread-safe-use-of-a-singletons-members
[3]: http... |
I just noticed that there even are some nice implementations.
For example in [Audacity][1]:<br/>
*Analyze* → *Find Clipping…*
[1]: http://audacity.sourceforge.net/ |
MS Access ADP Autonumber |
|access|msaccess|sqlserver2000| |
I am getting the following error in an MS Access ADP when trying to add a record on a form linked to a MS SQL Server 2000 table:
> Run-time error '31004':
>
> The value of an (AutoNumber) field
> cannot be retrived prior to being
> saved.
>
> Please save the record that contains
> the (AutoNumber) field pri... |
|sql-server|ms-access| |
Have you heard of [Pecha-Kucha?][1]
> The idea behind Pecha Kucha is to keep
> presentations concise, the interest
> level up and to have many presenters
> sharing their ideas within the course
> of one night. Therefore the 20x20
> Pecha Kucha format was created: each
> presenter is allowed a slideshow of 20
... |
ditto Lisp,.. or scheme
Even if you don't ever use it, it's handy. I only *really* got template programming after learning it.
Another one is prolog. it puts you in a non sequential mindset.
|
**Private Methods**
It's possible to have private methods for a class.
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
// A private method only visible from within this constructor
function calcFullName() {
return f... |
**Private Methods**
An object can have private methods.
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
// A private method only visible from within this constructor
function calcFullName() {
return firstName + " " ... |
Since you are already into C++, next "logical" level of abstraction would be [managed C++][1] or managed extensions for C++..this will get you a step in the big world of .Net framework..
*One of the areas that MC++ excels in, and is in fact unique in amongst the .NET languages, is the ability to take an existing unm... |
Since you are already into C++, next step would be to learn .Net through [managed C++][1] or managed extensions for C++..this will get you a step in the big world of .Net framework..Once you understand the framework, makes it more comfortable to learn other .Net languages like C#, VB.Net etc.
*One of the areas that ... |
The perfect solution for this is to use [log4net][1] with a console appender and a file appender. There are many other appenders available as well. It also allows you to turn the different appenders off and on at runtime.
[1]: http://logging.apache.org/log4net/ |
This Java code should work inside a **boolean** method:
private static boolean doPal(String test) {
boolean palindrome = true;
if(!(test.length() % 2 == 0)) {
int mid = test.length() / 2;
for(int i = 0; i < mid; i++) {
if((test.substring(i).equalsI... |
This Java code should work inside a **boolean** method:
private static boolean doPal(String test) {
if(test.length() % 2 == 0) {
return false;
}
for(int i = 0; i < test.length() / 2; i++) {
if(test.charAt(i) != test.charAt(test.length() - 1 - i)) {
... |
This Java code should work inside a **boolean** method:
private static boolean doPal(String test) {
for(int i = 0; i < test.length() / 2; i++) {
if(test.charAt(i) != test.charAt(test.length() - 1 - i)) {
return false;
}
}
return true;
} |
This Java code should work inside a **boolean** method:
**Note**: You only need to check the first half of the characters with the back half, otherwise you are overlapping and doubling the amount of checks that need to be made.
private static boolean doPal(String test) {
for(int i = 0; i < test.lengt... |
UPDATE: You can use [Cumulative update package 5][1] for SQL Server 2005 Service Pack 25 SP2 to connect to 2008.
FIX:
50002151 946127 (http://support.microsoft.com/kb/946127/) FIX: You may experience problems when you use SQL Server Management Studio in SQL Server 2005 to connect to an instance of SQL Server 2008
... |
UPDATE: You can use [Cumulative update package 5][1] for SQL Server 2005 Service Pack 2 to connect to 2008.
FIX:
50002151 946127 (http://support.microsoft.com/kb/946127/) FIX: You may experience problems when you use SQL Server Management Studio in SQL Server 2005 to connect to an instance of SQL Server 2008
... |
We created our own FilterCriteria object that is kind of a *black-box* dynamic query builder. It has collection properties for SelectClause, WhereClause, GroupByClause and OrderByClause. It also contains a properties for CommandText, CommandType, and MaximumRecords.
We then jut pass our FilterCriteria object to ou... |
SELECT ELAPSED_TIME_MIN,SUBSTR(AUTHID,1,10) AS AUTH_ID,
AGENT_ID, APPL_STATUS,SUBSTR(STMT_TEXT,1,20) AS SQL_TEXT
FROM SYSIBMADM.LONG_RUNNING_SQL
WHERE ELAPSED_TIME_MIN > 0
ORDER BY ELAPSED_TIME_MIN DESC
Credit: [SQL to View Long Running Queries ][1]
[1]: http://it.toolbox.com/blogs/db... |
Put differently:
Is there a good reason to choose a loosely-typed collection over a type-safe one (HashTable vs. Dictionary)? Are they still there only for compatibility?
As far as I understand, generic collections not only are type-safe, but their performance is better. |
|.net|generics|collections| |
Put differently:
Is there a good reason to choose a loosely-typed collection over a type-safe one (HashTable vs. Dictionary)? Are they still there only for compatibility?
As far as I understand, generic collections not only are type-safe, but their performance is better.
<hr>
Here's a comprehensive article ... |
Enums are supposed to represent the enumeration of all possible values, so extending rather does go against the idea.
However, what you can do in Java (and presumably C++0x) is have an interface instead of a enum class. Then put you standard values in an enum that implements the feature. Obviously you don't get to u... |
You must architect your solution to be updatable, so that you can handle unknown situations when they crop up. Create an interface for parsers that contains not only methods for parsing the emails and returning results in a standard format, but also for examining the email to determine if the parser will execute.
W... |
Perhaps a bit more theoretical. Mathematically, collections in C++ can be described as a half-open interval of iterators, namely one iterator pointing to the start of the collection and one iterator pointing *just behind* the last element.
This convention opens up a host of possibilities. The way algorithms work in ... |
Trying something really foreign like Haskell will allow you to think in different ways. It also helps you to think recursively. C++ has recursion but it infiltrates many more parts of functional languages. |
As usual the answer is: it depends. Different classes implement IDisposable in different ways, and it's up to you to do the necessary research.
As far as SqlClient goes, the recommended practice is to do the following:
using (SqlConnection conn = /* Create new instance using your favorite method */)
{
... |
As usual the answer is: it depends. Different classes implement IDisposable in different ways, and it's up to you to do the necessary research.
As far as SqlClient goes, the recommended practice is to do the following:
using (SqlConnection conn = /* Create new instance using your favorite method */)
{
... |
I use a utility function I wrote. Its name is somewhat misleading because it kind of implies it might be a random item or something like that.
def anyitem(iterable):
try:
return iter(iterable).next()
except StopIteration:
return None
|
How to implement draggable tab using Java Swing? |
|java|user-interface|swing|tab| |
How do I implement a draggable tab using Java Swing? Instead of the static JTabbedPane I would like to drag-and-drop a tab to different position to rearrange the tabs. |
As Frank Kreuger commented, go with a GUID generator.
Like [this one][1]
[1]: http://www.phpclasses.org/browse/package/1738.html |
You can use [output buffering][1] to selectively save parts of your output (those you want to cache) and display them to the next user if it hasn't been long enough. This way you're still rendering other parts of the page on-the-fly (e.g., customizable boxes, personal information).
[1]: http://uk3.php.net/manual... |
Figured I'd post what I finally went with - WinSCP - http://winscp.net
Connects via GUI to an SFTP server + supports Local/Remote/Both synchronization + scriptable with command-line/batch interface. |
How I see it:
you'd want to build a table that maps unordered sets of letters to lists words i.e. go through the dictionary so you'd wind up with, say
lettermap[set(a,e,d,f)] = { "deaf", "fade" }
then from your starting word, you find the set of letters:
astronomers => (a,e,m,n,o,o,r,r,s,s,t)
... |
By default, any content between tags for a custom control is added as a child control. This can be intercepted in an **AddParsedSubObject()** override for filtering or additional parsing (e.g., of text content in LiteralControls):
protected override void AddParsedSubObject(object obj)
{ var literal... |
It depends on whether or not you're in the debugger. _Really._ Well, sort of.
Parentheses come first, of course. Then comparisons (>, <, =, etc). Then the logical operators. The trick is that the order of _execution_ is not defined. That means given the following expression:
If A < B And B < C Then
y... |
Have you tried [PowerShell][1] rather than old cmd.exe.
[1]: http://en.wikipedia.org/wiki/PowerShell |
Aside from the lowsrc option, I've also used a `background-image` on the `img`'s container. |
If we're looking for numbers and simple words, many correct answers have been given.
However, if we're looking for what we generally see as palindromes in written language (e.g., "A dog, a panic, in a pagoda!"), the correct answer would be to iterate starting from both ends of the sentence, *skipping non-alphanumeri... |
Shuffle alot, and then record the outcomes (if im reading this correctly). I remember seeing comparisons of "random number generators". They just test it over and over, then graph the results.
If it is truly random the graph will be mostly even. |
I've seen "Silverlight only" websites at Microsoft and they are pretty impressive. But again, the demos were there to exploit the full potential of what Silverlight can do. The moment you need something different you may be out of luck. I don't see Silverlight like Flash except in the way they are installed/seen. But t... |
I can tell you that XAML serialization of collections rely on them implementing either IList or IDictionary, so non-generic collections are going to be with us for some time to come. |
I would suggest another addition
SELECT "group" type, name
FROM groups
WHERE UPPER(name) LIKE UPPER("%$text%")
UNION ALL
SELECT "user" type, name
FROM users
WHERE UPPER(name) LIKE UPPER("%$text%")
You could convert $text to upper case first or do just do it in the que... |
What can cause a reduction in frame rate when upgrading a graphics card? |
|c++|hardware|directx| |
We have a two-screen DirectX application that previously ran at a consistent 60 FPS (the monitors' sync rate) using a NVIDIA 8400GS (256MB). However, when we swapped out the card for one with 512 MB of RAM the frame rate struggles to get above 40 FPS. (It only gets this high because we're using triple-buffering.) The t... |
It depends on what you're parsing. For anything beyond what Regex can handle, I've been using [ANTLR][1]. Before you jump into recursive descent parsing for the first time, I would research how they work, before attempting to use a framework like this one. If you subscribe to MSDN Magazine, check the Feb 2008 issue ... |
|java|user-interface|swing|tabs| |
How do I implement a draggable tab using Java Swing? Instead of the static JTabbedPane I would like to drag-and-drop a tab to different position to rearrange the tabs.
**EDIT**: [The Java Tutorials - Drag and Drop and Data Transfer][1].
[1]: http://java.sun.com/docs/books/tutorial/uiswing/dnd/index.html |
The "more correct way" would be:
XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "true"),
new XElement(ns + "urlset",
new XElement(ns + "url",
new XElement(ns + "loc", "http://www.example.com/page"),
new XElement(ns + "lastmod", "2008-09-14"))));
Same as your code, ... |
The best way to start a project... |
|project-management|projects|project-planning| |
When you are starting a personal programming project, what is your first step? I'm trying to start a project thats just an idea at the moment. I get lots of these and I dive right into the code and after a while just completely lose interest and or just forget about the project.
When you are starting, what is your f... |
|project-management|projects|project-planning| |
_This would-be quick advice became a long answer. Sorry._
As tyler pointed out in his nice answer, calling `Dispose()` is a great programming practice. This is because this method is supposed to "rally together" all the resource-freeing needed so there are no unneeded open resources. If you wrote some text to a file... |
Is it just the iPhone simulator that is restricted to intel only Mac's? |
|iphone|xcode|macos| |
I have read that the iPhone SDK (part of xcode 3) is restricted to Mac's with the intel chipset. Does this restriction apply to only the simulator part of the SDK or the complete shebang? |
I have read that the iPhone SDK (part of xcode 3) is restricted to Mac's with the intel chipset. Does this restriction apply to only the simulator part of the SDK or the complete shebang?
I have a Powerbook g4 running Leopard and would very much like to do dev on it rather than fork out for a new machine. |
|macos|iphone|xcode| |
I have read that the iPhone SDK (part of xcode 3) is restricted to Mac's with the intel chipset. Does this restriction apply to only the simulator part of the SDK or the complete shebang?
I have a Powerbook g4 running Leopard and would very much like to do dev on it rather than fork out for a new machine.
It is a... |
The only option probably is to have them not indexed by spotlight as from some reason you cannot do negative searches. You can search for files with specifix file extension, but you cannot not search for ones that don't match.
You could try making those files invisible for Finder, Spotlight won't index invisible fil... |
The only thing I would say is write your application so that it can be deployed on a cluster from the very start. Anything above that is a premature optimisation. Your first job should be getting enough users to have a scaling problem.
Build the code as simple as you can first, then profile the system second and op... |
Warning: I'm not a java hacker, so YMMV but...
The problem with using a list of "properties" is that you need a lot of discipline. Every time you add a string that should be output to the user you will need to open your properties file, look to see if that string (or something roughly equivalent to it) is already in... |
Using a plugin for your website makes it slow, and requires the user to have the plugin installed. Silverlight for instance rules out all Linux user. Also, since Silverlight is pretty new, there is no telling how committed Microsoft will be to keep the platform alive if it doesn't pick up soon.
I'd stick to plain ol... |
For ultimate reponsiveness, don't allow your app to be shutdown.
The first method is to make sure that it's incredibly popular so that there's always someone using it.
Alternatively, fetching a tiny keep-alive page from somewhere else as a scheduled activity can be used to keep your site 'hot'. |
Ok, this is embarrasing.
A collegue had added a trigger to that table a while ago, and the trigger had a bug. Although he had fixed the bug, the trigger had never been recreated for that table.
So the server was actually doing nothing, it just did it a huge number of times.
Oh well...
Thanks for the eyeball... |
I'm quite interested in this question myself. I've used the [Cygwin Setup guide][1] to get set up, but it doesn't get you all the way. One thing that I learned from it, though, is that it recommends leaving the setup.exe in the directory with Cygwin so that you can quickly add packages, since apt-get apparently doesn't... |
Pilif answer was good, and I have lots of experience with this too, but I'd like to add something more:
Remember that if you start yourapp.exe, then the "updater" will try to overwrite yourapp.exe with the newest version. Depending upon your operating system and programming environment (you've mentioned C++/QT, I ha... |
C++ library (the part formerly known as STL) iterators are designed to be compatible with pointers. Java, without pointer arithmetic, had the freedom to be more programmer-friendly.
In C++ you end up having to use a pair of iterators. In Java you either use an iterator or a collection. Iterators are supposed to be t... |
asp.net mvc, ajax and progressive enhancement |
|asp.net-mvc|jquery|ajax| |
Maybe they are alluding to the difference between duck typing and class hierarchies?
*if it walks like a duck and quacks like a duck, just pretend it's a duck and kick it.*
In C#, Java etc. the compiler fusses a lot about: Are you aloud to do this operation on that object?
Object Oriented vs. Class Oriented co... |
Maybe they are alluding to the difference between duck typing and class hierarchies?
*if it walks like a duck and quacks like a duck, just pretend it's a duck and kick it.*
In C#, Java etc. the compiler fusses a lot about: Are you aloud to do this operation on that object?
Object Oriented vs. Class Oriented co... |
Ctrl T (ReSharper, Goto, type) will open a class file for you.
Looks like Ctrl Shift T opens files. |
> **The search page appends "&terms=" to the query string for highlighting, so
> it messes it up.**
Only other option is a regex replace. If you *know for sure* that &terms is in the middle of the collection somewhere leave the trailing & in the regex, if you *know for sure* it's on the end then drop the trailing &... |
Depending on your keymap, Ctrl+Shift+N will open any file in the solution, or Ctrl+N will open any type. |
There are three pillars of OOP
1. Encapsulation
2. Inheritance
3. Polymorphism
If a language can do those three things it is a OOP language.
I am pretty sure the argument of language X does OOP better than language A will go on forever. |
I don't think AuthKit is actively maintained anymore. It does use the Paste (<http://pythonpaste.org>) libs though for things like HTTP Basic/Digest authentication. I would probably go ahead and take a look at the source for some inspiration and then use the Paste tools if you want to use HTTP authentication.
There... |
The duck typing comments here are more attributing to the fact that Ruby and Python are more *dynamic* than C#. It doesn't really have anything to do with it's OO Nature.
What (I think) Bellware meant by that is that in Ruby, everything is an object. Even a class. A class definition is an instance of an object. ... |
If we're looking for numbers and simple words, many correct answers have been given.
However, if we're looking for what we generally see as palindromes in written language (e.g., "A dog, a panic, in a pagoda!"), the correct answer would be to iterate starting from both ends of the sentence, *skipping non-alphanumeri... |