instruction stringlengths 0 30k ⌀ |
|---|
My automated functional tests usually follow one of two patters:
* Database Connected Tests
* Mock Persistence Layer Tests
**Database Connected Tests**
When I have automated tests that are connected to the database, I usually make a single test database template that has enough data for all the tests. When the automated tests are run, a new test database is generated from the template for every test. The test database has to be constantly re-generated because test will often change the data. As tests are added, I usually append more data to the test database template.
There are some nice advantages to this testing method. The obvious advantage is that the tests also exercise your schema. Another advantage is that after setting up the initial tests, most new tests will be able to re-use the existing test data. This makes it easy to add more tests.
The downside is that the test database will become unwieldy. Because data will usually be added one test at time, it will be inconsistent and maybe even unrealistic. You will also end up cursing the person who setup the test database when there is a significant database schema change (which for me usually means I end up cursing myself).
This style of testing obviously doesn't work if you can't generate new test databases at will.
**Mock Persistence Layer Tests**
For this pattern, you create [mock objects][1] that live with the test cases. These mock objects intercept the calls to the database so that you can programmatically provide the appropriate results. Basically, when the code you're testing calls the <code>findCustomerByName()</code> method, your mock object is called instead of the persistence layer.
The nice thing about using mock object tests is that you can get very specific. Often times, there are execution paths that you simply can't reach in automated tests w/o mock objects. They also free you from maintaining a large, monolithic set of test data.
Another benefit is the lack of external dependencies. Because the mock objects simulate the persistence layer, your tests are no longer dependent on the database. This is often the deciding factor when choosing which pattern to choose. Mock objects seem to get more traction when dealing with legacy database systems or databases with stringent licensing terms.
The downside of mock objects is that they often result in a lot of extra test code. This isn't horrible because almost any amount of testing code is cheap when amortized over the number of times you run the test, but it can be annoying to have more test code then production code.
[1]: http://www.mockobjects.com/ |
well, if it's 2-D, then all lines are on the only plane.
So this is basic 3-D geometry. You should be able to do this with a straightforward equation.
Check out this page: http://local.wasp.uwa.edu.au/~pbourke/geometry/planeline/ The second solution should be easy to implement in code, as long as you translate the coordinates of your rectangle into the equation of a plane.
Check that your denominator isn't zero (line doesn't intersect or is contained in the plane) and you'll be good to go. |
Hehe this was sort of asked moments ago and Jeff pointed out:
[http://www.regular-expressions.info/refflavors.html](http://www.regular-expressions.info/refflavors.html).
There is a comparison of regular expression capabilities across tools and languages. |
I've found that different implementations of regular expressions often have subtle differences in what exactly they support. If you want to be entirely sure that the result will be the same in both frontend and backend, the savest choice would be to make an Ajax call to your PHP backend and use the same piece of PHP code for both regex evaluations.
|
+1 for using a file.ext.end signaler if possible, where the contents of file.ext.end is a checksum for the larger file. This isn't for security so much as it is to make sure nothing got garbled along the way. If someone can insert their own file into the large stream they can replace the checksum as well. |
If the regular expressions are simple then there should be no issue, as the basics of regular expressions are common across most implementations.
For particulars then it would be best to study both implementations:
<http://www.regular-expressions.info/php.html>
<http://www.regular-expressions.info/javascript.html>
Javascripts implementation is probably the more basic, so if you are going for a lowest common denominator approach then aim for that one. |
Stack automatic are variables which are allocated on the stack of the current method. The idea behind designing a class which can acts as Stack automatic is that it should be possible to fully initialize it with one call and destroy it with another. It is essential that the destructor frees all resources allocated by the object and its constructor returns an object which has been fully initialized and ready for use. Similarly for the copy operation - the class should be able to be easily made copies, which are fully functional and independent.
The usage of such class should be similar to how primitive int, float, etc. are used. You define them (eventually give them some initial value) and then pass them around and in the end leave the compiler to the cleaning. |
I've heard only good things about [ReSharper][1]. It's on my to-learn list.
[1]: http://www.jetbrains.com/resharper |
For me, Ctrl+Shift+F maps to Find in Files. When I need to format code, I highlight it and hit Ctrl+K, Ctrl+F.
I understand this doesn't really address automated formatting, I just wanted to clarify for those who may not know this feature even exists in VS. |
No, you shouldn't. Feel free to try it out on a new project, but a lot of people familiar with ASP.NET webforms aren't loving it yet, due to having to muck around with raw HTML + lots of different concepts + pretty slim pickings on documentation/tutorials.
|
I have created a recursive function to concatenate a list of strings with a separator between them. I use it mostly to create SQL expressions, by passing a list of fields as the '*items*' and a '*comma+space*' as the separator. Here's the function (It uses some Borland Builder native data types, but can be adapted to fit any other environment):
String ArrangeString(TStringList* items, int position, String separator)
{
String result;
result = items->Strings[position];
if (position <= items->Count)
result += separator + ArrangeString(items, position + 1, separator);
return result;
}
I call it this way:
String columnsList;
columnsList = ArrangeString(columns, 0, ", ");
Imagine you have an array named '*fields*' with this data inside it: '*albumName*', '*releaseDate*', '*labelId*'. Then you call the function:
ArrangeString(fields, 0, ", ");
As the function starts to work, the variable '*result*' receives the value of the position 0 of the array, which is '*albumName*'.
Then it checks if the position it's dealing with is the last one. As it isn't, then it concatenates the result with the separator and the result of a function, which, oh God, is this same function. But this time, check it out, it call itself adding 1 to the position.
ArrangeString(fields, 1, ", ");
It keeps repeating, creating a LIFO pile, until it reaches a point where the position being dealt with IS the last one, so the function returns only the item on that position on the list, not concatenating anymore. Then the pile is concatenated backwards.
Got it? If you don't, I have another way to explain it. :o) |
Unfortunately the only API that isn't deprecated is located in the ApplicationServices framework, which doesn't have a bridge support file, and thus isn't available in the bridge. If you're wanting to use ctypes, you can use ATSFontGetFileReference after looking up the ATSFontRef.
Cocoa doesn't have any native support, at least as of 10.5, for getting the location of a font. |
Recursion works best with what I like to call "fractal problems", where you're dealing with a big thing that's made of smaller versions of that big thing, each of which is an even smaller version of the big thing, and so on. If you ever have to traverse or search through something like a tree or nested identical structures, you've got a problem that might be a good candidate for recursion.
People avoid recursion for a number of reasons:
1. Most people (myself included) cut their programming teeth on procedural or object-oriented programming as opposed to functional programming. To such people, the iterative approach (typically using loops) feels more natural.
2. Those of us who cut our programming teeth on procedural or object-oriented programming have often been told to avoid recursion because it's error prone.
3. We're often told that recursion is slow. Calling and returning from a routine repeatedly involves a lot of stack pushing and popping, which is slower than looping. I think some languages handle this better than others, and those languages are most likely not those where the dominant paradigm is procedural or object-oriented.
4. For at least a couple of programming languages I've used, I remember hearing recommendations not to use recursion if it gets beyond a certain depth because its stack isn't that deep. |
I use recursion. What does that have to do with having a CS degree... (which I don't, by the way)
Common uses I have found:
1. **sitemaps** - recurse through filesystem starting at document root
1. **spiders** - crawling through a website to find email address, links, etc.
1. ? |
I'm not sure it's the same issue, but I had a similar sounding issue with trying to bind a DropDownList that I wanted to contain in a GridView. When I looked around I found a lot of people asking similar questions, but no robust solutions. I did read conflicting reports about whether you could intercept databinding, etc events. I tried most of them but I couldn'f find a way of intercepting or pre-empting the error.
I ended up creating a subclass of the ddl, intercepting the error from there hacking a fix.
Not tidy but it worked for my needs. I put the code up on my blog in case it's of help. [link text][1]
[1]: http://david.safitech.com/?p=53 |
It turns out you have to set `top` to `.F.` for `float` to take effect, this worked:
USE report.frx
REPLACE float with .T., stretch with .T., top with .F. for objtype = 8
|
Most web sites I've seen don't solve this problem - they show you a page including some content you've already seen.
You might consider that a feature - when you click "next" and see some content you're seen before, it's a signal that you want to go back to the front again because there's some new content. |
Tag each question with its time entered into the database, carry the time the frontpage was last loaded as a cookie or part of the URL, and limit the search to items `n` through `n+displaynum` as you go forward.
But I wouldn't bother. This behavior is uniform enough that most users expect it, and it serves as a flag for when new data is becoming available. You can even open a new tab/window that starts back at the top of the list to see what has come up. |
Is the control that you are trying to reference inside of the repeater?
If so then you need to look them up using the FindControl method.
For example for:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server">stest</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
You would need to do this to reference it:
LinkButton lb = Repeater1.FindControl("LinkButton1");
|
The more code you can cover with compile time checking for me is something that I'd place a higher premium on than performance. Having said that at this stage I'd probably lean towards ESQL not just because of the performance, but it's also (at present) a lot more flexible in what it can do. There's nothing worse than using a technology stack that doesn't have a feature you really really need.
The entity framework doesn't support things like custom properties, custom queries (for when you need to really tune performance) and does not function the same as linq-to-sql (i.e. there are features that simply don't work in the entity framework).
My personal impression of the Entity Framework is that there is a lot of potential, but it's probably a bit to "rigid" in it's implementation to use in a production environment in its current state. |
Visual Studio 2008 Fubared |
|asp.net|visual-studio|c#|microsoft| |
Ok, so, my visual studio is broken. I say this NOT prematurely, as it was my first response to see where I had messed up in my code. When I add controls to the page I can't reference all of them in the code behind. Some of them I can, it seems that the first few I put on a page work, then it just stops.
I first thought it may be the type of control as initially I was trying to reference a repeater inside an update panel. I know I am correctly referencing the code behind in my aspx page. But just in case it was a screw up on my part I started to recreate the page from scratch and this time got a few more controls down before VS stopped recognizing my controls.
After creating my page twice and getting stuck I thought maybe it was still the type of controls. I created a new page and just threw some labels on it. No dice, build fails when referencing the control from the code behind.
In a possibly unrelated note when I switch to the dreaded "design" mode of the aspx pages VS 2008 errors out and restarts.
I have already put a trouble ticket in to Microsoft. I uninstalled all add-ins, I reinstalled visual studio.
Anyone that wants to see my code just ask, but I am using the straight WYSIWYG visual studio "new aspx page" nothing fancy.
I doubt anyone has run into this, but have you?
Has anyone had success trouble shooting these things with Microsoft? Any way to expedite this ticket without paying??? I have been talking to a rep from Microsoft for days with no luck yet and I am dead in the water.
Thank you. |
Module level suppression messages need to be pasted into the same file as the code that is raising the FxCop error, before the namespace declaration. Additionally, you will need to have CODE_ANALYSIS defined as a conditional compiler symbols (Project > Properties > Build). Once that is in place, do a complete rebuild of project and the next time you run FxCop the error should be moved to the "Excluded in Source" tab.
Also, one small tip, but if you are dealing with a lot of FxCop exclusions it might be useful to wrap a region around them so you can get them out of the way. |
Module level suppression messages need to be pasted into the same file as the code that is raising the FxCop error before the namespace declaration or in assemblyinfo.cs. Additionally, you will need to have CODE_ANALYSIS defined as a conditional compiler symbols (Project > Properties > Build). Once that is in place, do a complete rebuild of project and the next time you run FxCop the error should be moved to the "Excluded in Source" tab.
Also, one small tip, but if you are dealing with a lot of FxCop exclusions it might be useful to wrap a region around them so you can get them out of the way. |
I don't know enough about the guts of the file systems to answer the first, except when I read the first descriptions of NTFS it sounded an awful lot like the Berkley Fast Filesystem.
As for the second, there are plenty of greps for Windows. When I had to use Windows in the past, I always installed Cygwin first thing.
|
I think you are a little bit confused. There is no 'Unix' and 'Windows' file systems. The *nix family of filesystems include ext3, ZFS, UFS etc. Windows primarily has had support for FAT16/32 and their own filesystem NTFS. However today linux systems can read and write to NTFS. More filesystems [here][1]
I can't tell you why one could be better than the other though.
[1]: http://en.wikipedia.org/wiki/List_of_file_systems |
Makepp source with two targets |
|lazy-c++|build-process| |
I use this tool called [Lazy C++][1] which breaks a single C++ <tt>.lzz</tt> file into a <tt>.h</tt> and <tt>.cpp</tt> file. I want [Makepp][2] to expect both of these files to exist after my rule for building <tt>.lzz</tt> files, but I'm not sure how to put two targets into a single build line.
[1]: http://www.lazycplusplus.com/
[2]: http://makepp.sourceforge.net/ |
Make source with two targets |
|build-process|makefile|lazy-c++| |
well the *nix filesystems do a far better job of actual file managment than fat16/32 or NTFS. The *nix systems try to prevent the need for a defrag over windows doing...nothing? Other than that I don't really know what would make one better than the other. |
If you don't want to write java code in-house, take a look at the commercial product <a href="http://scand.com/products/vault/">Vault Applet</a>. You can try out the eval to see if it fulfils your needs. |
Select your team project from team explorer, then right click on the Builds folder. Select a new build definition and then select the trigger tab. Move the radio button to "Build each check-in (more builds)"
More info can be found here
[MSDN How to: Create a Build Definition][1]
[1]: http://msdn.microsoft.com/en-us/library/ms181716.aspx |
There is a Linq provider for PostgreSQL at [http://code2code.net/DB_Linq/][1].
[1]: http://code2code.net/DB_Linq/ |
depending on what (if any) framework you're using, I suggest you do a query to check for the jobname yourself and create the proper information to user in with the rest of the validations for the form.
Depending on the number of jobnames, you could send the names to the view that contains the form and use javascript to tell use which is taken.
If this doesnt make sense to you, then to sum my view it's this: dont design your program and / or user to try to do illegal things and catch the errors when they do and handle it then. It is much better, imho, to design your system to not create errors. Keep the errors to actual bugs :) |
Another good one is [CEEBot][1]. It teaches C / Java style programming in a fun, robot-programming kind of game. It is aimed at 10-15 year olds, but it is a good one.
[1]: http://www.ceebot.com/ceebot/index-e.php |
First you should [turn warnings off][1] so that your visitors don't see your MySQL errors. Second, when you call [mysql_query()][2], you should check to see if it returned false. If it did, call [mysql_errno()][3] to find out what went wrong. Match the number returned to the error codes on [this page][4].
[1]: http://us.php.net/error_reporting
[2]: http://us.php.net/mysql_query
[3]: http://us.php.net/manual/en/function.mysql-errno.php
[4]: http://dev.mysql.com/doc/refman/4.1/en/error-messages-server.html |
First you should [turn warnings off][1] so that your visitors don't see your MySQL errors. Second, when you call [mysql_query()][2], you should check to see if it returned false. If it did, call [mysql_errno()][3] to find out what went wrong. Match the number returned to the error codes on [this page][4].
It looks like this is the error number you're looking for:
> Error: 1169 SQLSTATE: 23000 (ER_DUP_UNIQUE)
> Message: Can't write, because of unique constraint, to table '%s'
[1]: http://us.php.net/error_reporting
[2]: http://us.php.net/mysql_query
[3]: http://us.php.net/manual/en/function.mysql-errno.php
[4]: http://dev.mysql.com/doc/refman/4.1/en/error-messages-server.html |
How to set the order in subnodes of a tree structure. |
|treeview|tree| |
I have a tree representation of pages in a CMS application. However, I don't have a good way to:
A) Reorder subpages under a prticular parent page.
B) Provide a UI implementation that allows the user to change the order.
Any suggestions? |
|tree|treeview| |
I have a tree representation of pages in a CMS application. However, I don't have a good way to:
A) Reorder subpages under a prticular parent page.
B) Provide a UI implementation that allows the user to change the order.
Any suggestions? |
How do I configure and communicate with a serial port? |
|java|c++|windows|unix| |
I need to send and receive data over serial connections (RS-232 and RS-422).
How do I set up and communicate with such a connection? How do I figure out what the configuration settings (e.g. baud rate) should be and how do I set them?
In particular I am looking to do this in Java, C/C++, or one of the major Unix shells but I also have some interest in serial programming using Windows/Hyperterminal. |
I think you might be alluding to an "invisible" captcha. Check out the Subkismet project for an invisible captcha implementation.
<http://www.codeplex.com/subkismet> |
Mario, I don't understand why you used recursion for that example.. Why not simply loop through each entry? Something like this:
String ArrangeString(TStringList* items, String separator)
{
String result = items->Strings[0];
for ( int position=1; position < items->count; position++ ) {
result += separator + items->Strings[position];
}
return result;
}
The above method would be faster, and is simpler. There's no need to use recursion in place of a simple loop. |
Mario, I don't understand why you used recursion for that example.. Why not simply loop through each entry? Something like this:
String ArrangeString(TStringList* items, String separator)
{
String result = items->Strings[0];
for ( int position=1; position < items->count; position++ ) {
result += separator + items->Strings[position];
}
return result;
}
The above method would be faster, and is simpler. There's no need to use recursion in place of a simple loop. I think these sorts of examples is why recursion gets a bad rap. Even the canonical factorial function example is better implemented with a loop. |
So you mean that AD743 on spreadsheet B must be equal to AD743 on spreadsheet A? Try this:
- Open both spreadsheets on the same
machine.
- Go to AD743 on spreadsheet B.
- Type =.
- Go to spreadsheed A and click on
AD743.
- Press enter.
You'll notice that the formula is something like '*[path-to-file+file-name].worksheet-name!AD743*'.
The value on spreadsheet B will be updated when you open it. In fact, it will ask you if you want to update. Of course, your connection must be up and running for it to update. Also, you can't change the name or the path of spreadsheet A. |
Build a time machine and go back to 1987? Ho ho.
Ok, no more snarky comments.
> How do I figure out what the configuration settings (e.g. baud rate) should be...
Read the datasheet? Ok, ok. Seriously, last one. If you don't know the baud rate of the device you are trying to communicate with, you have two choices. Start guessing, or possibly bust out an o-scope. My suspicion is you can get there with brute force relatively quickly. There's a third option of having an old-school ninja who can tell just by the LOOK of the garbled characters at some standard baud rate what actual baud rate is. An impressive party trick to be sure.
Hopefully though you have access to this information. In unix, you can get ahold of minicom to play with the serial port directly.
> one of the major Unix shells
In Unix the serial port is file-mapped into the /dev/ subdir. ttyS0, for example. If you setup the correct baud rate and whatnot using minicom, you can even cat stuff to that file to send stuff out there.
On to the meat of the question, you can access it programmatically through the POSIX headers. termios.h is the big one.
See: <http://www.easysw.com/~mike/serial/serial.html#3_1> |
Manual steps to upgrade VS.NET solution and target .NET framework? |
|.net|visual-studio| |
After you've let the VS.NET (2008 in this case) wizard upgrade your solution, do you perform any manual steps to upgrade specific properties of your solution and projects? For instance, you have to go to each project and target a new version of the framework (from 2.0 to 3.5 in this case). Even after targeting a new version of the framework, I find assembly references still point to the assemblies from the old version (2.0 rather than 3.5 even after changing the target). Does this mean I lose out on the performance benefits of assemblies in the new version of the framework? |
Save yourself some headaches and use a parser instead. CPAN has several modules that are suitable. Here's an example using the <a href="http://search.cpan.org/dist/HTML-Parser/lib/HTML/TokeParser.pm">HTML::TokeParser</a> module that comes with the extremely capable <a href="http://search.cpan.org/dist/HTML-Parser">HTML::Parser</a> CPAN distribution:
use strict;
use HTML::TokeParser;
my $parser = HTML::TokeParser->new('/some/file.html')
or die "Could not open /some/file.html - $!";
while(my $t = $parser->get_token)
{
# Skip start or end tags that are not "p" tags
next if(($t->[0] eq 'S' || $t->[0] eq 'E') && lc $t->[1] ne 'p');
# Print everything else normally (see HTML::TokeParser docs for explanation)
if($t->[0] eq 'T')
{
print $t->[1];
}
else
{
print $t->[-1];
}
}
<a href="http://search.cpan.org/dist/HTML-Parser">HTML::Parser</a> accepts input in the form of a file name, an open file handle, or a string. Wrapping the above code in a library and making the destination configurable (i.e., not just <code>print</code>ing as in the above) is not hard. The result will be much more reliable, maintainable, and possibly also faster (HTML::Parser uses a C-based backend) than trying to use regular expressions. |
If you _insist_ on using a regex, something like this will work in most cases:
# Remove all HTML except "p" tags
$html =~ s{<(?>/?)(?:[^pP]|[pP][^\s>/])[^>]*>}{}g;
Explanation:
s{
< # opening angled bracket
(?>/?) # ratchet past optional /
(?:
[^pP] # non-p tag
| # ...or...
[pP][^\s>/] # longer tag that begins with p (e.g., <pre>)
)
[^>]* # everything until closing angled bracket
> # closing bracket
}{}gx; # replace with nothing, globally
But really, save yourself some headaches and use a parser instead. CPAN has several modules that are suitable. Here's an example using the <a href="http://search.cpan.org/dist/HTML-Parser/lib/HTML/TokeParser.pm">HTML::TokeParser</a> module that comes with the extremely capable <a href="http://search.cpan.org/dist/HTML-Parser">HTML::Parser</a> CPAN distribution:
use strict;
use HTML::TokeParser;
my $parser = HTML::TokeParser->new('/some/file.html')
or die "Could not open /some/file.html - $!";
while(my $t = $parser->get_token)
{
# Skip start or end tags that are not "p" tags
next if(($t->[0] eq 'S' || $t->[0] eq 'E') && lc $t->[1] ne 'p');
# Print everything else normally (see HTML::TokeParser docs for explanation)
if($t->[0] eq 'T')
{
print $t->[1];
}
else
{
print $t->[-1];
}
}
<a href="http://search.cpan.org/dist/HTML-Parser">HTML::Parser</a> accepts input in the form of a file name, an open file handle, or a string. Wrapping the above code in a library and making the destination configurable (i.e., not just <code>print</code>ing as in the above) is not hard. The result will be much more reliable, maintainable, and possibly also faster (HTML::Parser uses a C-based backend) than trying to use regular expressions. |
|asp.net|visual-studio|c#| |
Ok, so, my visual studio is broken. I say this NOT prematurely, as it was my first response to see where I had messed up in my code. When I add controls to the page I can't reference all of them in the code behind. Some of them I can, it seems that the first few I put on a page work, then it just stops.
I first thought it may be the type of control as initially I was trying to reference a repeater inside an update panel. I know I am correctly referencing the code behind in my aspx page. But just in case it was a screw up on my part I started to recreate the page from scratch and this time got a few more controls down before VS stopped recognizing my controls.
After creating my page twice and getting stuck I thought maybe it was still the type of controls. I created a new page and just threw some labels on it. No dice, build fails when referencing the control from the code behind.
In a possibly unrelated note when I switch to the dreaded "design" mode of the aspx pages VS 2008 errors out and restarts.
I have already put a trouble ticket in to Microsoft. I uninstalled all add-ins, I reinstalled visual studio.
Anyone that wants to see my code just ask, but I am using the straight WYSIWYG visual studio "new aspx page" nothing fancy.
I doubt anyone has run into this, but have you?
Has anyone had success trouble shooting these things with Microsoft? Any way to expedite this ticket without paying??? I have been talking to a rep from Microsoft for days with no luck yet and I am dead in the water.
Thank you. |
Visual Studio 2008 Foo-barred |
ASP.NET controls cannot be referenced in code-behind in Visual Studio 2008 |
|c#|asp.net|visual-studio| |
Ok, so, my visual studio is broken. I say this NOT prematurely, as it was my first response to see where I had messed up in my code. When I add controls to the page I can't reference all of them in the code behind. Some of them I can, it seems that the first few I put on a page work, then it just stops.
I first thought it may be the type of control as initially I was trying to reference a repeater inside an update panel. I know I am correctly referencing the code behind in my aspx page. But just in case it was a screw up on my part I started to recreate the page from scratch and this time got a few more controls down before VS stopped recognizing my controls.
After creating my page twice and getting stuck I thought maybe it was still the type of controls. I created a new page and just threw some labels on it. No dice, build fails when referencing the control from the code behind.
In a possibly unrelated note when I switch to the dreaded "design" mode of the aspx pages VS 2008 errors out and restarts.
I have already put a trouble ticket in to Microsoft. I uninstalled all add-ins, I reinstalled visual studio.
Anyone that wants to see my code just ask, but I am using the straight WYSIWYG visual studio "new aspx page" nothing fancy.
I doubt anyone has run into this, but have you?
Has anyone had success trouble shooting these things with Microsoft? Any way to expedite this ticket without paying??? I have been talking to a rep from Microsoft for days with no luck yet and I am dead in the water.
Thank you.
---
**Jon Limjap:** I edited the title to both make it clear and descriptive *and* make sure that nobody sees it as offensive. "Foo-barred" doesn't exactly constitute a proper question title, although your question is clearly a valid one. |
If you don't want to write java code in-house, there are commercial applet solutions available:
* <a href="http://scand.com/products/vault/">Vault</a>
* <a href="http://www.javaatwork.com/java-download-applet/details.html">MyDownloder</a>
Both of them have eval versions that you can download and test. |
I use: [Jquery-roundcorners-canvas][1]
it handles borders, and keeps things the same size, in fact you have to pad in a bit to keep from having letters live in the crease. Its pretty fast, unless you are on ie 6.
Same pretty syntax of the other corner packs, but just prettier in general.
[1]: http://jrc.meerbox.nl/?page_id=4 |
This question is far too vague to be useful to you or anyone else. Also, Wikipedia is your primary source of info on SQL Server, fail?
The first matrix of the MSDN page for [Features Supported by the Editions of SQL Server 2008][1] is titled "Scalability." The only edition with any features marked "Yes" is Enterprise (you get Partitioning, Data compression, Resource governor, and Partition table parallelism.) And it goes down the line from there, Express does not support many of the features designed for "scale." If your main demand is space, how soon will you exceed 4GB? If your main demand is high availability and integrity, don't even bother with Express.
"Scalable" is quickly becoming a weasel-/buzz-word, alongside "robust." People use it when they haven't thought hard enough about what they mean.
[1]: http://msdn.microsoft.com/en-us/library/cc645993.aspx |
One of the fundamental differences in filesystem semantics between Unix and Windows is the idea of inodes.
On Windows, a file name is directly attached to the file data. This means that the OS prevents somebody from deleting a file that is currently open. On some versions of Windows you can rename a file that is currently open, and on some versions you can't.
On Unix, a file name is a pointer to an inode, which is the place the file data is actually stored. This has a couple of implications:
- You can have two different filenames that refer to the same underlying file. This is often called a *hard link*. There is only one copy of the file data, so changes made through one filename will appear in the other.
- You can delete (also known as `unlink`) a file that is currently open. All that happens is the directory entry is removed, but this doesn't affect any other process that might still have the file open. The process with the file open hangs on to the inode, rather than to the directory entry. When the process closes the file, the OS deletes the inode because there are no more directory entries pointing at it and no more processes with the inode open.
This difference is important, but it is unrelated to things like the performance of `grep`. |
+1 on the execution plan. From here you can see where all the time is being spent in your particular query. Eg. 85% of the time is spent table scanning a particular table, can you put an index on that table to improve it? etc etc. |
There are differences in how Windows and Unix operating systems expose the disk drives to users and how drive space is partitioned.
The biggest difference between the two operating systems is that Unix essentially treats all of the physical drives as one logical drive. (This isn't exactly how it works, but should give a good enough picture.) This allows a much simpler file system from the users perspective as there are no drive letters to deal with. I have a folder called /usr/bin that could span multiple physical drives. If I need to expand that partition I can do so by adding a new drive, remapping the folder, and moving the files. (Again, somewhat simplified, but it gets the point across.)
The other difference is that when you format a drive, a certain amount is set aside (by default, as an admin you can change the size to 0 if you want) for use by the "root" account (admin account) which allows an admin to almost always be able to log in to the machine even when the user has filled the disk and is receiving "out of disk space" messages. |
|treeview|tree| |
I have a tree representation of pages in a CMS application. I understand how to persist the tree in the database. However, I don't have a good way to:
A) Reorder subpages under a particular parent page.
B) Provide a UI implementation that allows the user to change the order.
Any suggestions? |
[Pro Spring][1] is a superb introduction to the world of Inversion of Control and Dependency Injection. If you're not aware of these practices and their implications - the balance of topics and technical detail in Pro Spring is excellent. It builds a great case and consequent personal foundation.
Another book I'd suggest would be Robert Martin's [Agile Software Development][2] (ASD). Code smells, agile techniques, test driven dev, principles ... a well-written balance of many different programming facets.
More traditional classics would include the infamous GoF [Design Patterns][3], Bertrand Meyer's [Object Oriented Software Construction][4], Booch's [Object Oriented Analysis and Design][5], [Scott Meyer][6]'s "[Effective C++][7]'" series and a lesser known book I enjoyed by Gunderloy, [Coder to Developer][8].
And while books are nice ... don't forget [radio][9]!
[1]: http://www.apress.com/book/view/1590599217
[2]: http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445/sr=1-1/qid=1161361645/ref=sr_1_1/102-5628847-5032158?ie=UTF8&s=books
[3]: http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1220716853&sr=8-1
[4]: http://www.amazon.com/Object-Oriented-Software-Construction-Prentice-Hall-International/dp/0136291554/ref=sr_1_1?ie=UTF8&s=books&qid=1220716881&sr=1-1
[5]: http://www.amazon.com/Object-Oriented-Analysis-Applications-Addison-Wesley-Technology/dp/020189551X/ref=sr_1_1?ie=UTF8&s=books&qid=1220716915&sr=1-1
[6]: http://www.amazon.com/s/ref=nb_ss_b?url=search-alias%3Dstripbooks&field-keywords=scott+meyers&x=0&y=0
[7]: http://www.amazon.com/Effective-Specific-Addison-Wesley-Professional-Computing/dp/0321334876/ref=sr_1_1?ie=UTF8&s=books&qid=1220716951&sr=1-1
[8]: http://www.codertodeveloper.com/
[9]: http://www.se-radio.net/ |
[Pro Spring][1] is a superb introduction to the world of Inversion of Control and Dependency Injection. If you're not aware of these practices and their implications - the balance of topics and technical detail in Pro Spring is excellent. It builds a great case and consequent personal foundation.
Another book I'd suggest would be Robert Martin's [Agile Software Development][2] (ASD). Code smells, agile techniques, test driven dev, principles ... a well-written balance of many different programming facets.
More traditional classics would include the infamous GoF [Design Patterns][3], Bertrand Meyer's [Object Oriented Software Construction][4], Booch's [Object Oriented Analysis and Design][5], [Scott Meyer][6]'s "[Effective C++][7]'" series and a lesser known book I enjoyed by Gunderloy, [Coder to Developer][8].
And while books are nice ... don't forget [radio][9]!
... let me add one more thing. If you haven't already discovered [safari][10] - take a look. It is more addictive than stack overflow :-) I've found that with my google type habits - I need the more expensive subscription so I can look at any book at any time - but I'd recommend the trial to anyone even remotely interested.
(ah yes, a little obj-C today, cocoa tomorrow, patterns? soa? what was that example in that cookbook? What did Steve say in the [second edition][11]? Should I buy this book? ... a subscription like this is great if you'd like some continuity and context to what you're googling ...)
[1]: http://www.apress.com/book/view/1590599217
[2]: http://www.amazon.com/Software-Development-Principles-Patterns-Practices/dp/0135974445/sr=1-1/qid=1161361645/ref=sr_1_1/102-5628847-5032158?ie=UTF8&s=books
[3]: http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1220716853&sr=8-1
[4]: http://www.amazon.com/Object-Oriented-Software-Construction-Prentice-Hall-International/dp/0136291554/ref=sr_1_1?ie=UTF8&s=books&qid=1220716881&sr=1-1
[5]: http://www.amazon.com/Object-Oriented-Analysis-Applications-Addison-Wesley-Technology/dp/020189551X/ref=sr_1_1?ie=UTF8&s=books&qid=1220716915&sr=1-1
[6]: http://www.amazon.com/s/ref=nb_ss_b?url=search-alias%3Dstripbooks&field-keywords=scott+meyers&x=0&y=0
[7]: http://www.amazon.com/Effective-Specific-Addison-Wesley-Professional-Computing/dp/0321334876/ref=sr_1_1?ie=UTF8&s=books&qid=1220716951&sr=1-1
[8]: http://www.codertodeveloper.com/
[9]: http://www.se-radio.net/
[10]: http://safari.oreilly.com/0735619670
[11]: http://safari.oreilly.com/0735619670 |
If you _insist_ on using a regex, something like this will work in most cases:
# Remove all HTML except "p" tags
$html =~ s{<(?>/?)(?:[^pP]|[pP][^\s>/])[^>]*>}{}g;
Explanation:
s{
< # opening angled bracket
(?>/?) # ratchet past optional /
(?:
[^pP] # non-p tag
| # ...or...
[pP][^\s>/] # longer tag that begins with p (e.g., <pre>)
)
[^>]* # everything until closing angled bracket
> # closing angled bracket
}{}gx; # replace with nothing, globally
But really, save yourself some headaches and use a parser instead. CPAN has several modules that are suitable. Here's an example using the <a href="http://search.cpan.org/dist/HTML-Parser/lib/HTML/TokeParser.pm">HTML::TokeParser</a> module that comes with the extremely capable <a href="http://search.cpan.org/dist/HTML-Parser">HTML::Parser</a> CPAN distribution:
use strict;
use HTML::TokeParser;
my $parser = HTML::TokeParser->new('/some/file.html')
or die "Could not open /some/file.html - $!";
while(my $t = $parser->get_token)
{
# Skip start or end tags that are not "p" tags
next if(($t->[0] eq 'S' || $t->[0] eq 'E') && lc $t->[1] ne 'p');
# Print everything else normally (see HTML::TokeParser docs for explanation)
if($t->[0] eq 'T')
{
print $t->[1];
}
else
{
print $t->[-1];
}
}
<a href="http://search.cpan.org/dist/HTML-Parser">HTML::Parser</a> accepts input in the form of a file name, an open file handle, or a string. Wrapping the above code in a library and making the destination configurable (i.e., not just <code>print</code>ing as in the above) is not hard. The result will be much more reliable, maintainable, and possibly also faster (HTML::Parser uses a C-based backend) than trying to use regular expressions. |
Also take a look at [Microsoft StyleCop][1]
[1]: http://blogs.msdn.com/sourceanalysis/ |
How does WinXP's "Send to Compressed (zipped) Folder" decide what to include in zip file? |
|zip|windows-xp| |
I'm not going to be too surprised if I get shot-down for asking a "non programming" question, but maybe somebody knows ...
I was zipping the contents of my subversion sandbox using WinXP's inbuilt "Send to Compressed (zipped) Folder" capability and was surprised to find that the .zip file created did not contain the .svn directories and their contents.
I had always assumed that all files were included and I can't locate which property/option/attribute controls inclusion or otherwise. Can anybody help?
Thanks, Tom |
What you described is GORM. It is part of the [Grails][1] framework and is built to work with Hibernate (maybe JPA in the future). When I was first using Grails it seemed backwards. I was more comfortable with a Rails style workflow of making the tables and letting the framework generate scaffolding from the database schema. GORM persists your domain objects for you so you create and change the objects, it manages database create/update. This makes more sense now that I have gotten used to it. Sorry to tease you if you aren't looking for a new framework but it is on the [roadmap][2] for release 1.1 to make GORM available standalone.
[1]: http://grails.org/
[2]: http://grails.org/Roadmap |
IDisposable has nothing to do with freeing memory. IDisposable is a pattern for freeing *unmanaged* resources -- and memory is quite definitely a managed resource.
The links pointing to GC.Collect() are the correct answer, though use of this function is generally discouraged by the Microsoft .NET documentation. |
IDisposable has nothing to do with freeing memory. IDisposable is a pattern for freeing *unmanaged* resources -- and memory is quite definitely a managed resource.
The links pointing to GC.Collect() are the correct answer, though use of this function is generally discouraged by the Microsoft .NET documentation.
**Edit:** Having earned a substantial amount of karma for this answer, I feel a certain responsibility to elaborate on it, lest a newcomer to .NET resource management get the wrong impression.
Inside a .NET process, there are two kinds of resource -- managed and unmanaged. "Managed" means that the runtime is in control of the resource, while "unmanaged" means that it's the programmer's responsibility. And there really is only one kind of managed resource that we care about in .NET today -- memory. The programmer tells the runtime to allocate memory and after that it's up to the runtime to figure out when the memory can freed. The mechanism that .NET uses for this purpose is called [garbage collection][1] and you can find plenty of information about GC on the internet simply by using Google.
For the other kinds of resources, .NET doesn't know anything about cleaning them up so it has to rely on the programmer to do the right thing. To this end, the platform gives the programmer three tools:
1. The IDisposable interface and the "using" statement in VB and C#
2. Finalizers
3. The IDisposable pattern as implemented by many BCL classes
The first of these allows the programmer to efficiently acquire a resource, use it and then release it all within the same method.
using (DisposableObject tmp = DisposableObject.AcquireResource()) {
// Do something with tmp
}
// At this point, tmp.Dispose() will automatically have been called
// BUT, tmp may still a perfectly valid object that still takes up memory
If "AcquireResource" is a factory method that (for instance) opens a file and "Dispose" automatically closes the file, then this code cannot leak a file resource. But the memory for the "tmp" object itself may well still be allocated. That's because the IDisposable interface has absolutely no connection to the garbage collector. If you *did* want to ensure that the memory was freed, your only option would be to call `GC.Collect()` to force a garbage collection.
However, it cannot be stressed enough that this is probably not a good idea. It's generally much better to let the garbage collector do what it was designed to do, which is to manage memory.
What happens if the resource is being used for a longer period of time, such that its lifespan crosses several methods? Clearly, the "using" statement is no longer applicable, so the programmer would have to manually call "Dispose" when he or she is done with the resource. And what happens if the programmer forgets? If there's no fallback, then the process or computer may eventually run out of whichever resource isn't being properly freed.
That's where finalizers come in. A finalizer is a method on your class that has a special relationship with the garbage collector. The GC promises that -- before freeing the memory for any object of that type -- it will first give the finalizer a chance to do some kind of cleanup.
So in the case of a file, we theoretically don't need to close the file manually at all. We can just wait until the garbage collector gets to it and then let the finalizer do the work. Unfortunately, this doesn't work well in practice because the garbage collector runs non-deterministically. The file may stay open considerably longer than the programmer expects. And if enough files are kept open, the system may fail when trying to open an additional file.
For most resources, we want both of these things. We want a convention to be able to say "we're done with this resource now" and we want to make sure that there's at least some chance for the cleanup to happen automatically if we forget to do it manually. That's where the "IDisposable" pattern comes into play. This is a convention that allows IDispose and a finalizer to play nicely together. You can see how the pattern works by looking at the [official documentation for IDisposable][2].
**Bottom line:** If what you really want to do is to just make sure that memory is freed, then IDisposable and finalizers will not help you. But the IDisposable interface is part of an extremely important pattern that all .NET programmers should understand.
[1]: http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)
[2]: http://msdn.microsoft.com/en-us/library/system.idisposable.aspx |
In these days of **SQL Server Express**, I'd say there's really no reason for you not to use a database.
I know this doesn't really answer your question, but I'd hate to see you roll out code that will be a nightmare to maintain and scale.
Maybe you could tell us why you want to use xml files instead of a proper database. |
Well, sysrqb will let you match anything in the first paragraph assuming there's no other html in the paragraph. You might want something more like this
<p>.*?</p>
Placing the ? after your * makes it non-greedy, meaning it will only match as little text as necessary before matching the </p> |
C++ Memory management |
|c++|memory|management|pointers| |
I've learned in College that you always have to free your unused Objects but not how you actually do it. For example structuring your code right and so on.
Are there any general rules on how to handle pointers in C++?
|
|c++|memory-management|pointers| |
I've learned in College that you always have to free your unused Objects but not how you actually do it. For example structuring your code right and so on.
Are there any general rules on how to handle pointers in C++?
I'm currently not allowed to use boost. I have to stick to pure c++ because the framework I'm using forbids any use of generics.
|
|c++|pointers|memory-management| |
|c++|memory|pointers| |
How Does A Stack Overflow Occur and How Do You Prevent It? |
|hacking|stack-overflow| |
I was just wondering how a stack overflow occurs and the best ways to make sure it doesn't happen, or ways to prevent one - particularly on web servers, but other examples would be interesting, as well. |
|stack-overflow|memory-management| |
|stack-overflow|memory| |
C Memory Management |
|memory|c| |
I've always heard that in C you have to really watch how you manage memory. And I'm still beginning to learn C, but thus far, I have not had to do any memory managing related activities at all.. I always imagined having to release variables and do all sorts of ugly things. But this doesn't seem to be the case.
Can someone show me (with code examples) an example of when you would have to do some "memory management" ? |
The **+ operator** can work between a string and a string, char, integer, double or float data type value. It just converts the value to its string representation before concatenation.
The **concat operator** can only be done on and with strings. It checks for data type compatibility and throws an error if they don't match.
Except this, the code you provided do the same stuff. |