instruction stringlengths 0 30k ⌀ |
|---|
Get Home Premium unless you need to connect to a domain controller (if you don't know what that is, you don't need it). |
I did pretty much exactly what you want to do a few years ago. Im trying to find some code for it, though it was at a previous job so that code is at home.
I do remember though i used [this article][1] as my starting point. You set up the LDAP provider so you can actually run a check of the user vs the LDAP. One thing to make sure of if you try the LDAP approach. In the setting file where you set up the LDAP make sure LDAP is all caps, if it is not it will not resolve.
[1]: http://msdn.microsoft.com/en-us/library/ms998360.aspx |
This is a harder problem than it might at first appear, since you need to consider comment tokens inside strings, comment tokens that are themselves commented out etc.
I wrote a string and comment parser for C#, let me see if I can dig out something that will help... I'll update if I find anything. |
This is a harder problem than it might at first appear, since you need to consider comment tokens inside strings, comment tokens that are themselves commented out etc.
I wrote a string and comment parser for C#, let me see if I can dig out something that will help... I'll update if I find anything.
EDIT:
... ok, so I found my old 'codemasker' project. Turns out that I did this in stages, not with a single regex. Basically I inch through a source file looking for start tokens, when I find one I then look for an end-token and mask everything in between. This takes into account the context of the start token... if you find a token for "string start" then you can safely ignore comment tokens until you find the end of the string, and vice versa. Once the code is masked (I used guids as masks, and a hashtable to keep track) then you can safely do your search and replace, then finally restore the masked code.
Hope that helps. |
This is called a [Reservoir Sampling][1] problem. The simple solution is to assign a random number to each element of the list as you see it, then keep the top (or bottom) k elements as ordered by the random number.
[1]: http://gregable.com/2007/10/reservoir-sampling.html |
You could do it yourself. Some MMS companies just have a SOAP API that you can call. All you need to do is construct the XML and send it off via a URL. I have done this once before, but can't remember the name of the company I used. |
You should take a look at the UNPIVOT clause. |
You should take a look at the UNPIVOT clause.
**Update**: GateKiller, strangely enough I read an article (about something unrelated) about it this morning and I'm trying to jog my memory where I saw it again, had some decent looking examples too. It'll come back to me I'm sure. |
You should take a look at the UNPIVOT clause.
**Update1**: GateKiller, strangely enough I read an article (about something unrelated) about it this morning and I'm trying to jog my memory where I saw it again, had some decent looking examples too. It'll come back to me I'm sure.
**Update2**: Found it: [http://weblogs.sqlteam.com/jeffs/archive/2008/04/23/unpivot.aspx][1]
[1]: http://weblogs.sqlteam.com/jeffs/archive/2008/04/23/unpivot.aspx |
There are <a href="http://validator.w3.org/docs/why.html">many reasons</a> to use valid markup. My favorite is that it allows you to use validation as a form of regression testing, preventing the markup equivalent of "delta rot" from leading to real rendering problems once the errors reach some critical mass. And really, just plain sloppy to allow "lazy" errors like typos and mis-nested/iunclosed tags to accumulate. Valid markup is one way to identify <a href="http://stackoverflow.com/questions/3247/identifying-passionate-programmers">passionate programmers</a>.
There's also the issue of debugging: valid markup also gives you a stable baseline from which to work on the inevitable cross-browser compatibility woes. No web developer who values his time should begin debugging browser compatibility problems without first ensuring that the markup is at least *syntactically* valid—and any other invalid markup should have a good reason for being there.
(Incidentally, stackoverflow.com fails both these tests, and suggestions to fix the problems <a href="http://stackoverflow.uservoice.com/pages/general/suggestions/14739">were</a> <a href="http://stackoverflow.uservoice.com/pages/general/suggestions/14740">declined</a>.) |
There are <a href="http://validator.w3.org/docs/why.html">many reasons</a> to use valid markup. My favorite is that it allows you to use validation as a form of regression testing, preventing the markup equivalent of "delta rot" from leading to real rendering problems once the errors reach some critical mass. And really, just plain sloppy to allow "lazy" errors like typos and mis-nested/iunclosed tags to accumulate. Valid markup is one way to identify <a href="http://stackoverflow.com/questions/3247/identifying-passionate-programmers">passionate programmers</a>.
There's also the issue of debugging: valid markup also gives you a stable baseline from which to work on the inevitable cross-browser compatibility woes. No web developer who values his time should begin debugging browser compatibility problems without first ensuring that the markup is at least *syntactically* valid—and any other invalid markup should have a good reason for being there.
(Incidentally, stackoverflow.com fails both these tests, and suggestions to fix the problems <a href="http://stackoverflow.uservoice.com/pages/general/suggestions/14739">were</a> <a href="http://stackoverflow.uservoice.com/pages/general/suggestions/14740">declined</a>.)
All of that said, to answer your specific question, it's probably not worthwhile to use one of the XHTML doctypes unless you plan to produce valid (or at *least* well-formed) markup. XHTML's primary advantages are derived from the fact that XHTML is XML, allowing it to be processed and transformed by tools and technologies that work with XML. If you don't plan to make your XHTML well-formed XML, then there's little point in choosing that doctype. The latest HTML 4 spec will probably do everything you need, and it's much more forgiving. |
Naming conventions allow the development team to design discovereability and maintainability at the heart of the project.
A good naming convention takes time to evolve but once it’s in place it allows the team to move forward with a common language. A good naming convention grows organically with the project. A good naming convention easily copes with changes during the longest and most important phase of the software lifecycle - service management in production.
Here are my answers:
1. Yes, table names should be plural when they refer to a set of *trades*, *securities*, or *counterparties* for example.
2. Yes.
3. Yes. SQL tables are prefixed with tb_, views are prefixed vw_, stored procedures are prefixed usp_ and triggers are prefixed tg_ followed by the database name.
4. List item |
Naming conventions allow the development team to design discovereability and maintainability at the heart of the project.
A good naming convention takes time to evolve but once it’s in place it allows the team to move forward with a common language. A good naming convention grows organically with the project. A good naming convention easily copes with changes during the longest and most important phase of the software lifecycle - service management in production.
Here are my answers:
1. Yes, table names should be plural when they refer to a set of *trades*, *securities*, or *counterparties* for example.
2. Yes.
3. Yes. SQL tables are prefixed with tb_, views are prefixed vw_, stored procedures are prefixed usp_ and triggers are prefixed tg_ followed by the database name.
4. Column name should be lower case separated by underscore.
Naming is hard but in every organisation there is someone who can name things and in every software team there should be someone who takes responsibility for namings standards and ensures that naming issues like ’sec_id’, ’sec_value’ and ’security_id’ get resolved early before they get baked into the project.
So what are the basic tenets of a good naming convention and standards: -
- Use the language of your client and
your solution domain
- Be descriptive
- Be consistent
- Disambiguate, reflect and refactor
- Don’t use abbreviations unless they
are clear to everyone
- Don’t use SQL reserved keywords as
column names |
Naming conventions allow the development team to design discovereability and maintainability at the heart of the project.
A good naming convention takes time to evolve but once it’s in place it allows the team to move forward with a common language. A good naming convention grows organically with the project. A good naming convention easily copes with changes during the longest and most important phase of the software lifecycle - service management in production.
Here are my answers:
1. Yes, table names should be plural when they refer to a set of *trades*, *securities*, or *counterparties* for example.
2. Yes.
3. Yes. SQL tables are prefixed with tb_, views are prefixed vw_, stored procedures are prefixed usp_ and triggers are prefixed tg_ followed by the database name.
4. Column name should be lower case separated by underscore.
Naming is hard but in every organisation there is someone who can name things and in every software team there should be someone who takes responsibility for namings standards and ensures that naming issues like *sec_id*, *sec_value* and *security_id* get resolved early before they get baked into the project.
So what are the basic tenets of a good naming convention and standards: -
- Use the language of your client and
your solution domain
- Be descriptive
- Be consistent
- Disambiguate, reflect and refactor
- Don’t use abbreviations unless they
are clear to everyone
- Don’t use SQL reserved keywords as
column names |
(This isn't really iPhone specific - the same thing will happen in regular Cocoa).
NSUnknownKeyException is a common error when using [Key-Value Coding][1] to access a key that the object doesn't have.
The properties of most Cocoa objects can be accessing directly:
[@"hello world" length] // Objective-C 1.0
@"hello world".length // Objective-C 2.0
Or via Key-Value Coding:
[@"hello world" valueForKey:@"length"]
I would get an NSUnknownKeyException if I used the following line:
[@"hello world" valueForKey:@"purpleMonkeyDishwasher"]
because NSString does not have a property (key) called 'purpleMonkeyDishwasher'.
Something in your code is trying to set a value for the key 'kramerImage' on an UIView, which (apparently) doesn't support that key. If you're using Interface Builder, it might be something in your nib.
Find where 'kramerImage' is being used, and try to track it down from there.
[1]: http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/KeyValueCoding.html |
I'm not sure if you are asking only about .NET or other frameworks, my experience is mostly with Java but I'm sure similar tools exist for .NET.
On the level of classes you can get an auto-generated visualization using UML tools that can typically reverse engineer source code into a diagram. [Netbeans][1] is free and has [Java source to UML reverse engineering][2] features.
Class diagrams however are very low level, they tell you little (directly) about the larger architectural themes. At that point tools like [Structure101][3] can be valuable in discovering architectural properties that you didn't realize were there. They have a trial version and can also deal with C and C++.
[1]: http://www.netbeans.org
[2]: http://www.netbeans.org/kb/60/uml/re.html
[3]: http://www.headwaysoftware.com/products/structure101/index.php |
I agree that the sub-domain idea is the best, but if for some reason it doesn't work for you you could also have the php page at /test proxy requests to a URL at the dotted quad machine (using fopen to access the dotted quad URL). |
Thanks, *IainMH*, *Till*. I'm without a formal computer science qualification and find large blanks in my knowledge. Over the past couple of years I've gone surprisingly far, though knowing the underlining foundation of projects I've created pollute their efficiency and success.
Being a bit of a perfectionist doesn't help (what programmer isn't?) the headaches I get from looking at badly formed projects, that only to my knowing are badly formed only after stepping back and looking at how they're structured. I guess it's a chicken and egg thing, but also a planning thing.
Anyhow, what has helped is studying existing projects. |
Oh, bummer. I just saw, you select AS FOO. Don't you need a HAVING claus in this case?
SELECT whatever AS value FROM table HAVING value > 1;
I still would not use "value". But to be sure, look it up in your docs! |
Windows packet sniffer that can capture loopback traffic? |
|.net|windows|networking|remoting| |
(This is a followup to my [previous question][1] about measuring .NET remoting traffic.)
When I am testing our Windows service / service controller GUI combination, it is often most convenient to run both pieces on my development box. With this setup, the remoting traffic between the two is via loopback, not through the Ethernet card.
Are there any software packet sniffers that can capture loopback traffic on a WinXP machine? [Wireshark](http://www.wireshark.org/) is a great package, but it can only capture external traffic on a Windows machine, not loopback.
[1]: http://stackoverflow.com/questions/42468/how-do-i-measure-bytes-inout-of-an-ip-port-used-for-net-remoting |
|web-application| |
|web-applications| |
Get the DefaultView DataRowView from a DataRow |
|wpf|dataset|binding|datarowview|defaultview| |
Here's the situation: I need to bind a WPF FixedPage against a DataRow. Bindings don't work against DataRows; they work against DataRowViews. I need to do this in the most generic way possible, as I know nothing about and have no control over what is in the DataRow.
What I need is to be able to get a DataRowView for a given DataRow. I can't use the Find() method on the DefaultView because that takes a key, and there is no guarantee the table will have a primary key set.
Does anybody have a suggestion as to the best way to go around this? |
|wpf|dataset|binding|datarowview|defaultview| |
Developing and Testing a Facebook application |
|facebook|webapp|testing| |
Typically I develop my websites on trunk, then merge changes to a testing branch where they are put on a 'beta' website, and then finally they are merged onto a live branch and put onto the live website.
With a Facebook application things are a bit tricky. As you can't view a Facebook application through a normal web browser (it has to go through the Facebook servers) you can't easily give each developer their own version of the website to work with and test.
I have not come across anything about the best way to develop and test a Facebook application while continuing to have a stable live website that users can use. My question is this, what is the best practice for organising the development and testing of a Facebook application? |
|testing|web-application|facebook| |
|testing|web-applications|facebook| |
Tips for database design in a web application |
|database-design|web-application| |
Does someone have any tips/advice on database design for a web application? The kind of stuff that can save me a lot of time/effort in the future when/if the application I'm working on takes off and starts having a lot of usage.
To be a bit more specific, the application is a strategy game (browser based, just text) that will mostly involve players issuing "orders" that will be stored in the database and processed later, with the results also being stored there (the history of "orders" and the corresponding results will probably get quite big). |
Does someone have any tips/advice on database design for a web application? The kind of stuff that can save me a lot of time/effort in the future when/if the application I'm working on takes off and starts having a lot of usage.
To be a bit more specific, the application is a strategy game (browser based, just text) that will mostly involve players issuing "orders" that will be stored in the database and processed later, with the results also being stored there (the history of "orders" and the corresponding results will probably get quite big).
**Edited to add more details** (as requested):
platform: Django
database engine: I was thinking of using MySQL (unless there's a big advantage in using another)
the schema: all I have now are some Django models, and that's far too much detail to post here. And if I start posting schemas this becomes too specific, and I was looking for general tips. For example, consider that I issue "orders" that will be later processed and return a result that I have to store to display some kind of "history". In this case is it better to have a separate table for the "history" or just one that aggregates both the "orders" and the result? I guess I could cache the "history" table, but this would take more space in the database and also more database operations because I would have to constantly create new rows instead of just altering them in the aggregate table.
|
You can also check out [Sync Services for Sql Server and Compact edition][1]. The benefit of Sync Services is that you don't need a replication server or IIS and you can also sync between compact edition databases. This method involves writing a fair bit more code and is fairly involved, but I'd recommend looking into it as a lightweight service.
[1]: http://keithelder.net/blog/archive/2007/09/23/Sync-Services-for-SQL-Server-Compact-Edition-3.5-in-Visual.aspx |
I recommend checking out Microsoft's SQL Server sample databases:
<http://codeplex.com/SqlServerSamples>
The AdventureWorks sample uses a very clear and consistent naming convention that uses schema names for the organization of database objects.
1. Singular names for tables
2. Singular names for columns
3. Schema name for tables prefix
4. Pascal casing |
What are the options for delivering Flash video? |
|flash|video| |
I'd like a concise introduction to the different options. |
Something like this?
dim cars(2)
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x in cars
document.write(x & "<br />")
Next
See [www.w3schools.com][2].
If you want to associate keys and values [use a dictionary object][1] instead:
Dim objDictionary
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Name", "Scott"
objDictionary.Add "Age", "20"
if objDictionary.Exists("Name") then
' Do something
else
' Do something else
end if
[1]: https://web.archive.org/web/20210619173138/https://www.4guysfromrolla.com/webtech/102898-1.shtml
[2]: http://www.w3schools.com/VBscript/vbscript_looping.asp |
Something like this?
dim cars(2),x
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x in cars
response.write(x & "<br />")
Next
See [www.w3schools.com][2].
If you want to associate keys and values [use a dictionary object][1] instead:
Dim objDictionary
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Name", "Scott"
objDictionary.Add "Age", "20"
if objDictionary.Exists("Name") then
' Do something
else
' Do something else
end if
[1]: https://web.archive.org/web/20210619173138/https://www.4guysfromrolla.com/webtech/102898-1.shtml
[2]: http://www.w3schools.com/VBscript/vbscript_looping.asp |
How to display unicode text in OpenGL? |
|windows|unicode|opengl| |
Is there a good way for displaying unicode text in opengl under Windows? For example, when you have to deal with different languages. The most common approach like
#define FONTLISTRANGE 128
GLuint list;
list = glGenLists(FONTLISTRANGE);
wglUseFontBitmapsW(hDC, 0, FONTLISTRANGE, list);
just won't do because you can't create enough lists for all unicode characters. |
Ends up this resolved my issue:
SearchButton.UseSubmitBehavior = False |
There are <a href="http://validator.w3.org/docs/why.html">many reasons</a> to use valid markup. My favorite is that it allows you to use validation as a form of regression testing, preventing the markup equivalent of "delta rot" from leading to real rendering problems once the errors reach some critical mass. And really, it's just plain sloppy to allow "lazy" errors like typos and mis-nested/unclosed tags to accumulate. Valid markup is one way to identify <a href="http://stackoverflow.com/questions/3247/identifying-passionate-programmers">passionate programmers</a>.
There's also the issue of debugging: valid markup also gives you a stable baseline from which to work on the inevitable cross-browser compatibility woes. No web developer who values his time should begin debugging browser compatibility problems without first ensuring that the markup is at least *syntactically* valid—and any other invalid markup should have a good reason for being there.
(Incidentally, stackoverflow.com fails both these tests, and suggestions to fix the problems <a href="http://stackoverflow.uservoice.com/pages/general/suggestions/14739">were</a> <a href="http://stackoverflow.uservoice.com/pages/general/suggestions/14740">declined</a>.)
All of that said, to answer your specific question, it's probably not worthwhile to use one of the XHTML doctypes unless you plan to produce valid (or at *least* well-formed) markup. XHTML's primary advantages are derived from the fact that XHTML is XML, allowing it to be processed and transformed by tools and technologies that work with XML. If you don't plan to make your XHTML well-formed XML, then there's little point in choosing that doctype. The latest HTML 4 spec will probably do everything you need, and it's much more forgiving. |
I've worked on a SAN system in the past with telephony audio recordings which had issues with numbers of files in a single folder - that system became unusable somewhere near 5,000 (on Windows 2000 Advanced Server with an application in C#.Net 1.1)- the only sensible solution that we came up with was to change the folder structure so that there were a more reasonable number of files. Interestingly Explorer would also time out!
The convention we came up with was a structure that broke the structure up in years, months and days - but that will depend upon your system and whether you can control the directory structure... |
I don't believe there is any easy way to make a Windows Installer project have the ease or upgradability of ClickOnce. I use ClickOnce for all the internal .NET apps I develop (with the exception of Console Apps). I find that in an enterprise environment, the ease of deployment outweighs the lack of flexibility. |
> **[Brian Deacon][1]** wrote:
>
> Dvorak is so... Spolsky.
I can't describe why, but I agree.
[1]: http://stackoverflow.com/users/409/brian-deacon |
Nope. The reason ActiveX can do it is because ActiveX is a little application that runs on the client's machine.
I would imagine access to such information via JavaScript would be a security vulnerability. |
Have you seen WiX yet?
<http://wix.sourceforge.net/>
It builds windows installers using an XML file and has additional libraries to use if you want to fancify your installers and the like. I'll admit the learning curve for me was medium-high in getting things started, but afterwards I was able to build a second installer without any hassles.
It will handle updates and other items if you so desire, and you can apply folder permissions and the like to the installers. It also gives you greater control on where exactly you want to install files and is compatible with all the standardized Windows folder conventions, so you can specify "PROGRAM_DATA" or something to that effect and the installer knows to put it in C:\Documents and Settings\All Users\Application Data or C:\ProgramData depending on if you're running XP or Vista.
The rumor is that Office 2007 and Visual Studio 2008 used WiX to create their installer, but I haven't been able to verify that anywhere. I do believe is is developed by some Microsoft folks on the inside. |
Code completion for Perl in vim? |
|perl|vim|vi| |
Surprisingly as you get good at vim, you can code even faster than standard IDEs such as Eclipse. But one thing I really miss is code completion, especially for long variable names and functions.
Is there any way to enable code completion for Perl in vim? |
If you're in a posix shell environment (I'm really thinking of bash), you can redirect any file descriptor to any other file descriptor, so to redirect, you can just:
$ myprogram 2>&5
to redirect stderr to the file represented by fd=5.
Edit: on second thought, I like @Konrad Rudolph's answer about redirection better. rdbuf() is a more coherent and portable way to do it.
As for logging, well...I start with the Boost library for all things C++ that isn't in the std library. Behold: [Boost Logging v2][1]
Of course, there are alternatives:
- [Log4Cpp][2] (a log4j-style API for C++)
- [Log4Cxx][3] (Apache-sponsored log4j-style API)
- [Pantheios][4]
There's also the Windows Event logger.
And a couple of articles that may be of use:
- [Logging in C++ (Dr. Dobbs)][5]
- [Logging and Tracing Simplified (Sun)][6]
[1]: http://www.torjo.com/log2/index.html
[2]: http://log4cpp.sourceforge.net/
[3]: http://logging.apache.org/log4cxx/index.html
[4]: http://pantheios.sourceforge.net/
[5]: http://www.ddj.com/cpp/201804215
[6]: http://developers.sun.com/solaris/articles/logging.html |
If you're in a posix shell environment (I'm really thinking of bash), you can redirect any file descriptor to any other file descriptor, so to redirect, you can just:
$ myprogram 2>&5
to redirect stderr to the file represented by fd=5.
Edit: on second thought, I like @Konrad Rudolph's answer about redirection better. rdbuf() is a more coherent and portable way to do it.
As for logging, well...I start with the Boost library for all things C++ that isn't in the std library. Behold: [Boost Logging v2][1]
**Edit**: Boost Logging is *not* part of the Boost Libraries; it has been reviewed, but not accepted.
Of course, there are alternatives:
- [Log4Cpp][2] (a log4j-style API for C++)
- [Log4Cxx][3] (Apache-sponsored log4j-style API)
- [Pantheios][4]
There's also the Windows Event logger.
And a couple of articles that may be of use:
- [Logging in C++ (Dr. Dobbs)][5]
- [Logging and Tracing Simplified (Sun)][6]
[1]: http://www.torjo.com/log2/index.html
[2]: http://log4cpp.sourceforge.net/
[3]: http://logging.apache.org/log4cxx/index.html
[4]: http://pantheios.sourceforge.net/
[5]: http://www.ddj.com/cpp/201804215
[6]: http://developers.sun.com/solaris/articles/logging.html |
Does it need to be formatted nicely, or will an automated system pick up the mail message on the other end? If the latter, just use the datatable's .WriteXml() method. |
In theory, yes, I can single out a script tag that way. The problem is that we potentially have dozens of situations where this occurs, so I am trying to find some cause or documentation of this behavior.
Also, the `script` tag does not seem to be a part of the DOM anymore after it gets loaded. In our environment, my `container` div remains empty, so I cannot fetch the `script` tag. It should work, though, because in my example above the script does not get executed, but is still part of the DOM. |
View TFS checkin history across branches? |
|tfs|merge|branch| |
In TFS when you merge branch A to branch B and checkin, you get a single changeset on B (typically with a comment like "merged A->B").
This means B doesn't have any of the checkin history from A. So if someone created a new file on branch A, you can't tell who created it from branch B. And if someone updated a file on A, you can't tell who did the update from branch B.
Is there any way to see this kind of detailed changeset history across branches? Some kind of power toy, or third party tool, or anything? |
In TFS when you merge branch A to branch B and checkin, you get a single changeset on B (typically with a comment like "merged A->B").
This means B doesn't have any of the checkin history from A. So if someone created a new file on branch A, you can't tell who created it from branch B. And if someone updated a file on A, you can't tell who did the update from branch B.
Is there any way to see this kind of detailed changeset history across branches? Some kind of power toy, or third party tool, or anything?
Update: The TFS Power Toy tfpt history /followbranches tool does not "expand merges," it only "expands branches" and therefore doesn't solve this problem. |
How do I specify multiple constraints on a generic type in C#? |
|c#|.net|oop| |
What is the syntax for placing constraints on multiple types? The basic example:
class Animal<SpeciesType> where SpeciesType : Species
I would like to place constraints on both types in the following definition such that SpeciesType must inherit from Species and OrderType must inherit from Order:
class Animal<SpeciesType, OrderType> |
I'm not sure if it can or not, but have you looked at [Microsoft Network Monitor][1]? It *might* be an option.
[1]: http://www.microsoft.com/downloads/details.aspx?familyid=18b1d59d-f4d8-4213-8d17-2f6dde7d7aac&displaylang=en |
This should work:
SELECT A.Value
FROM (
SELECT "Ugly OLAP name" as "Value"
FROM OpenQuery( OLAP, 'OLAP Query')
) AS a
WHERE a.Value > 0
It's not that Value is a reserved word, the problem is that it's a column alias, not the column name. By making it an inline view, "Value" becomes the column name and can then be used in a where clause. |
Delete all but top n from database table in SQL |
|sql| |
What's the best way to delete all rows from a table in sql but to keep n number of rows on the top? |
I don't know about other flavors but MySQL [DELETE](http://dev.mysql.com/doc/refman/5.0/en/delete.html) allows LIMIT.
If you could order things so that the n rows you want to keep are at the bottom, then you could do a DELETE FROM table LIMIT tablecount-n.
**Edit**
Oooo. I think I like [Cory Foy's](http://stackoverflow.com/questions/46385/delete-all-but-top-n-from-database-table-in-sql#46386) answer better, assuming it works in your case. My way feels a little clunky by comparison. |
One key feature in a functional language is the concept of first-class functions. The idea is that you can pass functions as parameters to other functions and return them as values.
Functional programming involves writing code that does not change state. The primary reason for doing so is so that successive calls to a function will yield the same result. You can write functional code in any language that supports first-class functions, but there are some languages, like Haskell, which do not allow you to change state. In fact, you're not supposed to make any side effects (like printing out text) at all - which sounds like it could be completely useless.
Haskell instead employs a different approach to IO: monads. These are objects that contain the desired IO operation to be executed by your interpreter's toplevel. At any other level they are simply objects in the system.
What advantages does functional programming provide? Functional programming allows coding with fewer potentials for bugs because each component is completely isolated. Also, using recursion and first-class functions allows for simple proofs of correctness which typically mirror the structure of the code. |
I think that it sounds like this could be done using [SSIS packages][1]. They're similar to SQL 2000's DTS packages. I've used them to successfully transform everything from plain text CSV files, from existing SQL tables, and even from XLS files with 6-digit rows spanned across multiple worksheets. You could use C# to transform the data into an importable format (CSV, XLS, etc), then have your SQL server run a scheduled SSIS job to import the data.
It's pretty easy to create an SSIS package, there's a wizard built-into SQL Server's Enterprise Manager tool (labeled "Import Data" I think), and at the end of the wizard it gives you the option of saving it as an SSIS package. There's a bunch more info [on Technet][2] as well.
[1]: http://msdn.microsoft.com/en-us/library/ms141026.aspx
[2]: http://technet.microsoft.com/en-us/sqlserver/bb671392.aspx |
If your code uses lot of functions that operate on those attributes (name/height/weight), then using class could be a good option. |
If you're using a language with first-class functions like Scheme, you can add memoization without changing the initial algorithm:
(define (memoize fn)
(letrec ((get (lambda (query) '(#f)))
(set (lambda (query value)
(let ((old-get get))
(set! get (lambda (q)
(if (equal? q query)
(cons #t value)
(old-get q))))))))
(lambda args
(let ((val (get args)))
(if (car val)
(cdr val)
(let ((ret (apply fn args)))
(set args ret)
ret))))))
(define fib (memoize (lambda (x)
(if (< x 2) x
(+ (fib (- x 1)) (fib (- x 2)))))))
The first block provides a memoization facility and the second block is the fibonacci sequence using that facility. This now has an O(n) runtime (as opposed to O(2^n) for the algorithm without memoization) |
If you're using a language with first-class functions like Scheme, you can add memoization without changing the initial algorithm:
(define (memoize fn)
(letrec ((get (lambda (query) '(#f)))
(set (lambda (query value)
(let ((old-get get))
(set! get (lambda (q)
(if (equal? q query)
(cons #t value)
(old-get q))))))))
(lambda args
(let ((val (get args)))
(if (car val)
(cdr val)
(let ((ret (apply fn args)))
(set args ret)
ret))))))
(define fib (memoize (lambda (x)
(if (< x 2) x
(+ (fib (- x 1)) (fib (- x 2)))))))
The first block provides a memoization facility and the second block is the fibonacci sequence using that facility. This now has an O(n) runtime (as opposed to O(2^n) for the algorithm without memoization).
*Note: the memoization facility provided uses a chain of closures to look for previous invocations. At worst case this can be O(n). In this case, however, the desired values are always at the top of the chain, ensuring O(1) lookup.* |
|web-applications|database-design| |
If you are talking about Windows Forms, this article should help you build you tri-state TreeView:
<http://www.codeproject.com/KB/tree/treeviewex2003.aspx?display=Print> |
If you are talking about Windows Forms, this article should help you build you tri-state TreeView:
<http://www.codeproject.com/KB/tree/treeviewex2003.aspx?display=Print>
If you need tri-state checkboxes on a treeview on asp.net i think you need to use a third-party component. Take a look a this one, and click "tri-state checkboxes" on the left side:
<http://www.aspnetexpert.com/demos/tree/default.aspx> |
Large Python Includes |
|python| |
I have a file that I want to include in Python but the included file is fairly long and it'd be much neater to be able to split them into several files but then I have to use several include statements.
Is there some way to group together several files and include all at once? |
If you ever receive values at the maximum or minimum, then you are, by definition, clipping. Those values represent their particular value as well as all values beyond, and so they are best used as outside bounds detectors.
-Adam |
Readability always wins. Always. Except when it doesn't. And that should be very rarely. |
Ask yourself the following question: *why do you want to store credit card numbers in the first place*? Chances are that you don't. In fact, if you *do* store them and manage to have one stolen, you could be looking at some serious liability.
I've written an app that does store credit card numbers (since the transactions were processed offline). Here's a good way to do it:
- Get an SSL certificate!
- Create a form to get CC# from the user.
- Encrypt part (not all!) of the CC# and store it in your database. (I'd suggest the middle 8 digits.) Use a strong encryption method and a secret key.
- Mail the remainder of the CC# to whoever processes your transactions (probably yourself) with the ID of the person to process.
- When you log in later, you will type in the ID and the mailed-out portion of the CC#. Your system can decrypt the other portion and recombine to get the full number so you can process the transaction.
- Finally, delete the online record. My paranoid solution was to overwrite the record with random data before deletion, to remove the possibility of an undelete.
This sounds like a lot of work, but by never recording a complete CC# anywhere, you make it extremely hard for a hacker to find anything of value on your webserver. Trust me, it's worth the peace of mind. |
Ask yourself the following question: *why do you want to store credit card numbers on a publicly accessible webserver in the first place*? Trust me, you don't. Even if you think you do, you don't. That's what [accounting software][1] is for. Furthermore, you're looking at some serious liability if your webserver ever gets hacked.
Having said all that, I have written an app that stores credit card numbers online temporarily (since the transactions were processed offline). Here's a good way to do it:
- Get an SSL certificate!
- Create a form to get CC# from the user.
- Encrypt part (not all!) of the CC# and store it in your database. (I'd suggest the middle 8 digits.) Use a strong encryption method and a secret key.
- Mail the remainder of the CC# to whoever processes your transactions (probably yourself) with the ID of the person to process.
- When you log in later, you will type in the ID and the mailed-out portion of the CC#. Your system can decrypt the other portion and recombine to get the full number so you can process the transaction.
- Finally, delete the online record. My paranoid solution was to overwrite the record with random data before deletion, to remove the possibility of an undelete.
This sounds like a lot of work, but by never recording a complete CC# anywhere, you make it extremely hard for a hacker to find anything of value on your webserver. Trust me, it's worth the peace of mind.
[1]: http://en.wikipedia.org/wiki/Accounting_software |
When the separator String for the command is allways the same String or char (like the ";") y recomend you use the StrinkTokenizer class:
[StringTokenizer][1]
but when the separator varies or is complex y recomend you to use the regular expresions, wich can be used by the String class itself, method split, since 1.4. It uses the Pattern class from the java.util.regex package
[Pattern][2]
[1]: http://java.sun.com/javase/6/docs/api/java/util/StringTokenizer.html
[2]: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html |
None. .NET relies on underlying Windows API calls that really, really hate that amount of files themselves.
As Ronnie says: split them up. |
If I understand your question, you want to affect what columns are returned first, second, third, etc in **existing** queries, right?
If all of your queries are written with SELECT * FROM TABLE - then they will show up in the output as they are layed out in SQL. If your queries are written with SELECT Field1, Field2 FROM TABLE - then the order they are layed out in SQL does not matter. |
Select Table_Name From Information_Schema.Columns
Where Column_Name = 'YourFieldName' |
I'm old-school:
select distinct object_name(id) from syscolumns where name = 'FIELDNAME' |
The following query will bring back a unique list of Tables where Column_Name is equal to the column you are looking for:
Select
Table_Name
From
INFORMATION_SCHEMA.COLUMNS
Where
Column_Name = 'Desired_Column_Name'
Group By
Table_Name |
Depending on the issue I like a combination of error_reporting(E_ALL) mixed with echo tests (to find the offending line/file the error happened in initally; you KNOW it's not always the line/file php tells you right?), IDE brace matching (to resolve "Parse error: syntax error, unexpected $end" issues), and print_r(); exit; dumps (real programmers view the source ;p).
You also can't beat phpdebug (check sourceforge) with "memory_get_usage();" and "memory_get_peak_usage();" to find the problem areas. |
ClickOnce can be problematic if you have 3rd party components that need to be installed along with your product. You can skirt this to some extent by creating installers for the components however with ClickOnce deployment you have to create the logic to update said component installers.
I've in a previous life used Wise For Windows Installer to create installation packages. While creating upgrades with it were not automatic like ClickOnce is, they were more precise and less headache filled when it came to other components that needed to be registered/added. |
Go to [http://www.fogbugz.com/][1] then at the bottom under "Try It", sign up.
under Settings => Your FogBugz Hosted Account, it should either already say "Payment Information: Using Student and Startup Edition." or there should be some option/link to turn on the Student and Startup Edition.
And yes, it's not only for Students and Startups, I asked their support :-)
Disclaimer: I'm not affiliated with FogCreek and Joel did not just deposit money in my account.
[1]: http://www.fogbugz.com/ |
As mentioned d will be `IEnumerable<MyProduct>` while f is `List<MyProduct>`
The conversion is done by the C# compiler
var d =
from mp in MyProducts
where mp.Price < 50d
select mp;
Is converted to (before compilation to IL and with generics expanded):
var d =
MyProducts.
Where<MyProduct>( mp => mp.Price < 50d ).
Select<MyProduct>( mp => mp );
//note that this last select is optimised out if it makes no change
Note that in this simple case it makes little difference. Where Linq becomes really valuable is in much more complicated loops.
For instance this statement could include group-bys, orders and a few let statements and still be readable in Linq format when the equivalent `.Method().Method.Method()` would get complicated. |
1. Definitely keep table names singular, person not people
2. Same here
3. No. I've seen some terrible prefixes, going so far as to state what were dealing with is a table (tbl_) or a user store procedure (usp_). This followed by the database name... Don't do it!
4. Yes. I tend to UpperCamelCase all my table names |