instruction
stringlengths
0
30k
Suppose I have the following C code: unsigned int u = 1234; int i = -5678; unsigned int result = u + i; What implicit conversions are going on here, and is this code safe for all values of u and i? (safe, in the sense that even though _result_ in this example will overflow to some huge positiv...
<Assuming Windows> If they only need to edit Office files one user at a time infrequently, get the files on a network share with appropriate permissions and back them up nightly. Active Directory will warn them if someone already has it open. If it's more complicated than just office consider Sharepoint. I think...
See section 2.7, *Type Conversions* in the K&R book
So you can clean up any open connections, etc. initialized in the try block. If you opened a connection and then an exception occurred, that exception would not be properly closed. This type of scenario is what the finally block is for.
Implicit casting and interger overflowing in the evaluation of expressions question in c.
Does this help: http://www.west-wind.com/weblog/posts/76293.aspx
Does this help: http://www.west-wind.com/weblog/posts/76293.aspx Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition","attachment; filename=logfile.txt"); Response.TransmitFile( Server.MapPath("~/logfile.txt") ); Response.End(); Response.TransmitFile...
On Vista could it also be that it's "marked" as unsafe because it's been downloaded from the internet and you have to click the unblock button on it's explorer properties dialog?
Check out the **db-utils** package. If you use apt, you can install it with the following: `apt-get install db4.4-util` Additional links: - [http://rpmfind.net/linux/rpm2html/search.php?query=db-utils][1] - [http://packages.ubuntu.com/search?suite=default&section=all&arch=any&searchon=names&keywords=db4.4-ut...
Check out the **db-utils** package. If you use apt, you can install it with the following: `apt-get install db4.4-util` Additional links: - [http://rpmfind.net/linux/rpm2html/search.php?query=db-utils][1] - [http://packages.ubuntu.com/search?keywords=db4.4-util][2] - [Man page of db4.4_dump][3] [1]...
<code><pre> ALTER TABLE table ADD COLUMN tmp; UPDATE table SET tmp = X; UPDATE table SET X = Y; UPDATE table SET Y = tmp; ALTER TABLE table DROP COLUMN tmp; </code></pre> Something like this?
<code><pre> ALTER TABLE table ADD COLUMN tmp; UPDATE table SET tmp = X; UPDATE table SET X = Y; UPDATE table SET Y = tmp; ALTER TABLE table DROP COLUMN tmp; </code></pre> Something like this? Edit: About Greg's comment: No, this doesn't work: <code><pre> mysql> select * from test; +------+------+ | x...
Auto defines in C editors... Why?
|c|eclipse|define|
When I let Eclipse create a new file (.c or .h file) in a C project the editor always auto creates a #define at the top of the file like this: If the file is named 'myCFile.c' there will be a #define at the start of the file like this #ifndef MYCFILE_C_ #define MYCFILE_C_ I have seen other editors do th...
The first answer you gave uses what is known as ANSI join syntax, the other is valid and will work in any relational database. I agree with grom that you should use ANSI join syntax. As they said, the main reason is for clarity. Rather than having a where clause with lots of predicates, some of which join tables and...
JohnLavoie - you don't need that. DATE in Oracle is actually a date and time data type. The only difference between DATE and TIMESTAMP is that DATE resolves down to the second but TIMESTAMP resolves down to the micro second. Therefore the Ask Tom article is perfectly valid for TIMESTAMP columns as well.
Sometimes using reflection can be a bit of a hack, but a lot of the time it's simply the most fantastic code tool. Look at the .Net property grid - anyone who's used Visual Studio will be familiar with it. You can point it at any object and it it will produce a simple property editor. That uses reflection, in fact m...
I recently used reflection in C# for finding implementations of a specific interface. I had written a simple batch-style interpreter that looked up "actions" for each step of the computation based on the class name. Reflecting the current namespace then pops up the right implementation of my IStep inteface that can be ...
As the mantra goes 'Go with the simplest thing that can possibly work.' - If fake classes can get the job done, go with them. - If you need an interface with multiple methods to be mocked, go with a mock framework. Avoid using mocks *always* because they make tests brittle. Your tests now have intricate k...
As the mantra goes 'Go with the simplest thing that can possibly work.' - If fake classes can get the job done, go with them. - If you need an interface with multiple methods to be mocked, go with a mock framework. Avoid using mocks *always* because they make tests brittle. Your tests now have intricate k...
We have been developing an Outlook Add-in using Visual Studio 2008. However I am facing a strange behavior while adding a command button to a custom command bar. This behavior is reflected when we add the button in the reply, reply all and forward windows. The issue is that the caption of the command button is not visi...
Actually, I recently made the switch from Visual Studio (*years* of experience there) to Linux and the first thing I did was try to find a reasonable IDE. And then I noticed that this simply isn't how you work there*, and I threw everything out, spent a few days reading manuals, set up my shell (bash), set up a GVIM...
I'm currently using this: String content = null; URLConnection connection = null; try { connection = new URL("http://www.google.com").openConnection(); Scanner scanner = new Scanner(connection.getInputStream()); scanner.useDelimiter("\\Z"); content = scanner.next(); }c...
You may want to check the documentation for Apache's org.apache.commons.HttpClient package and the related packages [here][1]. Sending an HTTP request from a Java application is pretty easy to do. Poking through the documentation should get you off in the right direction. [1]: http://hc.apache.org/httpclient-3...
Something like: Pattern exp = Pattern.compile( "<meta name=\"generator\" value=\"([^\"]*)\" />"); Matcher matcher=exp.matcher(html); if(matcher.find()) { System.out.println("Generator: "+matcher.group(1)); }
Depends on how sophisticated of an Http request you need to build (authentication, etc). Here's one simple way I've seen used in the past. StringBuilder html = new StringBuilder(); java.net.URL url = new URL("http://www.google.com/"); BufferedReader input = null; try { input new Buffered...
I haven't tried this, but wouldn't the basic framework be 1. Open a java.net.HttpURLConnection 2. Get an input stream using getInputStream 3. Use the regular expression in Mike's answer to parse out the bit you want
This error ofter occurs because incompatibility of VMWare Tools Version and recent Kernels (You can test it using older Kernels). Sometimes you can fix some thing with patches all over the internet, but I prefer to downgrade my kernel or don't using latest distribution's version in VMWare. It can be really annoying. An...
This is a topic that I was just talking about at work. Mainly the problem is that unless database migrations is handled for you nicely by your framework, eg rails and their migration scripts, then it is left up to you. The current way that we do it has apparent flaws, and I am open to other suggestions. 1. Hav...
As the mantra goes 'Go with the simplest thing that can possibly work.' 1. If fake classes can get the job done, go with them. 2. If you need an interface with multiple methods to be mocked, go with a mock framework. Avoid using mocks *always* because they make tests brittle. Your tests now have intricate k...
[TurboGears](http://www.turbogears.org/) currently uses [SQLObject](http://www.sqlobject.org/) by default but you can use it with [SQLAlchemy](http://docs.turbogears.org/1.0/SQLAlchemy). They are saying that the next major release of TurboGears (1.1) will use SQLAlchemy by default.
Unexpected behaviour of Process.MainWindowHandle
|c#|.net|msdn|
I've been trying to understand [Process.MainWindowHandle][1]. According to MSDN; "The main window is the window that is created when the process is started. After initialization, other windows may be opened, including the Modal and TopLevel windows, but <em>the first window associated with the process remains the ma...
1. [Code::Blocks][1] 2. [Eclipse CDT][2] [1]: http://www.codeblocks.org/ [2]: http://www.eclipse.org/cdt/ Soon you'll find that IDEs are not enough, and you'll have to learn the GCC toolchain anyway (which isn't hard, at least learning the basic functionality). But no harm in reducing the transitional pa...
I would strongly recommend getting a copy of Robert C. Martin's book [Working Effectively With Legacy Code][1] (by "Legacy Code" Martin means any system that isn't adequately covered by unit tests). It is full of good ideas which should help you with your refactoring and phasing in of best practices. Downsides of OR...
I would strongly recommend getting a copy of Robert C. Martin's book [Working Effectively With Legacy Code][1] (by "Legacy Code" Martin means any system that isn't adequately covered by unit tests). It is full of good ideas which should help you with your refactoring and phasing in of best practices. Sure, you could...
I would strongly recommend getting a copy of Michael Feather's book [Working Effectively With Legacy Code][1] (by "Legacy Code" Feathers means any system that isn't adequately covered by unit tests). It is full of good ideas which should help you with your refactoring and phasing in of best practices. Sure, you coul...
Your PM's concerns are valid - make sure you get your system under test before making any major refactorings. I would strongly recommend getting a copy of Robert C. Martin's book [Working Effectively With Legacy Code][1] (by "Legacy Code" Martin means any system that isn't adequately covered by unit tests). This is...
|c|
Lets take the code int a, b, c; ... if ((a + b) > C) If the values of a and b add to exceed the max value of an int will the integrity of the comparison be compromised? I was thinking that there might be an implicit up cast or overflow bit checked and factored into the evaluation of this expres...
C: Implicit casting and interger overflowing in the evaluation of expressions
Well, for one thing, if you RETURN inside your try block, the finally will still run, but code listed below the try-catch-finally block will not.
The finally block is supposed to execute whether you caught the exception or not. See [Try / Catch / Finally example][1] [1]: http://neptune.netcomp.monash.edu.au/JavaHelp/howto/try_catch_finally.htm#whyFinally
In the case, that the try and the catch are empty, there is no difference. Otherwise you can be sure, that the finally will be executed. If you, for example throw a new Exception in your catchblock (rethrow), than the assignment will only be executed, if it is in the finally-block. Normally a finally is used to c...
When you cast from signed to unsigned (and vice versa) the internal representation of the number does not change. What changes is how the compiler interprets the sign bit. So yes, aside from the possible overflows, it is safe to cast from signed to unsigned, though the result will probably be much larger after changing...
Ok, so what you really need is a "jagged array". This will allow you to have an "array that contains other arrays of varying lengths". Dim arr As Integer()() = {New Integer() {1, 2, 3}, New Integer() {4, 5, 6, 7, 8, 9, 9, 9}, New Integer() {5, 4, 3, 2}} For x = 0 To arr.GetUpperBound(0) ...
Dog should return a Leg not a DogLeg as the return type. The actual class may be a DogLeg, but the point is to decouple so the user of Dog doesn't have to know about DogLegs, they only need to know about Legs. Change: class Dog : Animal { public override DogLeg GetLeg() {...} } to: ...
MVC framework where model's has datasource classes with the actual database language, the developer in most cases uses save, saveField, delete, find etc methods and the framework translates this to sql queries. This is not only safer and easier, it is also very convenient in that the code is datasource indepenedent, ie...
Hava a look at SOS Assist (http://old.thinktecture.com/SOSAssist/default.html), it provides a GUI around SOS.
By default, the browser does not print background images at all. In Firefox * File > Page Setup > Check Off "Print Background" * File > Print Preview In IE * Tools > Internet Options > Advanced > Printing * Check Off "Print Background Images and Colors" In Opera * File > Print O...
Use the [ASCII table][1] to pick a range of letters, where the: $range_start , $range_end is a value from the decimal column in the ASCII table. // range is numbers through capital and lower case letters $range_start = 48; $range_end = 122; $random_string = ""; $random_string_length = 10; ...
Use the [ASCII table][1] to pick a range of letters, where the: $range_start , $range_end is a value from the decimal column in the ASCII table. I find that this method is nicer compared [to the method described][2] where the range of characters is specifically defined within another string. // range is numbe...
This may well be a bug in the designer; if you take a look around at the .designer.cs file (maybe doing a diff from before and after you set NullValue to null) you should be able to see the code it generates.
Storing Windows passwords.
|windows|password|security|
You can transform your XML data using [XSLT][1] Another option is to use XLinq. If you want concrete code example provide us with sample data [1]: http://www.xml.com/pub/a/2002/08/14/dotnetxslt.html
You can transform your XML data using [XSLT][1] Another option is to use XLinq. If you want concrete code example provide us with sample data **EDIT**: here is a sample XSLT transform for your XML file: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:outp...
You could use something like: svnadmin dump repositorypath | gzip > backupname.svn.gz
You could use something like (Linux): svnadmin dump repositorypath | gzip > backupname.svn.gz Since Windows does not support GZip it is just: svnadmin dump repositorypath > backupname.svn
It's to guard against [multiple definitions][1]. [1]: http://www.fredosaurus.com/notes-cpp/preprocessor/ifdef.html
I think it's a throwback of C include issues, where multiple copies of the source would get included - unless you are meticulous with include chains (One file includes n others). Checking if a symbol is defined and including only if the symbol is defined - was a way out of this.
I've recently started using CruiseControl.NET (<http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET>). It works reasonably well, although configuration could be easier. CruiseControl.NET is free and open source, and seems to integrate with most standard tools, although I've personally o...
Sometimes people include a whole .c file in other .c files (or even .h files), so it has the exact same purpose of preventing an include file from getting included multiple times and the compiler spitting out multiple definition errors. It is strange, though, that it would be the default behavior of an editor to put...
Your PM's concerns are valid - make sure you get your system under test before making any major refactorings. I would strongly recommend getting a copy of Robert C. Martin's book [Working Effectively With Legacy Code][1] (by "Legacy Code" Martin means any system that isn't adequately covered by unit tests). This is...
Your PM's concerns are valid - make sure you get your system under test before making any major refactorings. I would strongly recommend getting a copy of Michael Feather's book [Working Effectively With Legacy Code][1] (by "Legacy Code" Feathers means any system that isn't adequately covered by unit tests). This i...
It depends exactly what you mean by 'better'. I'd go for the object oriented way (using classes) because I find it makes for cleaner code (at least in my opinion). However, I'm not sure what the speed penalties might be for that option.
C++ IDE for linux
|c++|ide|linux|
|c++|linux|ide|
I'm currently in the process of expanding my programming horizons to linux. In order to do that, it is important to have a good basic toolset on which you can rely on. and what is more basic then the IDE in which you write your code? (honestly, you don't want to code in notepad; been there done that). there are two ...
Other than the downtime a few weeks ago. None that I heard of. They did a good job considering the one time it was down was because of an obscure server error that cascaded throughout the cloud. They was very open about it and resolve it as soon as they found out.(it happened during a weekend, iirc) So they are p...
I just left [this post in your other thread][1], though what you have above might work as well. I don't think either would be any easier than the other. The Apache packages can be accessed by just using `import org.apache.commons.HttpClient` at the top of your code. Edit: Forgot the link ;) [1]: http://stac...
I was using the basicHttp binding but the problem was actually with the XMLSerializer. It doesn't properly recognize the wsdl generated by WCF (even with basicHttp bindings) for anything other than basic value types. We got around this by added the reference to the 3.0 dll's and using the datacontract serializer.
I assume you're on Vista using VS2008? In that case I think that the [FOS_PICKFOLDERS option][1] is being used when calling the Vista file dialog [IFileDialog][2]. I'm afraid that in .NET code this would involve plenty of gnarly P/Invoke interop code to get working. [1]: http://msdn.microsoft.com/en-us/library/bb7...
I agree, quad-checking your code would be a good idea. I'm not saying that it can't happen, but I don't believe that I have ever seen it, and I've used S3 a pretty good bit now. I have, however, mismanaged exceptions/connection breaks a few times and ended up with pieces that didn't match what I was expecting. I w...
The Brail view engine has been implemented to be used in ASP.NET MVC. The [MvcContrib][1] project implemented the code. The [source code][2] is located on Google Code. As far as the controllers, I really am not sure. I am not that familiar with Boo. I know a lot of developers use it for configuration instead of ...
I uninstalled the previous 32bit version, reinstalled as 64bit, and now I get a completely different error. Its mentioned as requiring FP2 to fix, but since I'm using Express-C, I can't install the fixpack (IBM doesn't provide fixpacks for free DB2 products). Anyway, thanks for the help. At least I can come closer t...
I have a lot of experience with this. My application is highly iterative, and schema changes happen frequently. I do a production release roughly every 2 to 3 weeks, with 50-100 items cleared from my FogBugz list for each one. Every release we've done over the last few years has required schema changes to support ne...
I'm writing an administrative application which will poll multiple Windows systems for various bits of data. In many cases it will use WMI, but in some cases it may need to read remote registry or remotely execute some command or script on the polled system. These functions will require admin-level access to the polled...
|windows|security|passwords|
|c#|.net|windows|security|passwords|
I'm writing (in C# with .NET 3.5) an administrative application which will poll multiple Windows systems for various bits of data. In many cases it will use WMI, but in some cases it may need to read remote registry or remotely execute some command or script on the polled system. This polling will happen at repeating i...
Preventing XML Serialization of IEnumerable and ICollection<T> & Inherited Types
|xml|serialization|inheritance|.net-2.0|
**NOTE: _XMLIgnore_ is NOT the answer!** OK, so following on from my question on [XML Serialization and Inherited Types](http://stackoverflow.com/questions/20084/xml-serialization-and-inherited-types), I began integrating that code into my application I am working on, stupidly thinking all will go well.. I ran in...
**NOTE: _XMLIgnore_ is NOT the answer!** OK, so following on from my question on [XML Serialization and Inherited Types](http://stackoverflow.com/questions/20084/xml-serialization-and-inherited-types), I began integrating that code into my application I am working on, stupidly thinking all will go well.. I ran in...
|xml|.net-2.0|serialization|inheritance|
**NOTE: _XMLIgnore_ is NOT the answer!** OK, so following on from my question on [XML Serialization and Inherited Types](http://stackoverflow.com/questions/20084/xml-serialization-and-inherited-types), I began integrating that code into my application I am working on, stupidly thinking all will go well.. I ran in...
Since you're using Tortoise you may want to check out this link on LosTechies. It should be almost exactly what you are looking for. http://www.lostechies.com/blogs/joshua_lockwood/archive/2007/09/12/subversion-tip-of-the-day-moving-files.aspx
What are the names given to these 2 LINQ expressions
|linq|
I'm trying to find the correct names for these 2 "types" of coding expressions in LINQ so that I can refer to them correctly. I want to say that the first is called "Fluent Style"? var selectVar = arrayVar.Select( (a,i) => new { Line = a }); var selectVar = from s in arrayVar select...
Web browsers will not POST any disabled or hidden form elements. (@Dan: asp:Buttons do not call __doPostback() because HTML input controls already submit the form.) So what's happening is: 1. The user clicks on a button in your dialog. 2. The button calls SimpleModal's close() method, hiding the dialog and ...
Web browsers will not POST any disabled or hidden form elements. So what's happening is: 1. The user clicks on a button in your dialog. 2. The button calls SimpleModal's close() method, hiding the dialog and the button 3. The client POSTs the form (without the button's ID) 4. The ASP.NET framework can't fi...
Web browsers will not POST any disabled or hidden form elements. So what's happening is: 1. The user clicks on a button in your dialog. 2. The button calls SimpleModal's close() method, hiding the dialog and the button 3. The client POSTs the form (without the button's ID) 4. The ASP.NET framework can't fi...
The definitive pieces on this subject have been written by Joe Celko, and he has worked a number of them into a book called Joe Celko's Trees and Hierarchies in SQL for Smarties. He favours a technique called directed graphs. An introduction to his work on this subject can be found [here](http://www.intelligententer...
Jeff's mechanism was to create some sort of cached object which ASP.Net would automatically recreate at some sort of interval - It seemed to be an ASP.Net specific solution, so probably won't help you (or me) much in Java world. See [https://stackoverflow.fogbugz.com/default.asp?W13117][1] > Atwood: Well, I origi...
Jeff's mechanism was to create some sort of cached object which ASP.Net would automatically recreate at some sort of interval - It seemed to be an ASP.Net specific solution, so probably won't help you (or me) much in Java world. See [https://stackoverflow.fogbugz.com/default.asp?W13117][1] > Atwood: Well, I origi...