instruction
stringlengths 0
30k
⌀ |
---|
|c#|bestpractices|null|dbnull| |
We have our own ORM we use here, and provide strongly typed wrappers for all of our db tables. We also allow weakly typed ad-hoc SQL to be executed, but these queries still go through the same class for getting values out of a data reader.
In tweaking that class to work with Oracle, we've come across an interesting question. Is it better to use DBNull.Value, or null? Are there any benefits to using DBNull.Value? It seems more "correct" to use null, since we've separated ourselves from the DB world, but there are implications (you can't just blindly ToString() when a value is null for example) so its definitely something we need to make a conscious decision about. |
|c#|bestpractices|orm|null|dbnull| |
|c#|orm|null|dbnull| |
What are the best practices for using Extension Methods in .Net? |
|c#|vb.net|.net| |
I have seen these being used every which way, and have been accused of using them the wrong way (though in that case, I was using them that way to demonstrate a [point](http://blog.gadodia.net/extension-methods-in-vbnet-and-c/)).
So, what do you think are the best practices for employing Extension Methods?
Should development teams create a library of extension methods and deploy them across various projects?
Should there be a collection of common extension methods in the form of an open source project? |
|c#|vb.net|.net|bestpractices| |
Basically, if your site still works with JavaScript turned off, then anything you add with JavaScript can be considered progressive enhancement.
Some people may think that this is unnecessary, but plenty of people browse with addons like NoScript (or, with JavaScript simply turned off in their browser settings). In addition, many Mobile web browsers may or may not support JavaScript. So, it's always a good idea to test your site completely with and without JavaScript. |
You can use <a href="http://www.firephp.org/">Firephp</a> an add-on to firbug to debug php in the same environment as javascript.
I also use <a href="http://xdebug.org/">Xdebug</a> mentioned earlier for profiling php. |
Not an answer, but a warning: my company bought the 2007 Infragistics ASP.NET controls just for the Grid, and we regret that choice.
The quality of API is horrible (in our opinion at least), making it very hard to program against the grid (for example, inconsistent naming conventions, but this is just an inconvenience, we have complaints about the object model as well).
So I can't say that I know of a better option, I just know I will give a try to something else before paying for Infragistics products again (and the email support we got was horrible as well). |
Code Complete is the number one choice, but I'd also cite Gang of Four's Design Patterns and Craig Larman's Applying UML and Patterns.
The Timeless Way of Building, by Christopher Alexander, is another great one. Even though it's about archtecture, it's included in the bibliography of many great programming books I have already read.
Another one, from which I'm learning lots of new things, is Data Access Patterns, by Clifton Nock. |
***esellerate***
if it is Digital stuff that you are selling, I recommend http://www.esellerate.net/ .
they have nice support for website payment, delivery of serial numbers upon sell and even have API so you can integrate the buying process into your application in case it is a desktop application. |
Oracle has got an [online tutorial about SQL Injection][1]. Even though you want a ready-made solution, this might give you some hints on how to use it better to defend yourself.
[1]: http://st-curriculum.oracle.com/tutorial/SQLInjection/index.htm |
Well by cheap do you mean processing fees or month fees? Also is this for micro or normal transactions? PayPal in my experience is an all around good choice because it offers both starter to professional level payment processing services that fit most needs. |
Here is a good way to remember the process that each of them follow that I use when trying to decide which is better for my circumstance.
DateTime i = (DateTime)value;
// is like doing
DateTime i = value is DateTime ? value as DateTime : throw new Exception(...);
and the next should be easy to guess what it does
DateTime i = value as DateTime;
in the first case if the value cannot be cast than an exception is thrown in the second case if the value cannot be cast, i is set to null.
So in the first case a hard stop is made if the cast fails in the second cast a soft stop is made and you might encounter a NullReferenceException later on. |
Since you can't modify IIS settings to map .mvc to ASP.Net, you can use a different extension that's already mapped to ASP.Net. For example, you could use {controller}.ashx/{action} and it should work out of the box on IIS 6. |
In a client-server setting, if you care about security, you should always program on the assumption that the client may have been compromised. Even if it hasn't, there is always the risk of somebody using an old version of the client, using a competing or modified version of the client, or just of the net connection being a bit screwy.
So while you do as much work on the client as possible, processing and marshalling information into the right form, the server then needs to do a thorough sanity check on anything the client gives it.
So the answer I guess is "both". |
It rather depends how many times you want to do it, and what resources are available - if you're doing the test once, then the O(log N) techniques are good. If you're doing it a thousand times on a server, constructing a bitmap lookup table would be faster, either giving the result directly or as a first stage of. 2GB of bitmap can map the whole world lat-lon to a 32bit value at 0.011 degree pixels (1.2km at equator), and should fit into memory. If you're only doing single country, or can exclude the poles, you can have a smaller map or higher resolution. For 15,000 points you probably have a much smaller map - I first sized it up as a first step to doing lat-lon to postcode searches, which needs higher resolution. Depending on requirements, you use the mapped value to point at the result directly, or to short list of the candidates (which would allow a smaller map, but requires greater subsequent processing - you're not in O(1) lookup territory any more). |
You could check out the new [UI Automation][1] stuff in .NET 3.5. It is supposed to mask a whole lot of the PInovke stuff and works with web and WPF applications.
I haven't used it yet, so I don't have a more specific place to direct you, but it might fit the bill.
[1]: http://msdn.microsoft.com/en-us/library/ms747327.aspx |
Are you using Apache? If so you could have a look at [mod_log_spread][1] Though you may have too big an infrastructure to make it maintainable. The other option is to look at "broadcasting" or "multicasting" your log messages and having dedicated logging servers subscribing to those feeds and collating them
[1]: http://www.schlossnagle.org/~george/mod_log_spread/ |
Being an admin, I really appreciate apps that log to the Event Log (preferably their own, otherwise the application log) for all logging but trace logs. By logging to the event log, you make it much more likely that warnings or errors can be found and addressed by the admin staff before they become a major problem (if it is a issue they can address), or allows them to get in contact with the devs, who can use the trace logs to further troubleshoot the issue.
My biggest pain point in supporting a custom .NET app right now is that there are 8 different applications (some console apps, some winforms, and some web) from the same vendor. None of them log to the event log, they all have their own custom log files. But for all the winforms and console apps, they keep the file open while they are running, so I can't monitor it for issues. Also, the logs are all written slightly differently, so I would have to parse them a bit differently to get useful information.
This forces me to monitor the appearance of an application (is it responding on the ports it is active on, is the process working set getting too high, etc..), rather than what the state of the application really is.
Please, please consider the folks who maintain your application after it is deployed and provide logging they can use. Thanks! |
How do I track file downloads with apache/PHP |
|php|apache| |
I have a website that plays mp3's in a flash player. If a user clicks 'play' the flash player automatically downloads an mp3 and starts playing it.
Is there an easy way to track how many times a particular song clip (or any binary file) is downloaded? |
The _hook_ and _listener_ method is the most commonly used, but there are other things you can do. Depending on the size of your app, and who your going to allow see the code (is this going to be a FOSS script, or something in house) will influence greatly how you want to allow plugins.
kdeloach has a nice example, but his implementation and hook function is a little unsafe. I would ask for you to give more information of the nature of php app your writing, And how you see plugins fitting in.
+1 to kdeloach from me. |
Is the play link a link to the actual mp3 file or to some javascript code that pops up a player?
If the latter, you can easily add your own logging code in there to track the number of hits to it.
If the former, you'll need something that can track the web server log itself and make that distinction. My hosting plan comes with webalizer, which does this nicely. |
As of .Net 1.1 the only available method is reaching into the java libraries.<br>
<a href="http://msdn.microsoft.com/en-ca/magazine/cc164129.aspx">Using the Zip Classes in the J# Class Libraries to Compress Files and Data with C#</a><br>
Not sure if this has changed in recent versions. |
You could even set up an Apache .htaccess directive that converts *.mp3 requests into the querystring dubayou is working with. It might be an elegant way to keep the direct request and still be able to slipstream log function into the response. |
Well, what is the nature of the flat databases. Are they large or small. Is it simple arrays with arrays in them? if its something simple say userprofiles built as such:
$user = array("name" => "dubayou",
"age" => 20,
"websites" => array("dubayou.com","willwharton.com","codecream.com"),
"and_one" => "more");
and to save or update the _db record_ for that user.
$dir = "../userdata/"; //make sure to put it bellow what the server can reach.
file_put_contents($dir.$user['name'],serialize($user));
and to load the _record_ for the user
function &get_user($name){
return unserialize(file_get_contents("../userdata/".$name));
}
but again this implementation will very on the application and nature of the database you need. |
I used to have lots of Explorer crashes (on 32-bit) caused by Tortoise. They seem to have gone away since I used the Include/Exclude path settings in the "Icon Overlays" configuration of TSVN. Constraining icon overlays to specific directories where I keep my source made this much more stable. |
Use your httpd log files. Install http://awstats.sourceforge.net/ |
Strictly speaking, a memory leak is consuming memory that is "no longer used" by the program.
"No longer used" has more than one meaning, it could mean "no more reference to it", that is, totally unrecoverable, or it could mean, referenced, recoverable, unused but the program keeps the references anyway. Only the later applies to .Net for **perfectly managed objects**. However, not all classes are perfect and at some point an underlying unmanaged implementation could leak resources permanently for that process.
In all cases, the application consumes more memory than strictly needed. The sides effects, depending on the ammount leaked, could go from none, to slowdown caused by excessive collection, to a series of memory exceptions and finally a fatal error followed by forced process termination.
You know an application has a memory problem when monitoring shows that more and more memory is allocated to your process **after each garbage collection cycle**. In such case, you are either keeping too much in memory, or some underlying unmanaged implementation is leaking.
For most leaks, resources are recovered when the process is terminated, however some resources are not always recovered in some precise cases, GDI cursor handles are notorious for that. Of course, if you have an interprocess communication mechanism, memory allocated in the other process would not be freed until that process frees it or terminates. |
I store everything in the repository to make it easy for developers (or rebuilt devboxes) to check-out from SVN and then run a build (with all necessary assemblies in relative paths). If you have multiple projects that should be separate, this would also encourage the team of your shared components to deliver high quality assemblies. This could follow a normal release to production mentality where the shared assemblied would be updated in your downstream projects. This is a very natural [Software Value Chain,][1] at the cost of a little bit of disk space.
JP Boodhoo has [a great series][2] on the topic of automated builds, VS folder structure, and getting developers up and running quickly.
[1]: http://www.spaconference.org/cgi-bin/wiki.pl/ot2004/?KkbagegehhgidslcbhbffcaabcbzencoukKk
[2]: http://blog.jpboodhoo.com/AutomatingYourBuildsWithNAntPart1.aspx |
I think it is highly recommended that you create separate repositories for each project. If for nothing else than to avoid the scenario you are talking about.
With version control, especially Subversion, you can easily check out pieces of a repository into another working copy and then commit them back to their respective repositories. That allows you to keep them clearly separate and distinct while giving you a great deal of flexibility. Once you get into SVN a little more (I'm assuming you are new.) you can start using hooks and I might see where that could get difficult with you setup. If permission are important to you, a single repository might prove more difficult than necessary.
Also, if you are concerned that it will take a lot of time to setup each repository look into the SVNParentPath variable for the Apache configuration file. (Again, I'm assuming you are using Apache.)
|
Try overriding the validate method in your markup.
This should work (haven't tested though):
<input type="text" name="startDate" dojoType="dijit.form.DateTextBox"
constraints="{datePattern:'MM/dd/yyyy'}"
value='<c:out value="${sessionScope.adminMessageForm.startDate}"/>'
validate='return true;'
/> |
Try overriding the validate method in your markup.
This will work (just tested):
<input type="text" name="startDate" dojoType="dijit.form.DateTextBox"
constraints="{datePattern:'MM/dd/yyyy'}"
value='<c:out value="${sessionScope.adminMessageForm.startDate}"/>'
validate='return true;'
/> |
Network shares.
Of course, then you have killer lag on the network, but at least there's only one copy of your files.
You don't want to hear what I did when I was developing on both platforms. But you're going to: drag-n-drop copy a few times a day. Local build and run, and periodically checking it out on Unix to make sure gcc was happy and that the unit tests were happy on that platform too. Not really a rapid turnaround cycle there. |
I just built a quad core - 8 GB of RAM and run Server 2008 with Hyper-V on it. I have VMs for my build server, dev platform, and deployment options (XP, Vista, Server 2003/2008) with snapshots at the various service pack levels. What's nice is you can spin up a VM whenever you need it, and re-allocate the resources when you don't.. So if I want to have 4 or 5 GB of ram and four processors available for my dev platform, no problem.. when I need to test some installs, I can save my status and spin up my test machines.. (and it only ran about $800 US). |
I think there is a great misunderstanding about the use of the Singleton pattern. Most of the comments here refer to it as a place to access global data. We need to be careful here - Singleton as a pattern is **not** for accessing globals.
Singleton should be used to have **only one instance** of the given class. [Pattern Repository][1] has great information on [Singleton][2].
[1]: http://www.netobjectivesrepository.com/
[2]: http://www.netobjectivesrepository.com/TheSingletonPattern |
Is it possible to coax Visual Studio 2008 into using italics for comments? |
|visual-studio|fonts|consolas| |
I'm quite used to my IDE setup in Delphi 7, where I have my comments rendered in italics.
This doesn't appear to be possible in VS2008. There's only an option for bold font, not italics.
Is there some kind of registry hack or font magic I can perform to get it to work? The font I'm using is Consolas, if that makes a difference. |
I'm quite used to my IDE setup in Delphi 7, where I have my comments rendered in italics.
This doesn't appear to be possible in VS2008. There's only an option for bold font, not italics.
Is there some kind of registry hack or font magic I can perform to get it to work? The font I'm using is Consolas, if that makes a difference.
**Edit:** This is possible. See [this][1] answer for details.
[1]: http://stackoverflow.com/questions/17508/how-to-modify-the-style-property-of-a-font-on-windows#25676 |
opendir(D, "/path/to/directory") || die "Can't opedir: $!\n";
while (my $f = readdir(D)) {
print "\$f = $f\n";
}
closedir(D);
EDIT: Oh, sorry, missed the "into an array" part:
my $d = shift;
opendir(D, "$d") || die "Can't opedir $d: $!\n";
my @list = readdir(D);
closedir(D);
foreach my $f (@list) {
print "\$f = $f\n";
} |
opendir(D, "/path/to/directory") || die "Can't opedir: $!\n";
while (my $f = readdir(D)) {
print "\$f = $f\n";
}
closedir(D);
EDIT: Oh, sorry, missed the "into an array" part:
my $d = shift;
opendir(D, "$d") || die "Can't opedir $d: $!\n";
my @list = readdir(D);
closedir(D);
foreach my $f (@list) {
print "\$f = $f\n";
}
EDIT2: Most of the other answers are valid, but I wanted to comment on [this answer][1] specifically, in which this solution is offered:
opendir(DIR, $somedir) || die "can't opendir $somedir: $!";
@dots = grep { (!/^\./) && -f "$somedir/$_" } readdir(DIR);
closedir DIR;
First, to document what it's doing since the poster didn't, it's passing the returned list from readdir() through a grep() that only returns those values that are files (as opposed to dirs, devices, named pipes, etc) and that do not begin with a dot (which makes the list name @dots misleading, but that's due to the change he made when copying it over from the readdir() documentation). Since it limits the contents of the directory it returns I don't think it's technically a correct answer to this question, but it illustrates a common idiom used to filter filenames in perl and I thought it would be valuable to document. Another example seen a lot is:
@list = grep !/^\.\.?$/, readdir(D);
This snippet reads all contents from the dir handle D **except** '.' and '..', since those are very rarely desired to be used in the listing.
[1]: http://stackoverflow.com/questions/22566/how-do-i-read-in-the-contents-of-a-directory-in-perl#24436 |
Logging in a PHP webapp |
|php|logging| |
I want to keep logs of some things that people do in my app, in some cases so that it can be undone if needed.
Is it best to store such logs in a file or a database? I'm completely at a loss as to what the pros and cons are except that it's another table to setup.
Is there a third (or fourth etc) option that I'm not aware of that I should look into and learn about? |
Django Templates and variable attributes. |
|python|django|google-app-engine| |
I'm using Google App Engine and Django Templates.<br>
I have a table that I want to display the objects look something like:<br>
Object Result:
Items = [item1,item2]
Users = [{name='username',item1=3,item2=4},..]
The django template is:
<table>
<tr align="center">
<th>user</th>
{% for item in result.items %}
<th>{{item}}</th>
{% endfor %}
</tr>
{% for user in result.users %}
<tr align="center">
<td>{{user.name}}</td>
{% for item in result.items %}
<td>{{ user.item }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</code>
now the [django manual](http://www.djangoproject.com/documentation/0.96/templates/#variables) states that when it sees a **.** in variables<br>
it tries several things to get the data, one of which is dictionary lookup which is exactly what I want but doesn't seem to happen... |
If the OP is asking about idomatic sorting expressions, then not all languages have a *natural* expression built in. For c I'd go to `<stdlib.h>` and use `qsort`. Something on the lines of :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv){
/* Sort the command line arguments in place */
qsort(argv[1],argc-1,sizeof(char *),(int(*)(const void*, const void*)strcmp);
/* Print the same */
while(--argc){
printf("%s\n",(++argv)[0]);
}
}
to sort the arguments into lexical order. Unfortunately this idiom is rather hard to parse for those not used the ways of c.
----------
|
If the OP is asking about idomatic sorting expressions, then not all languages have a *natural* expression built in. For c I'd go to `<stdlib.h>` and use `qsort`. Something on the lines of :
/* non-functional mess deleted */
to sort the arguments into lexical order. Unfortunately this idiom is rather hard to parse for those not used the ways of c.
----------
*Suitably chastened by the downvote, I actually read the linked article. Mea culpa.*
In anycase the original code did not work, except in the single case I tested. Damn. Plain vanilla c does not have this function, nor is it in any of the usual libraries.
The code below sorts the command line arguments in the **natural** way as linked. *Caveat emptor* as it is only lightly tested.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int naturalstrcmp(const char **s1, const char **s2);
int main(int argc, char **argv){
/* Sort the command line arguments in place */
qsort(&argv[1],argc-1,sizeof(char*),
(int(*)(const void *, const void *))naturalstrcmp);
while(--argc){
printf("%s\n",(++argv)[0]);
};
}
int naturalstrcmp(const char **s1p, const char **s2p){
if ((NULL == s1p) || (NULL == *s1p)) {
if ((NULL == s2p) || (NULL == *s2p)) return 0;
return 1;
};
if ((NULL == s2p) || (NULL == *s2p)) return -1;
const char *s1=*s1p;
const char *s2=*s2p;
do {
if (isdigit(s1[0]) && isdigit(s2[0])){
/* Compare numbers as numbers */
int c1 = strspn(s1,"0123456789"); /* Could be more efficient here... */
int c2 = strspn(s2,"0123456789");
if (c1 > c2) {
return 1;
} else if (c1 < c2) {
return -1;
};
/* the digit strings have equal length, so compare digit by digit */
while (c1--) {
if (s1[0] > s2[0]){
return 1;
} else if (s1[0] < s2[0]){
return -1;
};
s1++;
s2++;
};
} else if (s1[0] > s2[0]){
return 1;
} else if (s1[0] < s2[0]){
return -1;
};
s1++;
s2++;
} while ( (s1!='\0') || (s2!='\0') );
}
This approach is pretty brute force, but it is simple and can probably be duplicated in any imperative language. |
I've used CyberSource in the past, and had a good experience.
They support several interfaces including SOAP, they work internationally, and have a pretty good web interface.
I'm not sure about a cheap, though.
<http://www.cybersource.com/products_and_services/global_payment_services/credit_card_processing/> |
I'd say paypal or [GoogleCheckout][1].
Google Checkout is either 2% + .20USD or free depending on how much you spend on adwords.
[1]: https://checkout.google.com/sell/ |
I'd say paypal or [GoogleCheckout][1].
Google Checkout is either 2% + .20USD or free depending on how much you spend on adwords. If you spend a dollar on adWords, your next $10 on Google checkout is free.
[Paypal][2] is 1.9% to 2.9% + $0.30 USD <span style='color:grey'>(2.9% for up to $30,000/month, 1.9% for more than $100,000/month)</span>
Without factoring in the 20/30 cents, Paypal is just barely cheaper if you sell more than $100,000 per month, and spend nothing on adwords.
[1]: https://checkout.google.com/sell/
[2]: https://www.paypal.com/us/cgi-bin/webscr?cmd=_wp-standard-pricing-outside |
I'm not a security expert, but I think the most important fact you should be aware of, before testing security, is what you are trying to protect. Only if you know what you are trying to protect, you can do a proper analysis of your security measures and only then you can start testing those implemented measures.
Very abstract, I know. However, I think it should be the first step of every security audit. |
In IIS, enable annonymous access and allow the web.config to handle user authentication.
If this doesn't work, please can you send a sample of your web.config. |
A VirtualHost would also work for this and may work better for you as you can host several projects without the need for subdirectories. Here's how you do it:
httpd.conf:
NameVirtualHost *:80
# ...
<VirtualHost *:80>
DocumentRoot C:\projects\transitCalculator\trunk\
ServerName transitcalculator.localhost
<Directory C:\projects\transitCalculator\trunk\>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
HOSTS file (c:\windows\system32\drivers\etc\hosts usually):
# localhost entries
127.0.0.1 localhost transitcalculator.localhost
Now restart XAMPP and you should be able to access http://transitcalculator.localhost/ and it will map straight to that directory.
This can be helpful if you're trying to replicate a production environment where you're developing a site that will sit on the root of a domain name. You can, for example, point to files with absolute paths that will carry over to the server:
<img src="/images/logo.png" alt="My Logo" />
whereas in an environment using aliases or subdirectories, you'd need keep track of exactly where the "images" directory was relative to the current file. |
A VirtualHost would also work for this and may work better for you as you can host several projects without the need for subdirectories. Here's how you do it:
httpd.conf (or extra\httpd-vhosts.conf relative to httpd.conf. Trailing slashes "\" might cause it not to work):
NameVirtualHost *:80
# ...
<VirtualHost *:80>
DocumentRoot C:\projects\transitCalculator\trunk\
ServerName transitcalculator.localhost
<Directory C:\projects\transitCalculator\trunk\>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
HOSTS file (c:\windows\system32\drivers\etc\hosts usually):
# localhost entries
127.0.0.1 localhost transitcalculator.localhost
Now restart XAMPP and you should be able to access http://transitcalculator.localhost/ and it will map straight to that directory.
This can be helpful if you're trying to replicate a production environment where you're developing a site that will sit on the root of a domain name. You can, for example, point to files with absolute paths that will carry over to the server:
<img src="/images/logo.png" alt="My Logo" />
whereas in an environment using aliases or subdirectories, you'd need keep track of exactly where the "images" directory was relative to the current file. |
With respect to diff and merging, I think the version control is more critical for graphics and media elements. If you think about it, most designers are going to be the sole owners of a file -- at least in the case of graphics -- or at least I would think that'd be the case. I'd be curious to hear from a designer. |
Use of 3rd party libraries/components in production |
|bestpractices| |
When using 3rd party libraries/components in production projects, are you rigorous about using only released versions of said libraries?
When do you consider using a pre-release or beta version of a library (in dev? in production, under certain circumstances)?
If you come across a bug or shortcoming of the library and you're already committed to using it, do you apply a patch to the library or create a workaround in your code? |
|untagged| |
|untagged| |
Off the top of my head, pretty much any card since a geforce 2 or something can do it. There's always a performance hit, but this varies on the card and AA mode (of which there are about 100 different kinds) but generally it's quite a performance hit. |
For more than you ever wanted to know about `sort`, read the [specification of `sort`][1] in the [Single Unix Specification v3][2]. It states
> Comparisons [...] shall be performed using the collating sequence of the current locale.
IOW, how `sort` sorts is dependent on the locale (language) settings of the environment that the script is running under.
[1]: http://OpenGroup.Org/onlinepubs/009695399/utilities/sort.html "sort"
[2]: http://OpenGroup.Org/onlinepubs/009695399/ "Single Unix Specification v3" |
I've got 2005 and 2008 installed concurrently.
2008 is a superset of 2005, so I have no reason whatsoever to have them both, I just haven't gotten around to un-installing it yet |
Agree with Orion Edwards, pretty much everything new can. Performance also depends greatly on the resolution you run at. |
I haven't used Oracle's table clusters myself, but I understand that its index table clusters are very much like MS SQL Server's clustered indexes. That is, the row data is physically organized by the clustered index's key.
That makes one ideal for a heavily-accessed column that has a reasonably small number of possible values (compared to the total number of rows), where most queries want to retrieve all rows with a particular value. Because all such rows are physically stored together, disk I/O, particularly seek time, is reduced.
"Reasonably small" is not easily defined, but postal or zip codes in an address table seems reasonable if you're often querying for all addresses in a single code's region. Province/state/territory codes are likely too small a selection for a country-wide address table.
So, you don't want to use them on columns with few possible values (e.g., M/F for gender) because then the clustering doesn't buy you anything and likely costs you for insertions. You also never want to use clustering on "autonumber" surrogate key columns (from sequences in Oracle) because that will create a "hot spot" in the last extent of the table as all insertions must physically happen there. You also don't want to apply clustering to a column value that will be updated because the RDBMS will have to physically move the record to maintain the clustered ordering. |
How do you begin designing a large system? |
|java| |
It's been mentioned to me that I'll be the sole developer behind a large new system. Among other things I'll be designing a UI and database schema.
I'm sure I'll receive some guidance, but I'd like to be able to knock their socks off. What can I do in the meantime to prepare, and what will I need to keep in mind when I sit down at my computer with the spec?
A few things to keep in mind: I'm a college student at my first real programming job. I'll be using Java. We already have SCM set up with automated testing, etc...so tools are not an issue. |
AFAIK, pretty much every OS X developer uses Xcode.
That, and Interface Builder for creating the GUIs.
FWIW, try to get hold of a copy of Hillegas's book, as it's a great introductory tutorial, and the reference Docs Apple provides really aren't. (They are generally very good reference docs, however). |
I'd suggest you pick a fun little product and dive in. If you're looking for a book I'd suggest [Cocoa Programming for Max OSX][1] which is a very good introduction both to Objective-C and Cocoa.
XCode is pretty much the de facto IDE and free with OSX. It should be on your original install DVD. It's good but not as good as Visual Studio (sorry, it's really not).
As a long-time VS user I found the default XCode config a little odd and hard to adjust to, particularly the way a new floating window would open for every sourcefile. Some tweaks I found particularly helpful;
- Settings/General -> All-In-One (unifies editor/debugger window)
- Settings/General -> Open counterparts in same editor (single-window edit)
- Settings/Debugging - "In Editor Debugger Controls"
- Settings/Debugging - "Auto Clear Debug Console"
- Settings/Key-binding - lots of binding to match VS (Ctrl+F5/Shift+F5,Shift+Home, Shift+End etc)
I find the debugger has some annoying issues such as breakpoints not correctly mapping to lines and exceptions aren't immediately trapped by the debugger. Nothing deal-breaking but a bit cumbersome.
I would recommend that you make use of the new property syntax that was introduced for Objective-C 2.0. They make for a heck of a lot less typing in many many places. They're limited to OSX 10.5 only though (yeah, language features are tied to OS versions which is a bit odd).
Also don't be fooled into downplaying the differences between C/C++ and Objective-C. They're very much related but ARE different languages. Try and start Objective-C without thinking about how you'd do X,Y,Z in C/C++. It'll make it a lot easier.
[1]: http://www.amazon.com/gp/product/0321503619?ie=UTF8&tag=shinthin-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0321503619 |
Before you start coding, plan out your database schema - everything else will flow from that. Getting the database reasonably correct early on will save you time and headaches later. |
I don't know if this is the right way to do it but you could add a prebuild event to your startup projcet (if it's static) to clean the project which will force a rebuild.
something like:
devenv project.csproj /clean
|
Do you know much about OOP? If so, look into Spring and Hibernate to keep your implementation clean and [orthagonal][1]. If you get that, you should find TDD a good way to keep your design compact and lean, especially since you have "automated testing" up and running.
UPDATE:
Looking at the first slew of answers, I couldn't disagree more. Particularly in the Java space, you should find plenty of mentors/resources on working out your application with Objects, **not a database-centric approach**. Database design is typically the first step for Microsoft folks (which I do daily, but am in a recovery program, er, Alt.Net). If you keep the focus on what you need to deliver to a customer and let your ORM figure out how to persist your objects, your design should be better.
[1]: http://codebetter.com/blogs/jeremy.miller/archive/2007/01/08/Orthogonal-Code.aspx |
If the OP is asking about idomatic sorting expressions, then not all languages have a *natural* expression built in. For c I'd go to `<stdlib.h>` and use `qsort`. Something on the lines of :
/* non-functional mess deleted */
to sort the arguments into lexical order. Unfortunately this idiom is rather hard to parse for those not used the ways of c.
----------
*Suitably chastened by the downvote, I actually read the linked article. Mea culpa.*
In anycase the original code did not work, except in the single case I tested. Damn. Plain vanilla c does not have this function, nor is it in any of the usual libraries.
The code below sorts the command line arguments in the **natural** way as linked. *Caveat emptor* as it is only lightly tested.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int naturalstrcmp(const char **s1, const char **s2);
int main(int argc, char **argv){
/* Sort the command line arguments in place */
qsort(&argv[1],argc-1,sizeof(char*),
(int(*)(const void *, const void *))naturalstrcmp);
while(--argc){
printf("%s\n",(++argv)[0]);
};
}
int naturalstrcmp(const char **s1p, const char **s2p){
if ((NULL == s1p) || (NULL == *s1p)) {
if ((NULL == s2p) || (NULL == *s2p)) return 0;
return 1;
};
if ((NULL == s2p) || (NULL == *s2p)) return -1;
const char *s1=*s1p;
const char *s2=*s2p;
do {
if (isdigit(s1[0]) && isdigit(s2[0])){
/* Compare numbers as numbers */
int c1 = strspn(s1,"0123456789"); /* Could be more efficient here... */
int c2 = strspn(s2,"0123456789");
if (c1 > c2) {
return 1;
} else if (c1 < c2) {
return -1;
};
/* the digit strings have equal length, so compare digit by digit */
while (c1--) {
if (s1[0] > s2[0]){
return 1;
} else if (s1[0] < s2[0]){
return -1;
};
s1++;
s2++;
};
} else if (s1[0] > s2[0]){
return 1;
} else if (s1[0] < s2[0]){
return -1;
};
s1++;
s2++;
} while ( (s1!='\0') || (s2!='\0') );
return 0;
}
This approach is pretty brute force, but it is simple and can probably be duplicated in any imperative language. |
I'd use a database simply for maintainability - also multiple edits on a file may cause some getting missed out. |
How do you full-text search multiple criteria on left-joined tables in SQL Server? |
|sql-server|full-text-search| |
I have a query that originally looks like this:
select c.Id, c.Name, c.CountryCode, c.CustomerNumber, cacc.AccountNumber, ca.Line1, ca.CityName, ca.PostalCode
from dbo.Customer as c
left join dbo.CustomerAddress as ca on ca.CustomerId = c.Id
left join dbo.CustomerAccount as cacc on cacc.CustomerId = c.Id
where c.CountryCode = 'XX' and (cacc.AccountNumber like '%C17%' or c.Name like '%op%'
or ca.Line1 like '%ae%' or ca.CityName like '%ab%' or ca.PostalCode like '%10%')
On a database with 90,000 records this query takes around 7 seconds to execute (obviously all the joins and likes are taxing).
I have been trying to find a way to bring the query execution time down with full-text search on the columns concerned. However, I haven't seen an example of a full-text search that has three table joins like this, especially since my join condition is not part of the search term.
Is there a way to do this in full-text search? |
The best way that I have found is the [MySQL Migration Toolkit][1] provided by MySQL. I have used it successfully for some large migration projects.
[1]: http://www.mysql.com/products/tools/migration-toolkit/ |
I would define memory leaks as an object not freeing up all the memory allocated after it has completed. I have found this can happen in your application if you are using Windows API and COM (i.e. unmanaged code that has a bug in it or is not being managed correctly), in the framework and in third party components. I have also found not tiding up after using certain objects like pens can cause the issue.
I personally have suffered Out of Memory Exceptions which can be caused but are not exclusive to memory leaks in dot net applications. (OOM can also come from pinning see [Pinning Artical][1]). If you are not getting OOM errors or need to confirm if it is a memory leak causing it then the only way is to profile your application.
I would also try and ensure the following:
a) Everything that implements Idisposable is disposed either using a finally block or the using statement these include brushes, pens etc.(some people argue to set everything to nothing in addition)
b)Anything that has a close method is closed again using finally or the using statement (although I have found using does not always close depending if you declared the object outside the using statement)
c)If you are using unmanaged code/windows API's that these are dealt with correctly after. (some have clean up methods to release resources)
Hope this helps.
[1]: https://blogs.msdn.com/yunjin/archive/2004/01/27/63642.aspx
[2]: http://support.microsoft.com/kb/839047/ |
You can use a [3rd-party library such as SharpZip](http://sharpdevelop.net/OpenSource/SharpZipLib/) as Tom pointed out.
Another way (without going 3rd-party) is to use the Windows Shell API. You'll need to set a reference to the Microsoft Shell Controls and Automation COM library in your C# project. Gerald Gibson has an example at:
<http://geraldgibson.net/dnn/Home/CZipFileCompression/tabid/148/Default.aspx> |
You can do it by adding the following anywhere in your code
$Id:$
So for example Jeff did:
<div id="svnrevision">svn revision: $Id:$</div>
and when checked in the server replaced $Id:$ with the current revision number. I also [found this reference][1].
There is also **$Date:$**, **$Rev:$**, **$Revision:$**
[1]: http://www.compuphase.com/svnrev.htm |
You could use conditional comments to get IE and Firefox to do different things
<![if !IE]>
<p> Firefox only code</p>
<![endif]>
<!--[if IE]>
<p>Internet Explorer only code</p>
<![endif]--> |
You could use conditional comments to get IE and Firefox to do different things
<![if !IE]>
<p> Firefox only code</p>
<![endif]>
<!--[if IE]>
<p>Internet Explorer only code</p>
<![endif]-->
The browsers themselves will ignore code that isn't meant for them to read. |
Personally, I feel like it's important to remain consistent. If you have getters and setters, use them. The only time I would access a field directly is when the accessor has a lot of overhead. It may feel like you're bloating your code unnecessarily, but it can certainly save a whole lot of headache in the future. The classic example:
Later on, you may desire to change the way that field works. Maybe it should be calculated on-the-fly or maybe you would like to use a different type for the backing store. If you are accessing properties directly, a change like that can break an awful lot of code in one swell foop. |
Windows Vista Virtual PC-image for Visual Studio-development minimized |
|windows-vista|virtual-pc| |
Which features and services in Vista can you remove with nLite (or tool of choice) to make a Virtual PC-image of Vista as small as possible?
The VPC must work with development in Visual Studio.
A normal install of Vista today is like 12-14 GB, which is silly when I got it to work with Visual Studio at 4 GB. But with Visual Studio it totals around 8 GB which is a bit heavy to move around in multiple copies. |
@Motti: Combining the `grep`s isn't working, it's having no effect.
I understand that without the trailing `$` something else may folow the checksum & still match, but it didn't work at all with it so I had no choice...
GNU grep 2.5.3 and GNU bash 3.2.39(1) if that makes any difference.
And it looks like the log files are using DOS line-breaks (CR+LF). Does `grep` need a switch to handle that properly? |
Does your video card support Shader 2.0? You can refer [to this wiki page][1] to see if it does...
[1]: http://en.wikipedia.org/wiki/Pixel_shader |
You can also create an ISAPI filter that re-writes urls. The user enters a url with no extension, but the filter will interpret the request so that it does. Note that in IIS it's real easy to screw this up, so you might want to find a pre-written one. I haven't used any myself so I can't recommend a specific product that's any different than what you'd find via google, especially as I don't know your specific use case. But at least now you know what to search for.
You can also rewrite your urls using ASP.Net:
[http://msdn.microsoft.com/en-us/library/ms972974.aspx][1]
[1]: http://msdn.microsoft.com/en-us/library/ms972974.aspx |
@baldy
Thanks. I'll look at as well. Oddly enough though I didn't change the connection string at all. And when I created a new project and tried to drag-n-drop a DB into the LINQ to SQL diagram that error was raised then as well.
|
Error handling / error logging in C++ for library/app combo |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.