instruction stringlengths 0 30k ⌀ |
|---|
The general principle is that you want to use whatever HTML elements best convey the semantic content that you are intending and then rely on css to visually represent that semantic content. Following that principle buys a lot of intrinsic benefits including easier site-general visual changes, search engine optimizatio... |
Here is how to get a list of current printers and the default one if there is one set as the default.
Also note: getting zero for the default printer name length is valid if the user has no printers or has not set one as default.
Also being able to handle long printer names should be supported so calling GetDefa... |
I would suggest to look at the IDataErrorInfo interface on your business object. Also have a look at this article: [Self Validating Text Box][1]
[1]: http://www.codeproject.com/KB/WPF/WPF_SelfValidatingTextBox.aspx |
Testing Abstract Class Concrete Methods |
|c#|.net|unit-testing| |
How would design and organize tests for the concrete methods of an abstract class? Specifically in .NET. |
Run the potential GUID though a RegEx or some custom code that does a sanity check to ensure the strig at least looks like a GUID and consists only of valid characters (and maybe that it seems to fit the overall format). If it doesn't pass the sanity check return an error - that'll probably weed out the vast majority ... |
Run the potential GUID though a RegEx or some custom code that does a sanity check to ensure the strig at least looks like a GUID and consists only of valid characters (and maybe that it seems to fit the overall format). If it doesn't pass the sanity check return an error - that'll probably weed out the vast majority ... |
Use a good [app launcher][1] such as Quicksilver or Launchy to cut down on the time it takes to perform simple tasks. They're usually not scriptable, but they do let you do each step faster.
[1]: http://stackoverflow.com/questions/107383/what-is-the-best-windows-program-launcher |
How would you format multiple properties when using Property Initialization? (.Net) |
|.net|coding-style|formatting|convention| |
For example:
root.Nodes.Add(new TNode() { Foo1 = bar1, Foo2 = bar2, Foo3 = bar3 });
or:
root.Nodes.Add(new TNode() { Foo1 = bar1,
Foo2 = bar2,
Foo3 = bar3 });
|
I always thought that
foreach my $item (@array) { $hash{$item} = 1 }
was at least nice and readable / maintainable.
|
Most of the time, I use python. Python requires you to use self.foo in order to access the attribute foo of the instance of the current class. That way, the problem of confusing local variables, parameters and attributes of the instance you work on is solved.
Generally, I like this approach, even though I dislike be... |
The main point I see reg. using SVN as central repository for binary files, is that if those files are of any reasonable size, they will take some time to be synced over the net.
So if you don't want to spend time waiting for your files coming in over the net, here the building blocks for an other mirroring solution:
... |
In Perl:
tr/a-z0-9//s;
Example:
$ perl -E'@a = (aaabbb, 14442345); for(@a) { tr/a-z0-9//s; say }'
ab
142345
If Java has no `tr` analog then:
s/(.)\1+/$1/sg;
#NOTE: `s` modifier. It takes into account consecutive newlines.
Example:
$ perl -E'@a = (aaabbb, 1444234... |
Writing shell scripts (Applescript, Bash, PowerShell, etc..) is a great way to automate most mundane tasks, assuming your apps are scriptable, as well as pick up a new language. As you venture further into this practice, you'll find yourself more and more annoyed at the apps you use that aren't scriptable, to the poin... |
The [GeSHi text highlighter][1] is pretty awesome. If you're using WordPress, [there's a plugin][2] for you already
[1]: http://qbnz.com/highlighter/
[2]: http://wordpress.org/extend/plugins/wp-syntax/ |
Depends on which platform you are running on (Windows/Linux/Mac/...?)
As a platform independent way, I use a personal subversion server. All the valuables are there, so if I lose one of the machines, a simple 'svn checkout' will take things back. This takes some initial work, though, and requires discipline. It migh... |
One approach is to take the example from the second chapter of the [dragon book](http://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1222064707&sr=8-2) which explains how to write a parser to convert from infix to postfix notation, and reverse it. |
A simple Google query reveals http://code.google.com/p/syntaxhighlighter/
From initial looks it seems pretty good. Entirly JS based so can be implemented independent of the server side language used. |
If you are using Qt you should have a look for [QFlags][1].
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
[1]: http://doc.trolltech.com/4.3/qflags.html#details "QFlags" |
It is often useful to create a code generator that generates code from a specification - usually one that has regular tabular rules. It reduces the chance of introducing an error via a typo or omission. |
I think the answer here is in the `MultiView` control, so that for example the dropdown switches between different views in the multi-view. |
I think the answer here is in the `MultiView` control, so that for example the dropdown switches between different views in the multi-view.
You can probably even data-bind the current view property of the multiview to the value of the dropdown! |
[Syntax Highlighter][1] is used by [wordpress][2] and produces nice results.
[1]: http://code.google.com/p/syntaxhighlighter/
[2]: http://wordpress.com/ |
Here is nice example of doing this. It's using DirectShow.Net (http://directshownet.sourceforge.net/), which is propably better than using "clipboard" :D.
http://www.codeproject.com/KB/audio-video/WebcamUsingDirectShowNET.aspx
|
I went this way based on some of the tidbits provided. It could be made more robust to handle multiple generic arguments on the interface.... but I didn't need it to ;)
private static Type SafeGetSingleGenericParameter(Type type, Type interfaceType)
{
if (!interfaceType.IsGenericType || int... |
The basic problem is this: for a long time, MRI was the only feasible Ruby Implementation. MRI has a number of problems that make it hard to embed it into another application (which is basically what [mod_ruby][1] does: it embeds MRI in Apache), especially a multi-threaded one (which Apache is). It is not particularly ... |
Rails and Gmail SMTP, how to use a custom from address |
|ruby-on-rails|smtp|gmail|actionmailer| |
I've got my Rails (2.1) app setup to send email via Gmail, however whenever I send an email no matter what I set the from address to in my ActionMailer the emails always come as if sent from my Gmail email address. Is this a security restriction they've put in place at Gmail to stop spammers using their SMTP?
Note: ... |
An .sbr file is used to keep the "browse information" for symbol browsing within the projects. It's created at the same time as its source .cpp file gets complied.
If VS cannot find an .sbr file, it means that the source .cpp was not compiled properly. Try to "rebuild" the project (rather than just "build" it), it ... |
What would you not test? Anything that could not possibly break.
When it comes to code coverage you want to aim for 100% of the code you actually write - that is you need not test third-party library code, or operating system code since that code will have been delivered to you tested. Unless its not. In which cas... |
"String" is the name of the class. "string" is keyword that maps this class.
it's the same like
- Int32 => int
- Decimal => decimal
- Int64 => long
... and so on... |
@GateKiller, the OP isn't developing an Office 2007 add-in, so the UI guidelines won't really help. It's an MFC application using the <a href="http://blogs.msdn.com/somasegar/archive/2008/04/07/visual-c-2008-feature-pack-shipped.aspx">Visual C++ 2008 Feature Pack</a> which allows MFC apps to take on the Office 2007 loo... |
string is an alias for System.String. They are the same thing.
By convention, though, objects of type (System.String) are generally refered to as the alias - e.g.
string myString = "Hello";
whereas operations on the class use the uppercase version
e.g.
String.IsNullOrEmpty(myStringVariable); |
jTDS is excellent. I've been using it for years without issue in high-availability production environments. |
"string" is a C# keyword. it's just an alias for "System.String" - one of the .NET BCL classes. |
"string" is just an C# alias for the class "String" in the System-namespace. |
What kind of servers did you virtualize lately? |
|virtualization| |
I wonder what type of servers for internal usage you virtualize in the last -say- 6 months. Here's what we got virtual so far:
- mediawiki
- bugtracker (mantis)
- subversion
We didn't virtualize spezialized desktop PCs which are running a certain software product, that is only used once in a while. Do you... |
Reverse "ON" bits in a byte.. |
|c|interview-questions| |
I was reading Joel's book where he was suggesting as interview question:
Write a program to reverse the "ON" bits in a given byte.
I only can think of a solution using C.
Asking here so you can show me how to do in a Non C way (if possible)
|
The classic [Bit Hacks][1] page has several (really very clever) ways to do this, but it's all in C. Any language derived from C syntax (notably Java) will likely have similar methods. I'm sure we'll get some Haskell versions in this thread ;)
[1]: http://graphics.stanford.edu/~seander/bithacks.html |
This might depend on how much you want to engineer the solution - if the array is never going to be that big and you don't care about sorting the list you might want to try something similar to the following:
public string[] RemoveDuplicates(string[] myList) {
System.Collections.ArrayList newLis... |
This is a bad approach. [From the author][1] of Log4j,Ceki Gülcü:
> The most common error in wrapper classes is the invocation of the Logger.getLogger method on each log request. This is guaranteed to wreak havoc on your application's performance. Really!!!
That is exactly what you are doing here.
The conven... |
Creating a stack trace is a relatively slow operation. Your caller already knows what class and method it is in, so the effort is wasted. This aspect of your solution is inefficient.
Even if you use static class information, you should not fetch the Logger again for each message. [From the author][1] of Log4j,Ceki G... |
I think I finally figured out what's going on based on a comment made in <http://www.dranger.com/ffmpeg/tutorial05.html>:
> ffmpeg reorders the packets so that the DTS of the packet being processed by avcodec\_decode\_video() will _always be the same_ as the PTS of the frame it returns
Translation: If I feed a pa... |
Personally, I think they allows to save a lot of time. I'm still using .NET Framework 1.1 and every time you want a specific collection, you need to create a strongly typed collection by implementing CollectionBase. With Generics, you just need to declare your collection like that `List<MyObject>` and it's done. |
Probably the most common use for them is having strongly typed ArrayLists. In .NET 1.1, you'd either have to cast everything from object to your desired Type, or use something like CodeSmith to generate a strongly typed ArrayList.
Additionally, they help decrease [boxing][1]. Again, in .NET 1.x, if you tried to use ... |
I base my decision on the Code's depth within a module.
If I'm writting code that is internal to a module, and does not interface with the outside world I don't encapsulate things with private as much because it affects my programmer performance (how fast I can write and rewrite my code).
But for the objects that ... |
Maintaining Automated Browser UI Testing |
|.net|performance|user-interface|browser| |
What's the best way to manage a slew of browser UI tests? I'm looking for an approach that may have worked for you in the past when dealing with numerous automated browser tests. Obvious answers such as "they should be refactored into lower-level UI tests" aren't what I'm looking for. Ultimately these tests are incredi... |
As someone having to maintain several-year-old code worked on by many people in the past, it's very clear to me that if a member attribute is made public, it is eventually abused. I've even heard people disagreeing with the idea of accessors and mutators, as that's still not really living up to the purpose of encapsula... |
Generics in .NET are excellent for object collections. You can define your object type <T> however you want and be able to have, say, a List<T> without writing any code for that, and have access to all the efficient functionality of the .NET List generic collection while being type-safe to T. It's great stuff. |
Why do C# and VB have Generics? What benefit do they provide? Generics, FTW |
|generics| |
From [Wikipedia][1]:
> Generic programming is a style of
> computer programming in which
> algorithms are written in terms of
> to-be-specified-later types that are
> then instantiated when needed for
> specific types provided as parameters
> and was pioneered by Ada which
> appeared in 1983. This approach
... |
|haskell|type-inference|decidability|fundeps|gadt| |
There are three kind of so-called "asynchronous exceptions". That are the ThreadAbortException, the OutOfMemoryException and the mentioned StackOverflowException. Those excepions are allowed to occur at any instruction in your code.
And, there's also a way to overcome them:
The easiest is the ThreadAbortException... |
Should I always use the AndAlso and OrElse operators? |
|vb|vb.net|.net| |
Is there ever a circumstance in which I would not want to use the [AndAlso][1] operator rather than the [And][2] operator? …or in which I would not want to use the [OrElse][3] operator rather than the [Or][4] operator?
[1]: http://msdn.microsoft.com/en-us/library/cb8x3kfz.aspx
[2]: http://msdn.microso... |
|.net|vb.net|vb|boolean-logic| |
|.net|vb.net|boolean-logic| |
Tank you all for your ansewers. They all helped a lot. I've dealt with the problem by writing a split function, and it works fine. It's a litte bit overhead from what I could have done, but you know, the deadline is hiding around the corner :) |
Do you really need a form? No matter what you do, you're limited by the username and password being known. If they know that, they get your magic cookie that lets them. You want to prevent them seeing the pages if they don't know the secret, and basic authorization does that, is easy to set up, and doesn't require a lo... |
If your forms are laid out in a tabular format (for example, labels on the left and fields on the right), then yes, use table tags. |
Another way is to link a [swfmill][1]-based swf via -swf-lib switch and set this ScriptLimits tag there, haxe will re-use it then.
[1]: http://swfmill.org/ |
You're essentially trying to cache a view, which is always going to get tricky. You should instead try to cache data only, because data rarely changes. Don't cache a forum, cache the thread rows. Then your db call should just return a list of ids, which you already have in your cache. The db call will be lightening fa... |
One possible solution is not to paginate the cache of threads in a forum, but rather put the thread information in to <code>Forum::getThreads|$iForumId</code>. Then in your PHP code only pull out the ones you want for that given page, e.g.
$page = 2;
$threads_per_page = 25;
$start_thread = $page * $thr... |
Most tests, that need huge and expensive (in cost of resource or computationtime) setups are integration tests. Unit tests should (in theory) only test small units of the code. Individual functions.
For example, if you are testing email-functionality, it makes sense, to create a mock-mailer. The purpose of that mock... |
I think I finally figured out what's going on based on a comment made in <http://www.dranger.com/ffmpeg/tutorial05.html>:
> ffmpeg reorders the packets so that the DTS of the packet being processed by avcodec\_decode\_video() will _always be the same_ as the PTS of the frame it returns
Translation: If I feed a pa... |
I think I finally figured out what's going on based on a comment made in <http://www.dranger.com/ffmpeg/tutorial05.html>:
> ffmpeg reorders the packets so that the DTS of the packet being processed by avcodec\_decode\_video() will _always be the same_ as the PTS of the frame it returns
Translation: If I feed a pa... |
[SQLDelta][1] is awesome. It is for SQL Server. I've used it with SQL 2000 and 2005. It will compare stored procedures, tables, views, permissions, indexes, etc. It can also compare data between tables I believe. You can sync the changes or generate SQL Scripts for later use. I use it often to script out db changes in ... |
[SQLDelta][1] is awesome. It is for SQL Server. I've used it with SQL 2000 and 2005. It will compare stored procedures, tables, views, permissions, indexes, etc. It can also compare data between tables I believe. You can sync the changes or generate SQL Scripts for later use. I use it often to script out db changes in ... |
From the man page:
C-a C (clear) Clear the screen.
|
Copy Visual studio code as HTML [http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/][1]
[1]: http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/ |
usb hard disk + rsync works for me
|
usb hard disk + [rsync](http://samba.anu.edu.au/rsync/) works for me
(see [here](http://www.itefix.no/i2/node/10650) for a Win32 build)
|
If you can read ruby, you'll find some good solutions to this [here][1]
[1]: http://www.rubyquiz.com/quiz148.html "Ruby Quiz 148" |
*Just* an opinion, but I would say the error text:
- is part of the test, in which case getting it from the resource would be 'wrong' (otherwise you could end up with a consistantly mangled resource), so just update the test when you change the resource (or the test fails)
- is not part of the test, and you shoul... |
The pedantic answer (sorry, Greg :), is to read [RFC 3330][1]:
127.0.0.0/8 - This block is assigned for use as the Internet host
loopback address. A datagram sent by a higher level protocol to an
address anywhere within this block should loop back inside the host.
This is ordinarily i... |
I use Live Writer and I use VS addin that copies source code as html to copy the code and then I change into HTML view in Writer and paste the result
you can download the addin at:http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/11/21/copy-source-as-html-copysourceashtml-for-visual-studio-2008-rtm.aspx |
If possible do NOT use macros. They aren't too much admired when it comes to modern C++. |
You can trigger a mini-dump by setting a handler for uncaught exceptions. Here's an [article][1] that explains all about minidumps
Google actually implemented their own open source crash handler called [BreakPad][2], which also mozilla use I think (that's if you want something more serious - a rich and robust crash ... |
|c#|.net|vb.net|generics| |
Certainly it makes a difference whether your writing internal code or code to be used by someone else (or even by yourself, but as a contained unit.) Any code that is going to be used externally should have a well defined/documented interface that you'll want to change as little as possible.
For internal code, de... |
My preference (in C++ and Python) is to use exceptions. The language-provided facilities make it a well-defined process to both raise, catch and (if necessary) re-throw exceptions, making the model easy to see and use. Conceptually, it's cleaner than return codes, in that specific exceptions can be defined by their nam... |
A maximum length specified on a password field should be read as a **SECURITY WARNING**:
Any sensible, security conscious user must assume the worst and expect that this site is storing your password literally (i.e. not hashed, as explained by epochwolf).
In that that is the case:
(a) avoid using this site like th... |
Exceptions should only be returned where something happens that you were not expecting.
The other point of exceptions, historically, is that return codes are inherently proprietary, sometimes a 0 could be returned from a C function to indicate success, sometimes -1, or either of them for a fail with 1 for a success.... |
I tend to follow the rule pretty strictly, even when it's just my own code. I really like Properties in C# for that reason. It makes it really easy to control what values it's given, but you can still use them as variables. Or make the set private and the get public, etc. |
I only use exceptions, no return codes. I'm talking about Java here.
The general rule I follow is if I have a method called `doFoo()` then it follows that if it doesn't "do foo", as it were, then something exceptional has happened and an Exception should be thrown. |
bool IsProbablyGuid(string s)
{
int hexchars = 0;
foreach(character c in string s)
{
if(IsValidHexChar(c))
hexchars++;
}
return hexchars==32;
}
|
Well, your best bet is to use ActiveRecord sessions, e.g.
http://dmdesigns.com/blog/2008/05/03/activerecord-sessions-with-rails-202/
Be warned, you'll need to set up a reaper to make sure you get em cleared out. |
Depending on how your app is set up, you *can* easily share cookies from sites in the same domain (foo.domain, bar.domain, domain) by setting your apps up to use the same secret:
http://www.russellquinn.com/2008/01/30/multiple-rails-applications/
Now, if you have disparate sites, such as sdfsf.com, dsfsadfsdafdsaf.... |