instruction
stringlengths
0
30k
|language-agnostic|education|
|language-agnostic|education|
The *implements mouselistener, mousemotionlistener* just allows the displayArea class to listen to some, to be defined, Swing component's mouse events. You have to explicitly define what it should be listening at. So I suppose you could at something like this to the constructor: this.addMouseListener(this); ...
The *implements mouselistener, mousemotionlistener* just allows the displayArea class to listen to some, to be defined, Swing component's mouse events. You have to explicitly define what it should be listening at. So I suppose you could add something like this to the constructor: this.addMouseListener(this); ...
Trouble with parallel make not always starting another job when one finishes
|makefile|
I'm working on a system with four logical CPS (two dual-core CPUs if it matters). I'm using make to parallelize twelve trivially parallelizable tasks and doing it from cron. The invocation looks like: make -C [dir] -j 4 -l 3.99 [12 targets] The trouble I'm running into is that sometimes one job will finis...
I'm working on a system with four logical CPS (two dual-core CPUs if it matters). I'm using make to parallelize twelve trivially parallelizable tasks and doing it from cron. The invocation looks like: make -k -j 4 -l 3.99 -C [dir] [12 targets] The trouble I'm running into is that sometimes one job will fi...
It looks like most of your CSS info is in some *.css files. There is also some inline Style info on the page. Your style for the static info comes from the in-line stuff. I am not sure how Drupal generates the page but the place to start looking is for any properties for "ultima-edicao". That is what the surround...
If you really want to get into the details of communication between threads via shared memory, even declaring a variable volatile won't be enough, even if the compiler does use appropriate access semantics to ensure that it won't get a stale version of data after checking the flag. The CPU can issue reads and writes ou...
This is a conflict between your graphics driver and Visual Studio. Go to your driver settings page (Control panel) and disable the display rotation shortcuts. With this conflict removed, the shortcut will work in Visual Studio.
What's the BEST way to remove the time portion of a datetime value (SQL Server)
|sql-server|
Here's what I use: SELECT CAST(FLOOR(CAST(getdate() as FLOAT)) as DATETIME) I'm thinking there may be a better/more elegant way. Requirements: - it has to be as fast as possible (the less casting the better) - final result has to be a datetime type, not a string
If you use SVN for source control, definitely get VisualSVN. It enables TortoiseSVN interactions from within the Visual Studio IDE. I also echo the Resharper comment. Retail price is a little steep, but if you're a student or otherwise educationally affiliated, it's actually pretty cheap.
Allright, I figured it out! This is a hard bug to catch, but results from the way pipes are handled in Unix. Every element of a pipeline runs in a separate process. When the read command sets var1 and var2, is sets them it its own subshell, not the parent shell. So when the subshell exits, the values of var1 and var...
You need to handle the System.Windows.Forms.Application.ThreadException event for winforms. This article really helped me: [http://bytes.com/forum/thread236199.html][1]. [1]: http://bytes.com/forum/thread236199.html
Your CAST-FLOOR-CAST already seems to be the optimum way, at least on MSSQL 2005. Some other solutions i've seen have a string-conversion like Select Convert(varchar(11), getdate(),101) in them, which is slower by a factor of 10.
emacs has been used by linux programmers for decades. It features syntax highlighting, it's fast, and there are a million tutorials out there you can find.
What's the best setup for Mono development on Windows?
|windows|mono|
I started trying to play with Mono, mostly for fun at the moment. I first tried to use the VS plugin that will convert a csproj into a makefile, but there seemed to be no version available for VS2005. I also read about the MonoDevelop IDE, which sounded nice. Unfortunately, there's no pre-fab Windows package for it....
|wpf|validation|data-binding|
I have a databound TextBox in my application like so: (The type of `Height` is `decimal?`) <TextBox Text="{Binding Height, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, Converter={StaticResource NullConverter}}" /> public class...
I have a databound TextBox in my application like so: (The type of `Height` is `decimal?`) <TextBox Text="{Binding Height, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, Converter={StaticResource NullConverter}}" /> public class...
I have also seen octal used in aircraft transponders. A mode-3a transponder code is a 12-bit number that everyone deals with as 4 octal numbers. There is a bit more information on [Wikipedia](http://en.wikipedia.org/wiki/Transponder_%28aviation%29). I know it's not generally computer related, but the FAA uses comput...
You can use various ways to handle this situation, depending on your source control system. Private branches: Allow you to check in and work on code while you go, merging back and forth at appropriate times. Shelvesets/pacakaged changesets: Allow you to store changesets and send them around for review - ensuring...
> Maybe a bonnet, lap or a tree is not a chair but they all are ISittable. Yes, but only ex post facto. They're ISittable because someone sat on them.
I don't think there's a built-in control that can do it in .NET. I'm poking around in the MSDN documentation for the standard Windows Button control, but it doesn't look like it's there. I did find a [Code Project article][1] with a custom implementation; this might help a little. [1]:http://www.codeproject.com/...
The problem with static functions is that they can lead to a design that breaks encapsulation. For example, if you find yourself writing something like: public class TotalManager { public double getTotal(Hamburger burger) { return burger.getPrice() + burget.getTax(); ...
LinqBridge works fine under .NET 2.0, and you get all the Linq extensions and query language. You need VS 2008 in order to use it, but you already knew that. However, Linq it not an ORM. It's a query syntax. If you want to use Linq to query a database, you will need .NET 3.5. That's because 2.0 does not provide the ...
I recently came across [divascheme](http://www.cs.brown.edu/research/plt/software/divascheme/) - an alternative set of key bindings for [DrScheme](http://www.drscheme.org/). This is modal, and part of the justification is to do with RSI - specifically avoiding lots of wrist twisting to hit Ctrl-Alt-Shift-something. T...
you could always write one yourself: def iterattr(iterator, attributename): for obj in iterator: yield getattr(obj, attributename) will work with anything that iterates, be it a tuple, list, or whatever. I love python, it makes stuff like this very simple and no more of a hassle than ...
I've never worked anywhere that had a formalized policy, but practically every manager I've ever had has allowed me to spend some time on things that weren't directly related to the current project or fighting a fire. I think the key is to talk about the things you'd like to try. Most managers want their teams to d...
I would definitely break down the jobs. Chances are you're likely to make changes in the builds, and it'll be easier to track down issues if you have smaller tasks instead of searching through one monolithic build. You should be able to create one big job from the smaller pieces, anyways.
Best practice for dynamically added Web.UI.ITemplate classes
|.net|asp.net|
We have a couple of ASP.Net dataview column templates that are dynamically added to the dataview depending on columns selected by users. These templated cells need to handle custom databindings: public class CustomColumnTemplate: ITemplate { public void InstantiateIn( Control contain...
What on Earth are you all Word-is-binary-so-no-diff people talking about? TortoiseSVN, for example, integrates right out of the box with Word and enables you to use Word's built-in diff and merge functionality. It works just fine. I have worked on projects that store documents in version control. It has worked out p...
You definitely want to break up the tasks. Here is a nice example of CruiseControl.NET configuration that has different targets (tasks) for each step. It also uses a common.build file which can be shared among projects with little customization. <http://code.google.com/p/dot-net-reference-app/source/browse/#svn/tr...
Try Thread.Sleep(10 * 60 * 1000)
Or how about logging to a queue? That way you can switch out pollers whenever you like to log to different things. It makes things like rolling over and archiving log files very easy. It's also nice because you can add pollers that log to different things, for example: * a poller that looks for error messages and...
Scott Hanselman / Stuart Celarier / Patrick Cauldwell's [poster][1] with ndepend metrics has some useful information on it. Rather than trying to break down all the heuristics being used I'd focus on only a few at a time starting with "zone of pain / zone of uselessness" and cyclomatic complexity. There is also a [...
.NET Development on a Mac Tips
|macos|.net|vmware|
I have just got a MacBook Pro and have been using it (+Fusion) to develop on for about a month now. The purpose of this question is similar to [Hidden Features of C#](http://stackoverflow.com/questions/9033/hidden-features-of-c#35342); to become a how-to of tips and trick for windows development on a mac. My enviro...
|macos|.net|vmware|virtualization|
|.net|macos|vmware|virtualization|
I have just got a MacBook Pro and have been using it (+Fusion) to develop on for about a month now. The purpose of this question is similar to [Hidden Features of C#](http://stackoverflow.com/questions/9033/hidden-features-of-c#35342); to become a how-to of tips and trick for windows development on a mac. I should ...
Flash has some neat security measures in place. Allowing users to upload swf's to your site and embedding them is unsafe, you're basically setting yourself up for an XSS attack. However, allowing them to hotlink should not be a problem. The swf will be locked to the domain that is hosting it and is not allowed calli...
How to return status 401 instead of redirecting to login page for select actions
|asp.net-mvc|forms-authentication|asp.net|
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually when a user tries to access a resource without proper authorization I want them to be redirected to a login page. FormsAuth does this for me easy enough. Problem: Now I have an action being accessed by a console app. What...
How do I bypass forms auth's interception of 401 responses
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually when a user tries to access a resource without proper authorization I want them to be redirected to a login page. FormsAuth does this for me easy enough. Problem: Now I have an action being accessed by a console app. What...
Bypass Forms Authentication, How to?
Bypass Forms Authentication auto redirect to login, How to?
|asp.net|asp.net-mvc|forms-authentication|
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually when a user tries to access a resource without proper authorization I want them to be redirected to a login page. FormsAuth does this for me easy enough. Problem: Now I have an action being accessed by a console app. What...
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually when a user tries to access a resource without proper authorization I want them to be redirected to a login page. FormsAuth does this for me easy enough. Problem: Now I have an action being accessed by a console app. What...
I would second the recommendation for [PCRE][1]. I have used it in C++ projects in Windows and it works great. It's free, even for building commercial software. It also implements something of a de facto standard regular expression language, which will be welcome to your users. PCRE is of course Perl-compatible, and Py...
One of the debugging techniques that I use frequently (except in cases of the most extreme weirdness) is to divide and conquer. If your program currently fails with some specific error, then divide it in half in some way and see if it still has the same error. Obviously the trick is to decide where to divide your progr...
Thanks for the answer, great! I did some research myself and found [ListNanny][1] - also super simple to use and tells you the type of bounce. Will write some proof of concept and see which one I like better... [1]: http://www.advancedintellect.com/product.aspx?listnanny
Then you'll have to warp CURRENT in another function that you'll call from the first (but this is a hack on the previous hack ...).
As tweakt said, Amazon S3 is a good model to work with. Their request signatures do have some features (such as incorporating a timestamp) that help guard against both accidental and malicious request replaying. The nice thing about HTTP Basic is that virtually all HTTP libraries support it. You will, of course, nee...
With javascript alone, it's **not possible**. Javascript is not intended to do such things and is severely crippled in the way it can interact with anything other than the webbrowser it lives in, (for good reason!). Think about it: a spammer writing a website with client side javascript which will automatically...
I've never worked anywhere that had a formalized policy, but practically every manager I've ever had has allowed me to spend some time on things that weren't directly related to the current project or fighting a fire. I think the key is to talk about the things you'd like to try. Most managers want their teams to d...
Enforcing web standards
|css|xhtml|coding-style|
The HTML standard defines a clear separation of concerns between CSS (presentation) and HTML (semantics or structure). Does anyone use a coding standards document for CSS and XHTML that has clauses which help to maintain this separation? What would be good clauses to include in such a coding standards document?
Yes! jQuery.fn.exists = function(){return jQuery(this).length>0;} There you go! This is in response to: [Herding Code podcast with Jeff Atwood][1] [1]: http://herdingcode.com/?p=36
Yes! jQuery.fn.exists = function(){return jQuery(this).length>0;} if ($(selector).exists()) { // Do something } There you go! This is in response to: [Herding Code podcast with Jeff Atwood][1] [1]: http://herdingcode.com/?p=36
Accessing a Component on an inherited form from the base form
|.net|winforms|reflection|inheritance|
A number of forms in my project inherit from a base form. It is easy to get at the Controls collection of the derived forms, but I have not found a simple way to access the Components collection, since VS marks this as private. I assume this could be done with reflection, but I'm not really sure how best to go abou...
Short of any other answers, I would try attaching to the executable process in Visual Studio, setting a break point in your code and when you step into the process you don't have source to, it should ask for a source file.
I've not familiar with using either of these, but try searching msdn for splitbutton or dropdownbutton. I think those are similar to what you're looking for.
You can try something like: InputStream stream = this.getClass().getClassLoader().getResourceAsStream("/images/image.jpg"); In your JAR file, you might have a directory structure of: > MyJAR.jar - com (class files in here) - images ----image.jpg
Apologies if I've missed the real point of the question but, if I was using sh/bash/etc., then I would probably use *find* to do the job: find . -name '*.rb' -type f Globs can get a bit nasty when used from within a script and *find* is much more flexible.
public void PageLinks(int currentPage, int lastPage) { if (currentPage > 2) Add([1], ...); for(int i=Math.Max(1, currentPage-1); i< Math.Min(currentPage+1, lastPage); i++) Add([i]); if (currentPage < lastPage-1) Add(..., [lastpage]); } last...
<pre><code> public void PageLinks(int currentPage, int lastPage) { if (currentPage > 2) Add('[1]', '...'); for(int i=Math.Max(1, currentPage-1); i< Math.Min(currentPage+1, lastPage); i++) Add('[i]'); if (currentPage < lastPage-1) Add('...', '[lastpage]'); } </code></pre...
public void PageLinks(int currentPage, int lastPage) { if (currentPage > 2) Add('[1]', '...'); for(int i=Math.Max(1, currentPage-1); i< Math.Min(currentPage+1, lastPage); i++) Add('[i]'); if (currentPage < lastPage-1) Add('...', '[lastpage]'); ...
This may be missing the point, but how about naming the tests so they indicate what they test - then you may not even need the message. If it proves to be absolutely necessary, I think you'll need to produce your own testrunner that would (off the top of my head) read an additional attribute off the TestCase and at...
I would go with the second version. The first one looks like the kind of code smell that Visitor is supposed to solve: long if-else-if or switch-case statements.
Is there a good method in C# for throwing an exception on a given thread
|c#|exception|multithreading|
The code that I want to write is like this: void MethodOnThreadA() { for (;;) { // Do stuff if (ErrorConditionMet) ThrowOnThread(threadB, new MyException(...)); } } void MethodOnThreadB() { try { ...
C2143 basically says that the compiler got a token that it thinks is illegal in the current context. One of the implications of this error is that the actual problem may exist before the line that triggers the compiler error. As Greg said I think we need to see more of your code to diagnose this problem. I'm also no...
In all cases here is actual code that runs ... doesn't mean much but produces output and hopefully can get you started ... use XML::Parser; package MyNode::inner; sub doSomething { my $self = shift; print "This is an inner node containing : "; print $self->{Kids}->[0]->{Text}; print "\n";...
`ldiv` ? Edit: reread title, so you might want to ignore this. Or not, depending on if it has an appropriate non-library version. MSN
okay found out what was the problem... forgot that in C you have to declare all your variables before any code.
Exception in Web Service locks DLL and prevents publishing. Workaround?
|c#|asp.net|visual-studio|web-services|iis|
I'm using a native DLL (FastImage.dll) in a C# ASP.NET Web Service that sometimes locks (can't delete it---says access denied); this requires stopping IIS to delete the DLL. The inability to delete this DLL in the bin folder of my published Web Service prevents me from publishing successfully (even though it thinks it ...
You should consider writing your code in such a way that you can mock your I/O completion port. Make an interface/abstract class that exposes the methods you need on the I/O object, and write and test implementation that does things like it's supposed to (and an option to simulate failure perhaps). AFAIK it's a comm...
It is definitely worthwhile to test failure conditions, both that your class properly throws an exception when you want it to and that exceptions are handled properly in the class. This can easily be done if you are acting on an object passed in to the constructor... just pass in a mock. If not, I tend to prefer to...
It is definitely worthwhile to test failure conditions, both that your class properly throws an exception when you want it to and that exceptions are handled properly in the class. This can easily be done if you are acting on an object passed in to the constructor... just pass in a mock. If not, I tend to prefer to...
any of the popular editors can be turned into an ide. I use Vi on the console and have used various gui editors over the years. This doesn't just go for linux I use Crimson Editor on windows as a C/python/z80asm ide.
In addition (or instead) of adding a .0 to the number, in my opinion it is also desirable to be as explicit as possible, for understandability and aid to your fellow programmers that eventually will read your code =). Using decimal.ToDouble(), like so: double transperancy = trackBar1.Value/5000; this.Opa...
If you're using VB.NET, you can tap into the very convenient ApplicationEvents.vb. This file comes for free with a VB.NET WinForms project and contains a method for handling unhandled exceptions. If you're not using VB.NET, then yeah, it's handling [Application.ThreadException][1]. [1]: http://msdn.microsoft...