instruction stringlengths 0 30k ⌀ |
|---|
Use the ListView_ApproximateViewRect (or the LVM_APPROXIMATEVIEWRECT message) to get the view rect height.
Use the ListView_GetItemRect (or the LVM_GETITEMRECT message) to get the height of an item.
Divide the view rect height by the height of an item to get the number of items that can fit in your view.
Do this... |
Django: Print url of view without hardcoding the url |
|django|python| |
Can i print out a url (/admin/manage/products/add) of a certain view in a template?
Here is the rule i want to create a link for
(r'^manage/products/add/$', create_object, {'model': Product, 'post_save_redirect': ''}),
I would like to have /manage/products/add in a template without hardcoding it. How can i... |
I agree with those that say this is not an anti-pattern. Its a perfectly valid pattern in certain contexts. Exceptions are for *exceptional* situations, return values (like in your example) should be used in expected situations. Some domains expect valid and invalid results from classes, and neither of those should be ... |
See: <http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx>
string animals = ",liger, unicorn, snipe";
//trimmed will contain "liger, unicorn, snipe"
string trimmed = word.Trim(',');
|
The IEEE 754 standard for floating-point numbers has the sign bit separate from the mantissa, which allows for zero to be negative. [Wikipedia][1] should be able to help explain this.
[1]: http://en.wikipedia.org/wiki/IEEE_754 |
How do I check for nulls in an '==' operator overload without infinite recursion? |
|c#|.net| |
The following will cause infinite recursion on the == operator overload method
Foo foo1 = null;
Foo foo2 = new Foo();
Assert.IsFalse(foo1 == foo2);
public static bool operator ==(Foo foo1, Foo foo2) {
if (foo1 == null) return foo2 == null;
return foo1.Eq... |
No he is not crazy, you can use images on almost all GUI tools instead of buttons, they are generally an image on the button, or in some cases you can put the image on the screen and have an onclick event assigned to it. |
Because "negative zero" is a valid number!
<http://en.wikipedia.org/wiki/%E2%88%920_(number)> |
I personally think you'd be better off using std::vector to allocate your memory, so you don't need the delete.
std::vector<BYTE> backing(sizeof(STRUCT) + nPaddingSize);
STRUCT* pStruct = (STRUCT*)(&backing[0]);
Once backing leaves scope, your pStruct is no longer valid.
Or, you can use:
boost:... |
C# has explicit interface implementations to address just this issue:
abstract class Leg { }
class DogLeg : Leg { }
interface IAnimal
{
Leg GetLeg();
}
class Dog : IAnimal
{
public override DogLeg GetLeg() { /* */ }
Leg IAnimal.GetLeg() { return GetL... |
[Cmockery][1] is a recently launched Google Code project that consists on a very simple to use C library for writing unit tests.
[1]: http://code.google.com/p/cmockery/ |
Use specific field names, so if somebody changes the table on you, you don't get unexpected results. On the subject: ALWAYS specify field names when doing an insert so if you need to add a column later, you don't have to go back and fix your program and change the database at the same time in the production release. |
A good start would be to watch the Android architecture videos and look at some of the documentation.
http://www.youtube.com/view_play_list?p=586D322B5E2764CF
http://code.google.com/android/what-is-android.html
Google is very good about documenting. From what I've heard Android very very similar to J2ME in its g... |
Unique ID c++ |
|c++|hash| |
What is the best way to generate a Unique ID from two (or more) short ints in C++? I am trying to uniquely identify vertices in a graph. The vertices contain two to four short ints as data, and ideally the ID would be some kind of a hash of them. Prefer portability and uniqueness over speed or ease. |
What is the best way to generate a Unique ID from two (or more) short ints in C++? I am trying to uniquely identify vertices in a graph. The vertices contain two to four short ints as data, and ideally the ID would be some kind of a hash of them. Prefer portability and uniqueness over speed or ease.
There are a... |
I can't speak for Win32, but on unixes there is no real way of reliably doing this. In unix with the traditional unix filesystem, you can open a file and then unlink it (remove its entry from the directory) and use it, at which point the name isn't stored anywhere. In addition, because a file may have multiple hardli... |
On unixes there is no real way of reliably doing this. In unix with the traditional unix filesystem, you can open a file and then unlink it (remove its entry from the directory) and use it, at which point the name isn't stored anywhere. In addition, because a file may have multiple hardlinks into the filesystem, each... |
If you set the `border-collapse` property to `collapse`, IE7 will show empty cells. It also collapses the borders though so this might not be 100% what you want
CSS:
td {
border: 1px solid red;
}
table {
border-collapse: collapse;
}
Example HTML Document:
<html>
<he... |
Bad Address error means that the address location that you have given is invalid. With the case you have above I would guess it is because you are passing in a copy of `info` instead of a pointer to `info`'s memory location.
Looking at the docs, `copy_to_user` is defined as
copy_to_user(void __user * to, cons... |
One thing, that would annoy me a lot, are the '.svn' folders, that svn puts into every folder it tracks.
They look annoying, when you copy a folder, you should remember to not copy them (or your sandbox might be irritated) and it is a lot harder to grep through a bunch of folders, since there are often a lot of hit... |
A workaround that can achieve that is to add a servlet filter to do URL re-writes e.g.
re-write *NEXTEVENT* to /NEXTEVENT/*(the one before the NEXTEVENT)/*(the one after NEXTEVENT) or something similar. |
How do you bind an Enum to a DropDownList control in ASP.NET? |
|c#|.net|asp.net| |
Let's say I have the following simple enum:
enum Response
{
Yes = 1,
No = 2,
Maybe = 3
}
How can I bind this enum to a DropDownList control so that the descriptions are displayed in the list as well as retrieve the associated numeric value (1,2,3) once an option has been sel... |
You can start developing for Silverlight with a text editor. It might take a little longer to put things together, but you will understand a lot more about what is going on. |
Kevin's example is good, however:
> std::vector<T> buffer[width * height];
Should be
std::vector<T> buffer;
Expanding it a bit you could of course add operator-overloads instead of the at()-functions:
const T &operator()(int x, int y) const
{
return buffer[y * width + x];
}
... |
I would make the TelephoneNumber just contain a bunch of numbers (maybe make it plural), and refer to it this way: Contact/C0001/TelephoneNumber(s)
|
Although you can start class names with lower case letters and include underscores and dollar signs, the "naming **convention**" is to start the class name and each separate word with a capital letter (e.g. UsefulThing), and not include underscores. When I see classes like useful_thing it looks wrong because it's not t... |
I believe if you install the 3.5 framework, you get everything backwards to the 2.0 framework. The 3.5 (and 3.0) framework runs on the 2.0 CLR, so you're really getting the 2.0 runtime with the extra goodness of 3.0 and 2.5 on top of it.
You'd have to separately install the 1.1 framework.
You can see the install... |
Is there an easy way to create two columns in a popup text window? |
|c#|tabs|textbox|meaurestring|stringformat| |
This seemed like an easy thing to do. I just wanted to pop up a text window and display two columns of data -- a description on the left side and a corresponding value displayed on the right side. I haven't worked with Forms much so I just grabbed the first control that seemed appropriate, a TextBox. I thought using ta... |
|c#|controls|winforms|formatting| |
|c#|winforms|controls|formatting| |
This seemed like an easy thing to do. I just wanted to pop up a text window and display two columns of data -- a description on the left side and a corresponding value displayed on the right side. I haven't worked with Forms much so I just grabbed the first control that seemed appropriate, a TextBox. I thought using ta... |
|python|django| |
Can i print out a url (/admin/manage/products/add) of a certain view in a template?
Here is the rule i want to create a link for
(r'^manage/products/add/$', create_object, {'model': Product, 'post_save_redirect': ''}),
I would like to have /manage/products/add in a template without hardcoding it. How can i... |
If you use [named url patterns][1] you can do the follwing in your template
{% url create_object %}
[1]: http://www.djangoproject.com/documentation/url_dispatch/#naming-url-patterns |
The new (max) fields make it a lot easier to deal with the data from .NET code. With varbinary(max), you simply set the value of a SqlParameter to a byte array and you are done. WIth the image field, you need to write a few hundred lines of code to stream the data into and out of the field.
Also, the image/text fi... |
I don't think there is any other such Mac tool. I've never found the web interface too bad personally. |
"Cannot change DataType of a column once it has data" error in Visual Studio 2005 DataSet Designer |
|visual-studio|.net-2.0| |
I've got a DataSet in VisualStudio 2005. I need to change the datatype of a column in one of the datatables from System.Int32 to System.Decimal. When I try to change the datatype in the DataSet Designer I receive the following error:
"Property value is not valid. Cannot change DataType of a column once it has dat... |
How to override std::swap() |
|c++| |
std::swap() is used by many std containers (such as std::list and std::vector) during sorting and even assignment.
But the std implementation of swap() is very generalized and rather inefficient for custom types.
Thus efficiency can be gained by overriding std::swap() with a custom type specific implementation. B... |
How to overload std::swap() |
std::swap() is used by many std containers (such as std::list and std::vector) during sorting and even assignment.
But the std implementation of swap() is very generalized and rather inefficient for custom types.
Thus efficiency can be gained by overloading std::swap() with a custom type specific implementation. ... |
|c++|performance|optimisation| |
That's not quite what you're looking for, but might help:
http://blog.jeffhandley.com/archive/2008/01/27/enum-list-dropdown-control.aspx |
I am not sure how to do it in ASP.NET but check out [this][1] post... it might help?
Enum.GetValues(typeof(Response));
[1]: http://stackoverflow.com/questions/58743/databinding-an-enum-property-to-a-combobox-in-wpf#58819 |
Is there a way to loop through a table variable in TSQL without using a cursor? |
|sql-server|t-sql|loops| |
Let's say I have the following simple table variable:
declare @databases table
(
DatabaseID int,
Name varchar(15),
Server varchar(15)
)
-- insert a bunch rows into @databases
Is declaring and using a cursor my only option if I wanted to iterate throu... |
The machines are in different locations, home and work so software like SyncToy won't work.
I don't know about SyncBack. It's not clear from their web site if it can be done over the web. I can't find the client software on MS's site for Live Mesh.
I will check ideas here:
http://lifehacker.com/372175/free-way... |
From my work using smart phones, the best way I have found of preserving battery life is to ensure that everything you do not need for your program to function at that specific point is disabled.
For example, only switch Bluetooth on when you need it, similarly the phone capabilities, turn the screen brightness down... |
JavaScript sqlite |
|javascript|sqlite| |
Best recommendations for accessing and manipulation of sqlite databases from JavaScript. |
VS Code Snippets automatic synchronizer? |
|code-snippets| |
I use more than one machine for development in VS 2008. Is there a tool to automatically synchronize the snippets between the machines? Same concept of synchronizing browsers' bookmark. |
|visual-studio|code-snippets| |
My work is currently using a mostly OSS build process with Cruise Control as the engine and it is great. I would suggest that if you don't know why you would need TFS, it's probably not worth the cost.
The thing you have to keep in mind with the OSS stuff is that the software has either been in use by the Java crew ... |
If you are already aware of Catalyst, then I recommend focusing on it. It is mature, well-documented, and has a very large user-base, community, and collection of plug-ins. |
In the past I've chosen option C -- <i>Creating a 'long, narrow' table that stores dynamic column values as rows that then need to be pivoted to create a 'short, wide' rowset containing all the values for a specific entity.</i>. However, I was using an ORM, and that REALLY made things painful. I can't think of how you'... |
There's simply an overhead associated with using the JNI, see also:
http://java.sun.com/docs/books/performance/1st_edition/html/JPNativeCode.fm.html
So as others have suggested try to collate operations that would involve using the JNI. |
The most reliable manner of doing this is checking a site like <http://checkip.dyndns.org/> or similar. However, hardcoding such a URL is asking for eventual failure. You may wish to only perform this check if the current IP looks like an [RFC1918](http://www.faqs.org/rfcs/rfc1918.html) private address (`192.168.x.x` b... |
The most reliable manner of doing this is checking a site like <http://checkip.dyndns.org/> or similar, because until you actually go external to your network, you cannot find your external IP. However, hardcoding such a URL is asking for eventual failure. You may wish to only perform this check if the current IP looks... |
Look at enabling strict mode in the /etc/my.ini file. |
Unescaping angle-brackets through System.Xml.XmlWriter |
|c#|.net|xml| |
I'm writing a string containing some XML via System.Xml.XmlWriter. I'm stuck using WriteString(), and from the documentation:
> WriteString does the following:
> The characters &, <, and > are replaced with &amp;, &lt;, and &gt;, respectively.
I'd like this to stop, but I can't seem to find any XmlW... |
Jonathan Holland's answer is fundamentally correct, but it's worth adding that the API calls behind Dns.GetHostByName are fairly time consuming and it's a good idea to cache the results so that the code only has to be called once. |
Yes, the `Content-type` header in the user agent's request should include `multipart/form-data` as described in (at least) the HTML4 spec:
http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2 |
as a local variable in a C function:
int x[100000000000]; |
SQL Server 2005 has problems connecting to a website running on the same server. |
|c++|performance|optimization| |
|c++|performance|optimization|stl| |
|c++|performance|algorithm|optimization|stl| |
Using the IISReset command line tool will only restart IIS on the local machine, not on a remote server to which you are publishing.
Assuming that you are publishing to a Windows 2003 server, I'd suggest trying the slightly less drastic step of stopping and restarting the IIS AppPool in the web site or virtual folde... |
instead of the try..catch maybe you could try using
if( this && this._getGalleryInfo )
{
//use the function
}
you could also check in the same way this.element.rel ( if(this && this.element && this.element.rel) ... ) before using it.
it looks like there's a case that the _getGal... |
There is an article on using AppleScript to do this at <A HREF="http://www.macosxtips.co.uk/index_files/move-all-windows-to-main-display.html">macosxtips.co.uk</A>, and another at <A HREF="http://www.macosxhints.com/article.php?story=2007102012424539">macosxhints.com</A>. |
What is .MSPX? |
|.net|asp.net|microsoft| |
I've noticed a lot of microsoft sites have the *.MSPX extension. While I'm very familiar with ASP.NET, I've not seen this extension before.
Does anyone know what this identifies? |
cscope (http://cscope.sourceforge.net/) does this in a standalone xterm, and also can be used inside your favorite editor - it has great emacs and vi/vim support.
|
As python is in kind of an transition phase towards python 3 with breaking backward compatibility I don't think it is a good idea to go python 3 only. Based on the [timeline][1] there will be at least one or two following releases of the 2.x series after 2.6/3.0 in Oktober.
Beside not having python 3 available on yo... |
VB.NET on Vista, trying to get date (Today) causes security exception |
|vb.net|security|date|today| |
I have a VB6 program that someone recently helped me convert to VB.NET
In the program, when saving files, I stamp them with the date which I was getting by calling the Today() function.
When I try to run the new VB.NET code in Vista it throws a permission exception for the Today() . If I run Visual Studio Expres... |
I have a VB6 program that someone recently helped me convert to VB.NET
In the program, when saving files, I stamp them with the date which I was getting by calling the Today() function.
When I try to run the new VB.NET code in Vista it throws a permission exception for the Today() . If I run Visual Studio Expres... |
I don't know if this will work for your project but
you might try to attack the problem from the **link phase** of your build.
This would completely eliminate your #include problem.
All you would need to do is re-implement the interfaces in the included files to do what ever you want and then just link to the mock... |
How to add method using metaclass |