instruction stringlengths 0 30k ⌀ |
|---|
If your program validates the XML against the DTD during normal execution, then you should just get the DTD from wherever your program will get it.
If not and the DTD is extremely short (only a few lines), then storing it as a string in your code is probably okay.
Otherwise, I'd put it in an external file and have your unit test read it from that file. |
I would say your test scheme is not really useful. To fulfill the db query, the db server goes through several steps:
1. parse the SQL
2. work up a query plan, i. e. decide on which indices to use (if any), optimize etc.
3. if used, search the index for the pointers to the actual data
4. load the data from disk into a temporary location (hopefully memory)
5. perform the count() and avg() calculations
So, creating an array in Python and getting the average basically skips steps 1 to 4. As disk I/O is among the most expensive operations a program has to perform, this is a major flaw in the test (see also the answers to [this question][1] I asked here before). Even if you read the data from disk in your other test, the process is completely different and it's hard to tell how relevant the results are.
To obtain more information about where Postgres spends its time, I would suggest the following tests:
- Compare the execution time of your query to a SELECT without the aggregating functions
- If you find that the aggregation leads to a significant slowdown, try if Python does it faster, obtaining the raw data through the plain SELECT from the comparison.
To speed up your query, reduce disk access first. I doubt very much that iterating over a set of data records in memory and counting them or calculating the average value of one of their members is a task that takes significant amounts of time on a modern computer.
There's several ways to do that:
- Cache data (in memory!) for subsequent access, either via the db engine's own capabilities or with tools like memcached
- Reduce the size of your stored data
- Optimize the use of indices. Sometimes this can mean to skip index use altogether (after all, it's disk access, too). For MySQL, I seem to remember that it's recommended to skip indices if you assume that the query fetches more than 10% of all the data in the table.
- If your query makes good use of indices, I know that for MySQL databases it helps to put indices and data on seperate physical disks. However, I don't knw whether that's applicable for Postgres.
- There also might be more sophisticated problems such as swapping rows to disk if for some reason the result set can't be completely processed in memory. But I would leave that kind of research until I run into serious performance problems that I can't find another way to fix, as it requires knowledge about a lot of little under-the-hood details in your process.
[1]: http://stackoverflow.com/questions/26021/how-is-data-compression-more-effective-than-indexing-for-search-performance |
I would say your test scheme is not really useful. To fulfill the db query, the db server goes through several steps:
1. parse the SQL
2. work up a query plan, i. e. decide on which indices to use (if any), optimize etc.
3. if an index is used, search it for the pointers to the actual data, then go to the appropriate location in the data or
4. if no index is used, scan <i>the whole table</i> to determine which rows are needed
4. load the data from disk into a temporary location (hopefully, but not necessarily, memory)
5. perform the count() and avg() calculations
So, creating an array in Python and getting the average basically skips all these steps save the last one. As disk I/O is among the most expensive operations a program has to perform, this is a major flaw in the test (see also the answers to [this question][1] I asked here before). Even if you read the data from disk in your other test, the process is completely different and it's hard to tell how relevant the results are.
To obtain more information about where Postgres spends its time, I would suggest the following tests:
- Compare the execution time of your query to a SELECT without the aggregating functions (i. e. cut step 5)
- If you find that the aggregation leads to a significant slowdown, try if Python does it faster, obtaining the raw data through the plain SELECT from the comparison.
To speed up your query, reduce disk access first. I doubt very much that it's the aggregation that takes the time.
There's several ways to do that:
- Cache data (in memory!) for subsequent access, either via the db engine's own capabilities or with tools like memcached
- Reduce the size of your stored data
- Optimize the use of indices. Sometimes this can mean to skip index use altogether (after all, it's disk access, too). For MySQL, I seem to remember that it's recommended to skip indices if you assume that the query fetches more than 10% of all the data in the table.
- If your query makes good use of indices, I know that for MySQL databases it helps to put indices and data on seperate physical disks. However, I don't knw whether that's applicable for Postgres.
- There also might be more sophisticated problems such as swapping rows to disk if for some reason the result set can't be completely processed in memory. But I would leave that kind of research until I run into serious performance problems that I can't find another way to fix, as it requires knowledge about a lot of little under-the-hood details in your process.
[1]: http://stackoverflow.com/questions/26021/how-is-data-compression-more-effective-than-indexing-for-search-performance |
Secure all folders containing any sensitive info with the location tag. Encrypt any connection strings with [DPAPI][1].
[1]: http://msdn.microsoft.com/en-us/library/ms998280.aspx |
If your only intent is to get calling code to not make a mistake, and modify the collection when it should only be reading all that is necessary is to return an interface which doesn't support Add, Remove, etc.. Why not return IEnumerable<string>? Calling code would have to cast, which they are unlikely to do without knowing the internals of the property they are accessing.
If however your intent is to prevent the calling code from observing updates from other threads you'll have to fall back to solutions already mentioned, to perform a deep or shallow copy depending on your need.
|
Our company (and others) use the open source <a href="http://www.icu-project.org/">Internation Components for Unicode</a> (ICU) library originally developed by Taligent.
It handles strings, locales, conversions, date/times, collation, transformations, et. al.
Start with the <a href="http://www.icu-project.org/userguide/intro.html">ICU Userguide</a>
|
@CodingTheWheel:
There is one slight problem with your approach. Consider a call such as
XTRACE("x=%d", x);
This works fine in the debug build, but in the release build it will expand to:
("x=%d", x);
Which is perfectly legitimate C and will compile and usually run without side-effects but generates unnecessary code. The approach I usually use to eliminate that problem is:
1. Make the XTrace function return an int (just return 0, the return value doesn't matter)
2. Change the #define in the #else clause to:
0 && XTrace
Now the release version will expand to:
0 && XTrace("x=%d", x);
and any decent optimizer will throw away the whole thing since short-circuit evaluation would have prevented anything after the && from ever being executed.
Of course, just as I wrote that last sentence, I realized that perhaps the original form might be optimized away too and in the case of side effects, such as function calls passed as parameters to XTrace, it might be a better solution since it will make sure that debug and release versions will behave the same. |
You can use shared memory or named pipe to facilitate IPC as well. Conceptually this is similar to TCP/IP, but you don't have to worry about finding an unused port.
You have to make sure that the named objects you create are prefixed with "Global\" to allow them to be accessed by all sessions as described [here][1].
AFAIK there is no way for a service to directly interact with the desktop any more.
[1]: http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx |
One should not that [aku][1]'s answer will only protect the list as being read only. Elements in the list are still very writable. I don't know if there is any way of protecting non-atomic elements without cloning them before placing them in the read only list.
[1]: http://stackoverflow.com/questions/55502/return-collection-as-read-only#55507 |
One should note that [aku][1]'s answer will only protect the list as being read only. Elements in the list are still very writable. I don't know if there is any way of protecting non-atomic elements without cloning them before placing them in the read only list.
[1]: http://stackoverflow.com/questions/55502/return-collection-as-read-only#55507 |
Before you check the code in. |
When hacking something together for myself, I test at the end. Bad practice, but these are usually small things that I'll use a few times and that's it.
On a larger project, I write tests before I write a class and I run the tests after every change to that class. |
The [Beagle search engine][1] had code to parse Mork files. It's not the most memory efficient solution, but it worked and could be a useful starting point. Here's a link to the file:
[http://svn.gnome.org/viewvc/beagle/tags/BEAGLE_0_2_18/Util/Mork.cs?view=markup][2]
(These days Beagle doesn't use this parser anymore; we took the easier (and supported) path of writing a Thunderbird extension which just sent the data to Beagle itself. Has the disadvantage of not working while Thunderbird is closed, but has the advantage of not instilling the desire to bash your head in with the nearest blunt instrument.)
[1]: http://beagle-project.org
[2]: http://svn.gnome.org/viewvc/beagle/tags/BEAGLE_0_2_18/Util/Mork.cs?view=markup |
Open Calais probably use language parsing technology and language statics to guess which words or phrases are Names, Places, Companies, etc. Then, it is just another step to do some kind of search for those entities and return meta data.
Zementa probably does something similar, but matches the phrases against meta-data attached to images in order to acquire related results.
It certainly isn't easy. |
This is going to be a long answer, because I want to make sure you are fully aware of all the ways you can accomplish what you want to do.
The routing engine that powers the ASP.NET MVC Framework will work with the traditional ASP.NET Framework. You can take advantage of using the RouteTable and assigning routes, just like you would in an ASP.NET MVC application. You just don't get the MVC portion in traditional ASP.NET sites. That was a huge enhancement for the ASP.NET Framework and it was great to see them reuse that code and make it work in both frameworks. If you want to learn more about this, check out ScottGu's [post][1] and scroll down to URL Routing Improvements.
Now, if you still want to write you own. You will need to learn the ASP.NET HTTP pipeline and how to implement the [IHttpModule][2] and the [IHttpHandler][3] interfaces to create your own HttpModule or HttpHandler class to handle your routing. These interfaces are the key in writing your own routing engine. To help put those interfaces in a working example, I couldn't recommend this [MSDN article][4] enough. It shows you how to with either interface and explains the differences when creating your own routing/url rewriting engine.
Now, if you find out that this might be to much for you. There are third party libraries you can use of people who already wrote a routing/url rewriting engine in .NET. There was a question that I saw to long ago asking "[What What Url rewriter do you use for ASP.Net?][5]".
[1]: http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx
[2]: http://msdn.microsoft.com/en-us/library/system.web.ihttpmodule.aspx
[3]: http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx
[4]: http://msdn.microsoft.com/en-us/library/ms972974.aspx
[5]: http://stackoverflow.com/questions/14697/what-url-rewriter-do-you-use-for-aspnet |
|.net|asp.net|.net-3.5|crystal-reports| |
While not related to .net, I would consider obfuscation in Javascript, and possibly other interpeted languages. Javascript benefits well from obfuscation because it reduces the bandwith needed, and the tokens the parser has to read.
But obfuscating compiled bytecode doesn't really seem that usefull to me. I mean what would you try and achieve? I can only see obfuscation beeing slightly usefull in license checking code to avoid it beeing circumvented too easily. |
The main reason to use obfuscation is to protect intellectual property as you have indicated. It is generally much more cost effective to a business to purchase an obfuscation product like .NET Reactor than it is to try and legally enforce your copyrights.
Obfuscation can also provide other more incidental benefits such as performance improvements and assembly size reduction. These would the *engineering* benefits you are looking for.
|
Another system (not mentioned in the accepted answer yet) is PyInstaller, which worked for a PyQt project of mine when py2exe would not. I found it easier to use.
http://pyinstaller.python-hosting.com/ |
Another system (not mentioned in the accepted answer yet) is PyInstaller, which worked for a PyQt project of mine when py2exe would not. I found it easier to use.
http://pyinstaller.python-hosting.com/
Pyinstaller is based on Gordon McMillan's Python Installer. Which is no longer available. |
You asked for engineering reasons, so this is not strictly speaking an answer to the question. But I think it's a valid clarification.
As you say, obfuscation is intended to address a social problem. And social (or business) problems, unlike technical ones, rarely have a complete solution. There are only degrees of success in addressing or minimising the problem.
In this case, obfuscation will raise the barriers to someone decompiling and stealing your code. It will discourage casual attacks and, through inertia, may make your intellectual property less likely to be stolen. To make a tiresome analogy, an immobiliser doesn't prevent your car being stolen, but it will make it less likely.
Of course there is a cost, in maintainability, (possibly) in performance and most importantly in making it harder for users to accurately submit bug reports.
As GateKiller said, obfuscation won't prevent a determined team from decompiling, but (and it depends what your product is) how determined a team is likely to be attacking you?
So, this is not a technical solution to a social problem, it's a technical decision which adds one influence to a complex social structure. |
Best strategy to write hooks for subversion in Windows |
|subversion|hook| |
What is the best approach to write **hooks** for **Subversion** in **Windows**? As far as I know, only executable files can used. So what is the best choice?
- Plain batch files (very limited but perhaps OK for very simple solutions)
- Dedicated compiled executable applications (sledgehammer to crack a nutshell)
- Some other hybrid choice (like a batch file running a Powershell script) |
I attempted to use the Entity Framework on an existing project (~60 tables, 3 with inheritance) just to see what it was all about. My experience boiled down to:
The designer surface is kludgy. The mapping isn’t intuitive and someone must have thought that having several tool windows open at the same time is acceptable. It took a long time to manually create an object and map the right fields – then it was still odd talking to it from the code. While having something handling the database communication is essential, *I feel that handing the control over to EF was far more of a fight than doing it manually*.
Sometimes the designer just doesn’t load until you restart Visual Studio. I’m sure it’s just a bug but restarting VS is annoying.
All your work ends up in a single file, I’d hate to merge multiple developer editions.
The resultant SQL (watched via the Profiler) wasn’t very good. I didn’t really delve into looking why, but you’d be pressed to write something worse on a first attempt.
|
Why is it considered bad practice to use cursors in SQL Server? |
|sql-server| |
I knew of some performance reasons back in the SQL 7 days, but do the same issues still exist in SQL Server 2005? If I have a resultset in a stored procedure that I want to act upon individually, are cursors still a bad choice? If so, why? |
The following will do it:
for i in `seq 1 N` ; do mv foo$i `printf foo%05d $i` ; done
(Although technically `seq` isn't part of `bash`, it's in [gnu coreutils][1], and I just found out it's not in OS X!)
[1]: http://www.gnu.org/software/coreutils/ |
The following will do it:
for i in ((i=1; i<=N; i++)) ; do mv foo$i `printf foo%05d $i` ; done
**EDIT:** changed to use ((i=1,...)), thanks [mweerden][1]!
[1]: http://stackoverflow.com/users/4285/mweerden |
How do I position one image on top of another in HTML? |
|html|rails| |
I'm a beginning rails programmer, attempting to show many images on a page. Some images are to lay on top of others. To make it simple, say I want a blue square, with a red square in the upper right corner of the blue square (but not tight in the corner). I am trying to avoid compositing (with ImageMagick and similar) due to perfomance issues.
I just want to position overlapping images relative to one another.
As a more difficult example, imagine an odometer placed inside a larger image. For six digits, I would need to composite a million different images, or do it all on the fly, where all that is needed is to place the six images on top of the other one. |
|html|css| |
|html|css|graphics| |
Hierarchical Data In ASP.NET MVC |
|asp.net|asp.net-mvc| |
I am trying to come up with the best way to render some hierarchical data in to a nested unordered list using ASP.NET MVC. Does anyone have any tips on how to do this?
|
This is going to be a long answer, because I want to make sure you are fully aware of all the ways you can accomplish what you want to do.
The routing engine that powers the ASP.NET MVC Framework will work with the traditional ASP.NET Framework. You can take advantage of using the RouteTable and assigning routes, just like you would in an ASP.NET MVC application. You just don't get the MVC portion in traditional ASP.NET sites. That was a huge enhancement for the ASP.NET Framework and it was great to see them reuse that code and make it work in both frameworks. If you want to learn more about this, check out ScottGu's [post][1] and scroll down to URL Routing Improvements.
Now, if you still want to write you own. You will need to learn the ASP.NET HTTP pipeline and how to implement the [IHttpModule][2] and the [IHttpHandler][3] interfaces to create your own HttpModule or HttpHandler class to handle your routing. These interfaces are the key in writing your own routing engine. To help put those interfaces in a working example, I couldn't recommend this [MSDN article][4] enough. It shows you how to with either interface and explains the differences when creating your own routing/url rewriting engine.
Now, if you find out that this might be to much for you. There are third party libraries you can use of people who already wrote a routing/url rewriting engine in .NET. Here is a question that I saw not to long ago asking "[What What Url rewriter do you use for ASP.Net?][5]" right here on SO.
[1]: http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx
[2]: http://msdn.microsoft.com/en-us/library/system.web.ihttpmodule.aspx
[3]: http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx
[4]: http://msdn.microsoft.com/en-us/library/ms972974.aspx
[5]: http://stackoverflow.com/questions/14697/what-url-rewriter-do-you-use-for-aspnet |
This is going to be a long answer, because I want to make sure you are fully aware of all the ways you can accomplish what you want to do.
The routing engine that powers the ASP.NET MVC Framework will work with the traditional ASP.NET Framework. You can take advantage of using the RouteTable and assigning routes, just like you would in an ASP.NET MVC application. You just don't get the MVC portion in traditional ASP.NET sites. That was a huge enhancement for the ASP.NET Framework and it was great to see them reuse that code and make it work in both frameworks. If you want to learn more about this, check out ScottGu's [post][1] and scroll down to URL Routing Improvements.
Now, if you still want to write you own. You will need to learn the ASP.NET HTTP pipeline and how to implement the [IHttpModule][2] and the [IHttpHandler][3] interfaces to create your own HttpModule or HttpHandler class to handle your routing. These interfaces are the key in writing your own routing engine. To help put those interfaces in a working example, I couldn't recommend this [MSDN article][4] enough. It shows you how to with either interface and explains the differences when creating your own routing/url rewriting engine.
Now, if you find out that this might be to much for you. There are third party libraries you can use of people who already wrote a routing/url rewriting engine in .NET. Here is a question that I saw not to long ago asking "[What Url rewriter do you use for ASP.Net?][5]" right here on SO.
[1]: http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx
[2]: http://msdn.microsoft.com/en-us/library/system.web.ihttpmodule.aspx
[3]: http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx
[4]: http://msdn.microsoft.com/en-us/library/ms972974.aspx
[5]: http://stackoverflow.com/questions/14697/what-url-rewriter-do-you-use-for-aspnet |
You can do it, but the downside is that it can't be part of the prototype:
function Restaurant()
{
var private_stuff = function() // Only visible inside Restaurant()
{
}
this.use_restroom = function() // use_restroom is visible to all
{
private_stuff();
}
}
|
You can do it, but the downside is that it can't be part of the prototype:
function Restaurant()
{
var myPrivateVar;
var private_stuff = function() // Only visible inside Restaurant()
{
myPrivateVar = "I can set this here!";
}
this.use_restroom = function() // use_restroom is visible to all
{
private_stuff();
}
this.buy_food = function() // buy_food is visible to all
{
private_stuff();
}
}
|
I assume with shards we're talking about horizontal partitioning and not vertical partitioning ([here are the differences on Wikipedia][1]).
First off, **stretch vertical partitioning** as far as you can take it before you consider horizontal partitioning. It's easy in Rails to have different models point to different machines and for most Rails sites, this will bring you far enough.
For horizontal partitioning, in an ideal world, this would be handled at the **application layer** in Rails. But while it's not hard, it's not trivial in Rails, and by the time you need it, usually your application has grown beyond the point where this is feasible since you have ActiveRecord calls sprinkled all over the place. And no one, developers or management, likes working on it before you need it since everyone would rather work on features users will use now rather than on partitioning which may not come into play for years after your traffic has exploded.
**ActiveRecord layer**... not easy from what I can see. Would require lots of monkey patching into Rails internals.
At [Spock][2] we ended up handling this using a **custom MySQL proxy** and open sourced it on SourceForge as [Spock Proxy][3]. ActiveRecord thinks it's talking to one MySQL database machine when reality it's talking to the proxy, which then talks to one or more MySQL databases, merges/sorts the results, and returns them to ActiveRecord. Requires only a few changes to your Rails code. Take a look at the Spock Proxy SourceForge page for more details and for our reasons for going this route.
[1]: http://en.wikipedia.org/wiki/Partition_(database)
[2]: http://www.spock.com/about
[3]: http://spockproxy.sourceforge.net/ |
Indeed, for security reasons it is no longer possible to communicate directly with the "desktop". What exactly is the "desktop" anyway, when you live in a machine with multiple active users + remote sessions?
The general way to solve the problem is to use service apps which communicate via some RPC mechanism (TCP/IP, IPC, .Net Remoting Channels over one of those, etc). Its kind of a pain, but I think the benefits are worth the change. |
SharePoint Permissions |
|sharepoint|permissions| |
I would like to create a folder that users who do not have privileges to view the rest of the site can see. This user group would be granted access to the site, but I only want them to be able to view one particular page.
Is this possible to do without going to every single page and removing the new user group's access? |
This is going to be a long answer, because I want to make sure you are fully aware of all the ways you can accomplish what you want to do.
The routing engine that powers the ASP.NET MVC Framework will work with the traditional ASP.NET Framework. You can take advantage of using the RouteTable and assigning routes, just like you would in an ASP.NET MVC application. You just don't get the MVC portion in traditional ASP.NET sites. That was a huge enhancement for the ASP.NET Framework and it was great to see them reuse that code and make it work in both frameworks. If you want to learn more about this, check out ScottGu's [post][1] and scroll down to URL Routing Improvements. Also here is a [reference][2] on how to use the System.Web.Routing in WebForms by Phil Haack.
Now, if you still want to write you own. You will need to learn the ASP.NET HTTP pipeline and how to implement the [IHttpModule][3] and the [IHttpHandler][4] interfaces to create your own HttpModule or HttpHandler class to handle your routing. These interfaces are the key in writing your own routing engine. To help put those interfaces in a working example, I couldn't recommend this [MSDN article][5] enough. It shows you how to with either interface and explains the differences when creating your own routing/url rewriting engine.
Now, if you find out that this might be to much for you. There are third party libraries you can use of people who already wrote a routing/url rewriting engine in .NET. Here is a question that I saw not to long ago asking "[What Url rewriter do you use for ASP.Net?][6]" right here on SO.
[1]: http://weblogs.asp.net/scottgu/archive/2008/05/27/asp-net-mvc-preview-3-release.aspx
[2]: http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx
[3]: http://msdn.microsoft.com/en-us/library/system.web.ihttpmodule.aspx
[4]: http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx
[5]: http://msdn.microsoft.com/en-us/library/ms972974.aspx
[6]: http://stackoverflow.com/questions/14697/what-url-rewriter-do-you-use-for-aspnet |
I have trouble wrapping my head around lambda expressions because I work in Visual FoxPro, which has Macro substitution and the ExecScript{} and Evaluate() functions, which seem to serve much the same purpose.
? Calculator(10, 23, "a + b")
? Calculator(10, 23, "a - b");
FUNCTION Calculator(a, b, op)
RETURN Evaluate(op)
One definite benefit to using formal lambdas is (I assume) compile-time checking: Fox won't know if you typo the text string above until it tries to run it.
This is also useful for data-driven code: you can store entire routines in memo fields in the database and then just evaluate them at run-time. This lets you tweak part of the application without actually having access to the source. (But that's another topic altogether.) |
I've had good success using [Mockito][1].
When I tried learning about JMock and EasyMock, I found the learning curve to be a bit steep (though maybe that's just me).
I like Mockito because of its simple and clean syntax that I was able to grasp pretty quickly. The minimal syntax is designed to support the common cases very well, although the few times I needed to do something more complicated I found what I wanted was supported and easy to grasp.
Here's an (abridged) example from the Mockito homepage:
import static org.mockito.Mockito.*;
List mockedList = mock(List.class);
mockedList.clear();
verify(mockedList).clear();
It doesn't get much simpler than that.
The only major downside I can think of is that it won't mock static methods.
[1]: http://code.google.com/p/mockito/ |
I would say your test scheme is not really useful. To fulfill the db query, the db server goes through several steps:
1. parse the SQL
2. work up a query plan, i. e. decide on which indices to use (if any), optimize etc.
3. if an index is used, search it for the pointers to the actual data, then go to the appropriate location in the data or
4. if no index is used, scan <i>the whole table</i> to determine which rows are needed
4. load the data from disk into a temporary location (hopefully, but not necessarily, memory)
5. perform the count() and avg() calculations
So, creating an array in Python and getting the average basically skips all these steps save the last one. As disk I/O is among the most expensive operations a program has to perform, this is a major flaw in the test (see also the answers to [this question][1] I asked here before). Even if you read the data from disk in your other test, the process is completely different and it's hard to tell how relevant the results are.
To obtain more information about where Postgres spends its time, I would suggest the following tests:
- Compare the execution time of your query to a SELECT without the aggregating functions (i. e. cut step 5)
- If you find that the aggregation leads to a significant slowdown, try if Python does it faster, obtaining the raw data through the plain SELECT from the comparison.
To speed up your query, reduce disk access first. I doubt very much that it's the aggregation that takes the time.
There's several ways to do that:
- Cache data (in memory!) for subsequent access, either via the db engine's own capabilities or with tools like memcached
- Reduce the size of your stored data
- Optimize the use of indices. Sometimes this can mean to skip index use altogether (after all, it's disk access, too). For MySQL, I seem to remember that it's recommended to skip indices if you assume that the query fetches more than 10% of all the data in the table.
- If your query makes good use of indices, I know that for MySQL databases it helps to put indices and data on seperate physical disks. However, I don't know whether that's applicable for Postgres.
- There also might be more sophisticated problems such as swapping rows to disk if for some reason the result set can't be completely processed in memory. But I would leave that kind of research until I run into serious performance problems that I can't find another way to fix, as it requires knowledge about a lot of little under-the-hood details in your process.
<b>Update:</b>
<i>I just realized that you seem to have no use for indices for the above query and most likely aren't using any, too, so my advice on indices probably wasn't helpful. Sorry. Still, I'd say that the aggregation is not the problem but disk access is. I'll leave the index stuff in, anyway, it might still have some use.</i>
[1]: http://stackoverflow.com/questions/26021/how-is-data-compression-more-effective-than-indexing-for-search-performance |
How to serialize a graph structure? |
|serialization|graph| |
Flat files and relational databases give us a mechanism to serialize structured data. XML is superb for serializing un-structured tree-like data.
But many problems are best represented by graphs. A thermal simulation program will, for instance, work with temperature nodes connected to each others through resistive edges.
So what is the best way to serialize a graph structure? I know XML can, to some extent, do it---in the same way that a relational database can serialize a complex web of objects: it usually works but can easily get ugly.
I know about the dot language used by the graphviz program, but I'm not sure this is the best way to do it. This question is probably the sort of thing academia might be working on and I'd love to have references to any papers discussing this. |
@[modesty]():
> I wish there was a Mac version.
You can install the font on a Mac. I use it all the time, everywhere, without any problem. The only thing to pay attention for is to set `nomacatsui` when working with GVIM, or better yet, switch to [MacVim](http://code.google.com/p/macvim/). |
I test constantly. After I finish even a loop inside of a function, I run the program and hit a breakpoint at the top of the loop, then run through it. This is all just to make sure that the process is doing exactly what I want it to.
Then, once a function is finished, you test it in it's entirety. You probably want to set a breakpoint just before the function is called, and check your debugger to make sure that it works perfectly.
I guess I would say: "Test often." |
I've only recently added unit testing to my regular work flow but I write unit tests:
* to express the requirements for each new code module (right after I write the interface but before writing the implementation)
* every time I think "it had better ... by the time I'm done"
* when something breaks, to quantify the bug and prove that I've fixed it
* when I write code which explicitly allocates or deallocates memory---I loath hunting for memory leaks...
I run the tests on most builds, and always before running the code. |
[YSlow][1] can give you a quick analysis of different metrics.
[1]: http://developer.yahoo.com/yslow/ |
It sounds like in the console situation you are running with your current user credentials, which have access to the PSI. When running from the web, it's running with the creds of the IIS application instance. I think you'd either need to set up delegation to pass the session creds to the IIS application, or use some static creds for your IIS app that have access to the PSI. |
Store procedures should be used as much as possible, if your writing SQL into code your already setting yourself up for headaches in the futures. It takes about the same time to write a SPROC as it does to write it in code.
Consider a query that runs great under a medium load but once it goes into fulltime production your badly optimized query hammers the system and brings it to a crawl. In most SQL servers you are not the only application/service that is using it. Your application has now brought a bunch of anger people at your door.
If you have your queries in SPROCs you also allow your friendly DBA to manage and optimize with out recompiling or breaking your app. Remember DBA's are experts in this field, they know what to do and not do. It makes sense to utilise there greater knowledge! |
Store procedures should be used as much as possible, if your writing SQL into code your already setting yourself up for headaches in the futures. It takes about the same time to write a SPROC as it does to write it in code.
Consider a query that runs great under a medium load but once it goes into fulltime production your badly optimized query hammers the system and brings it to a crawl. In most SQL servers you are not the only application/service that is using it. Your application has now brought a bunch of angry people at your door.
If you have your queries in SPROCs you also allow your friendly DBA to manage and optimize with out recompiling or breaking your app. Remember DBA's are experts in this field, they know what to do and not do. It makes sense to utilise their greater knowledge!
EDIT: someone said that recompile is a lazy excuse! yeah lets see how lazy you feel when you have to recompile and deploy your app to 1000's of desktops, all because the DBA has told you that your ad-hoc Query is eating up too much Server time! |
Ubuntu 32 bit maximum address space |
|memory|ubuntu|operating-system| |
Jeff covered this a while back [on his blog][1] in terms of 32 bit Vista.
Does the same 32 bit 4 GB memory cap that applies in 32 bit Vista apply to 32 bit Ubuntu? Are there any 32 bit operating systems that have creatively solved this problem?
[1]: http://www.codinghorror.com/blog/archives/000811.html |
I would try running the tests from the command line using [MSTest.exe][1]. This might help isolate the problem to Visual Studio, and at least give you some method of running the tests successfully.
[1]: http://msdn.microsoft.com/en-us/library/ms182486(VS.80).aspx |
Modifying a spreadsheet using a VB macro |
|excel|vba|macros| |
I have two spreadsheets... when one gets modified in a certain way I want to have a macro run that modifies the second in an appropriate manner. I've already isolated the event I need to act on (the modification of any cell in a particular column), I just can't seem to find any concrete information on accessing and modifying another spreadsheet (this spreadsheet is located on a different LAN share also... the user has access to both, though).
Any help would be great. References on how to do this or something similar are just as good as concrete code samples. |
There's a lot to the whole process. The single easiest way to do it is to use services similar to paypal, so that you never actually handle any credit card data. Apart from that, there's a quite a bit of stuff to go through to get approved to offer credit card services on your website. You should probably talk with your bank, and the people who issue your merchant ID to help you in setting up the process. |
In theory, all 32-bit OSes have that problem. You have 32 bits to do addressing. 2^32 bits / 2^10 (bits per kb) / 2^10 (kb per mb) / 2^10 (mb per gb) = 2^2 = 4gb.
Although there are some ways around it. (Look up the jump from 16-bit computing to 32-bit computing. They hit the same problem.) |
This is my understanding of your question: You have a plugin object that may have to listen for events on x data objects - you don't want to subscribe to the event on each data object though. I'm assuming that several plugins may want to listen to events on the same data object.
You could create a session type object. Each plugin listens for events on the session object. The data object no longer raises the event - it calls the session object to raise the event (one of the parameters would have to be the data object raising the event).
That means that your plugins only have to subscribe to one event, but they get the event from all data objects.
On the other hand, if only one plugin will ever listen to a data object at a time, why not just have the data object call the plugin directly? |
Well, with windows, there's something called [PAE][1], which means you can access up to 64 GB of memory on a windows machine. The downside is that most apps don't support actually using more than 4 GB of RAM. Only a small number of apps, like SQL Server are programmed to actually take advantage of all the extra memory.
[1]: http://en.wikipedia.org/wiki/Physical_Address_Extension |
|svn|subversion|hook| |
|svn|hook| |
What is the best approach to write **hooks** for **Subversion** in **Windows**? As far as I know, only executable files can used. So what is the best choice?
- Plain batch files (very limited but perhaps OK for very simple solutions)
- Dedicated compiled executable applications (sledgehammer to crack a nutshell?)
- Some other hybrid choice (like a batch file running a Powershell script) |
What is the best approach to write **hooks** for **Subversion** in **Windows**? As far as I know, only executable files can be used. So what is the best choice?
- Plain batch files (very limited but perhaps OK for very simple solutions)
- Dedicated compiled executable applications (sledgehammer to crack a nutshell?)
- Some other hybrid choice (like a batch file running a Powershell script) |
Example 1 **dissociates** the $query variable from the MySQL result. The MySQL result still exists in memory, and will continue to exist and waste memory until garbage collection occurs.
Example 2 **frees** the MySQL result immediately, releasing the used resources.
However, since PHP pages are generally short-lived with small result-sets, the memory saved is trivial. You will not notice a slowdown unless you leave **a ton** of results in memory over a long period of time on pages that run for a long time.
Brian,
PHP *can* garbage collect the MySQL result, it just doesn't happen immediately.
The result lives in PHP's memory pool, not in the MySQL server's.
(the locality of memory when using unbuffered queries is slightly different, but they're so rarely used in PHP as to not be worth mentioning)
|
How to efficiently archive older parts of a big (multi-GB) SQL Server database? |
|sql|sql-server| |
Right now I am working on a solution to archive older data from a big working database to a separate archive database with the same schema. I move the data using SQL scripts and SQL Server Management Objects (SMO) from a .Net executable written in C#.
The archived data should still be accessible and even (occassionally) changeable, we just want it out of the way to keep the working database lean and fast.
Hurling large portions of data around and managing the relations between tables has proven to be quite a challenge.
I wonder if there is a better way to archive data with SQL Server.
Any ideas? |
> Consolidate them. Create a timer
> service and ask that for the timers.
> It will only need to keep 1 active
> timer (for the next due call)...
For this to be an improvement over just creating lots of Threading.Timer objects, you have to assume that it isn't exactly what Threading.Timer is already doing internally. I'd be interested to know how you came to that conclusion (I haven't disassembled the native bits of the framework, so you could well be right). |
I hope this helps. I'm just doing the trick of `float`ing the buttons on the right - like in normal wizard :-)
This way the Prev button is left of the Next button but the Next comes first in the HTML code:
<html>
<head>
<style>
.f {
float: right;
}
</style>
</head>
<body>
<form action="action" method="get">
<input type="text" name="abc">
<div id="buttons">
<input type="submit" class="f" name="next" value="Next">
<input type="submit" class="f" name="prev" value="Prev">
<div style="clear:both"></div><!-- Need this to have the buttons actually inside div#buttons -->
</div>
</form>
</body>
</html>
Hope this helps... :-)
Edit: benefits over other suggestions: no javascript, accessible, both buttons remain `type="submit"` |
No, from MSDN on HttpContext.Current: "Gets or sets the HttpContext object for the current HTTP request." In other words it is a HttpContext object, not a Page. |
No, from MSDN on HttpContext.Current: "Gets or sets the HttpContext object for the current HTTP request." In other words it is a HttpContext object, not a Page.
You can get to the Page via HttpContext using:
Page page = HttpContext.Current.Handler as Page;
if (page != null)
{
// Use page instance.
}
|
Do you mean that you need the values sorted by the value of the key?
In that case, this should do it:
for key in sorted(d.keys()):
print d[key] |
Do you mean that you need the values sorted by the value of the key?
In that case, this should do it:
for key in sorted(d):
print d[key]
**EDIT:** changed to use sorted(d) instead of sorted(d.keys()), thanks [Eli][1]!
[1]: http://stackoverflow.com/users/1694/eli-courtwright |
I think cursors get a bad name because SQL newbies discover them and think "Hey a for loop! I know how to use those!" and then they continue to use them for everything.
If you use them for what they're designed for, I can't find fault with that. |
SQL is a set based language--that's what it does best.
I think cursors are still a bad choice unless you understand enough about them to justify their use in limited circumstances.
Another reason I don't like cursors is clarity. The cursor block is so ugly that it's difficult to use in a clear and effective way.
All that having been said, there _are_ some cases where a cursor really is best--they just aren't usually the cases that beginners want to use them for.
|
The basic issue, I think, is that databases are designed and tuned for set-based operations -- selects, updates, and deletes of large amounts of data in a single quick step based on relations in the data.
In-memory software, on the other hand, is designed for individual operations, so looping over a set of data and potentially performing different operations on each item serially is what it is best at.
Looping is not what the database or storage architecture are designed for, and even in SQL Server 2005, you are not going to get performance anywhere close to you get if you pull the basic data set out into a custom program and do the looping in memory, using data objects/structures that are as lightweight as possible. |
Because cursors take up memory and create locks.
What you are really doing is attempting to force set-based technology into non-set based functionality. And, in all fairness, I should point out that cursors *do* have a use, but they are frowned upon because many folks who are not used to using set-based solutions use cursors instead of figuring out the set-based solution.
But, when you open a cursor, you are basically loading those rows into memory and locking them, creating potential blocks. Then, as you cycle through the cursor, you are making changes to other tables and still keeping all of the memory and locks of the cursor open.
All of which has the potential to cause performance issues for other users.
So, as a general rule, cursors are frowned upon. Especially if that's the first solution arrived at in solving a problem. |
I found this site called [Visual Studio Gallery][1] - it has a lot of visual studio add-ins. I'm browsing it right now and I recommend everyone to visit it.
[1]: http://www.visualstudiogallery.com/ |
I don't understand why people start debates like this. It really serves no purpose than to start flame wars at then end of which nothing is gained. Now if the C# team was trying to phase out one style in favor of the other, I can see the reason to argue over the merits of each style. But since both are going to remain in the language, why not use the one *you* prefer and let everybody do the same. It's like the use of everybody's favorite ternary operator: some like it and some don't. At the end of the day, it makes no difference to the compiler.
This is like arguing with your siblings over which is your favorite parent: it doesn't matter unless they are divorcing! |
You could try [NDOC][1] or [SandCastle][2] if you dont mind using 3rd party tools.
[1]: http://ndoc.sourceforge.net/
[2]: http://www.codeplex.com/Sandcastle |
Actually it's in the project properties. Build tab, Output section, XML documentation file, and enter the filename. It will be built on every build of the project.
After that you can build the actual help with [Sandcastle][1].
[1]: http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&displaylang=en |
You can use [Lint][1] to do that.
Unusually there isn't a free OS version of the tool available.
[1]: http://www.gimpel.com/ |
You can use [Lint][1] to do that.
Unusually there isn't a free OS version of the tool available.
You can remove #includes by passing by reference instead of passing by value and forward declaring. This is because the compiler doesn't need to know the size of the object at compile time. This will require a large amount of manual work on your behalf however. The good thing is it will reduce your compile times.
[1]: http://www.gimpel.com/ |
XML is very verbose. Whenever I do it, I roll my own. Here's an example of a 3 node directed acyclic graph. It's pretty compact and does everything I need it to do:
0: foo
1: bar
2: bat
----
0 1
0 2
1 2
|
haXe can't iterate over Dynamic variables (as the compiler says).
You can make it work in several ways, where this one is probably easiest (depending on your situation):
var d : {a:Array<Dynamic>} = getDynamic();
for(t in d.a) { ... }
You could also change Dynamic to the type of the contents of the array.
PS: yay haXe! |
On a less academic, more practical note, in [CubicTest][1] we use [Xstream][2] (Java) to serialize tests to and from xml. Xstream handles graph-structured object relations, so you might learn a thing or two from looking at it's source and the resulting xml. You're right about the *ugly* part though, the generated xml files don't look pretty.
[1]: http://cubictest.openqa.org
[2]: http://xstream.codehaus.org/ |
One example you might be familiar is Java serialization. This effectively serializes by graph, with each object instance being a node, and each reference being an edge. The algorithm used is recursive, but skipping duplicates. So the pseudo code would be:
serialize(x):
done - a set of serialized objects
if(serialized(x, done)) then return
otherwise:
record properties of x
record x as serialized in done
for each neighbour/child of x: serialize(child)
Another way of course is as a list of nodes and edges, which can be done as XML, or in any other preferred serialization format, or as an adjacency matrix.
|