instruction
stringlengths
0
30k
It depends on the complexity of your query. If you're retrieving the data once, then doing a table scan is faster. However, if you're going back to the table more than once for related information in the same query, then the index is faster. Another related strategy is to do the table scan, and put all the data in a temporary table. Then index THAT and then you can do all your subsequent selects, groupings, and as many other queries on the subset of indexed data. The benefit being that looking up related information in related tables using the temp table is MUCH faster. However, space is cheap these days, so you'd probably best be served by examining how your users actually USE your system and adding indexes on those frequent columns. I have yet to see users use ALL the search parameters ALL the time.
|python|
What is the best way to go about calling a function given a string with the function's name in a python program. For example, let's say that I have a module foo, and I have a string whose contents are "bar". What is the best way to go about calling foo.bar()? I need to get the return value of the function, which is why I don't just use eval. I figured out how to do it by using eval to define a temp function that returns the result of that function call, but I'm hoping that there is a more elegant way to do this.
Maybe I'm crazy but worrying about speed in cases like this using an interpretive language is like trying to figure out what color to paint the shed. Let's not even get into the idea that this kind of optimization is entirely pre-mature. You hit the nail on the head when you said 'maintainability'. I'd choose the approach that is the most productive and most maintainable. If you need speed later, it ain't gonna come from switching between procedural versus object oriented coding paradigms inside an interpreted language.
Bottom line: no, because the overhead of interpretation is greater than the overhead of method dispatching. As I heard someone observe a while back: "I used to worry about the overhead of a virtual function. Then I started programming in Tcl."
Bottom line: no, because the overhead of interpretation overwhelms the overhead of method dispatching.
If you are using an interpreted language, the difference is irrelevant. You should not be using an interpreted language if performance is an issue. Both will perform about the same.
Assuming module 'foo' with method 'bar': import foo methodToCall = getattr(foo, 'bar') result = methodToCall() As far as that goes lines 2 and three can be compressed to: result = getattr(foo, 'bar')() if that makes more sense for your use case. You can use getattr in this fashion on class instance bound methods, module-level methods, classmethods... the list goes on.
I always use method 2 as well. The only benefit of using each is if you're just reading (rather than re-assigning) the value of the hash entry, you're not constantly de-referencing the hash.
The official size is 57x57. I would recommend using the exact size simply due to the fact that it takes less memory when loaded (unless Apple caches the scaled representation). With that said, [Rex is right](http://stackoverflow.com/questions/1598/what-are-the-correct-pixel-dimensions-for-an-apple-touch-icon#1599) that any square size will work
If you're mostly concerned with data layer testing, you might want to check out this book: **xUnit Test Patterns: Refactoring Test Code**. I was always unsure about it myself, but this book does a great job to help enumerate the concerns like performance, reproducibility, etc.
Can ASP.NET AJAX partial rendering work inside a SharePoint 2007 application page?
|ajax|sharepoint|
I have a simple page with my ScriptManager and my UpdatePanel, and my ContentTemplate has one ListBox and one Label. I am just trying to catch its OnSelectionChanged so I can update the text in the Label. No matter what settings I try to tweak, I always get a full-page postback. Is this really not going to work, or am I just screwing this up? thanks, Chris
|unix|filesystems|
Have you looked at Wikipedia's [Category:Computational problems][1] and [Category:NP Complete Problems][2] pages? It's probably not complete, but they look like good starting points. Wikipedia seems to do pretty well in CS topics. [1]: http://en.wikipedia.org/wiki/Category:Computational_problems [2]: http://en.wikipedia.org/wiki/Category:NP-complete_problems
I did subclass and it was easy and did work. I still don't like it so much. I was already subclassing column styles for other reasons. I'd rather handle all databinding myself, where I can more easily change it and test it. This whole mixing of the UI with the data is old school, and not it a good way. Thanks for your answers, it's good to have a second opinions. Mike
A lot of times I'll use client alias to point an application at a different sql server than the ones it's connection string is for, esp. handy when working on DTS or an application with a hard coded connection string. Have everybody use a commonly named alias, use the alias in the connection string and point the alias’s on each dev box to the to the different instances. That way you won't have to worry about if the server is the default instance or not.
We are a C++ shop, that is moving to C# for UI work (our image processing and 3D graphics code will stay in native C++). I found [C# for C++ Developers][1] a very quick and handy introduction to the language. Our team has been using Visual Studio for while, whereas I came from an SVN/Slickedit/CMake/Ant kind of environment in my last job. I found it very helpful to just dive in and start working, but as I figured things out, I documented them on our internal wiki. It's been about 6 months, but not only am I very comfortable with Visual Studio, but the rest of the team has had me streamlining our build process, and converting our build system to do out-of-place builds from Visual Studio (which I document on the wiki, of course). So I'd say do both - dive in and do real work, but document what you learn - which not only helps others, but it reinforces it in your mind. [1]: http://media.wiley.com/assets/264/22/0764557599_bonus_AppD.pdf
Microsoft has a page which gives several examples of writing scripts to "drive" MS Word. [One such example][1] shows how to convert from a Word document to HTML. By changing the last parameter to any values listed [here][2], you can get the output in different formats. [1]: http://www.microsoft.com/technet/scriptcenter/scripts/office/word/default.mspx?mfr=true [2]: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdsaveformat%28VS.80%29.aspx
**There's no easy way to find out the memory size of a python object**. One of the problems you may find is that Python objects - like lists and dicts - may have references to other python objects (in this case, what would your size be? The size containing the size of each object or not?). There are some pointers overhead and internal structures related to object types and garbage collection. Finally, some python objects have non-obvious behaviors. For instance, lists reserve space for more objects than they have, most of the time; dicts are even more complicated since they can operate in different ways (they have a different implementation for small number of keys and sometimes they over allocate entries). There is a [big chunk of code][1] out there to try to best approximate the size of a python object in memory. There's also some [simpler approximations][2]. But they will always be approximations. You may also want to check some [old description about PyObject][3] (the internal C struct that represents virtually all python objects). [1]: http://code.activestate.com/recipes/544288/ [2]: http://mail.python.org/pipermail/python-list/2008-January/472683.html [3]: http://mail.python.org/pipermail/python-list/2002-March/135223.html [4]: http://docs.python.org/lib/module-struct.html
A better design is to make this class release the expensive resource on its own, before its disposed. For example, If its a database connection, only connect when needed and release immediately, long before the actual class gets disposed.
You would use what is known as an iterative recursive function, which is O(N) in time as it takes N iterations to complete and O(1) in space as each function it holds its own state in the function arguments. (define (reverse sentence-to-reverse) (reverse-iter (sentence-to-reverse "")) (define (reverse-iter(sentence, reverse-sentence) (if (= sentence.length 0) reverse-sentence ( reverse-iter( remove-first-word(sentence), add-first-word(sentence, reverse-sentence))) *Note: I have written this in scheme which is very novice, so apologies for lack of correct string manipulation.* remove-first-word finds the first word boundary of sentence, then takes that section of characters (including space and punctuation) and removes it and returns new sentence add-first-word finds the first word boundary of sentence, then takes that section of characters (including space and punctuation) and adds it to reverse-sentence and returns new reverse-sentence contents.
You would use what is known as an iterative recursive function, which is O(N) in time as it takes N iterations to complete and O(1) in space as each function it holds its own state in the function arguments. (define (reverse sentence-to-reverse) (reverse-iter (sentence-to-reverse "")) (define (reverse-iter(sentence, reverse-sentence) (if (= 0 string-length sentence) reverse-sentence ( reverse-iter( remove-first-word(sentence), add-first-word(sentence, reverse-sentence))) *Note: I have written this in scheme which is very novice, so apologies for lack of correct string manipulation.* remove-first-word finds the first word boundary of sentence, then takes that section of characters (including space and punctuation) and removes it and returns new sentence add-first-word finds the first word boundary of sentence, then takes that section of characters (including space and punctuation) and adds it to reverse-sentence and returns new reverse-sentence contents.
You would use what is known as an iterative recursive function, which is O(N) in time as it takes N (N being the number of words) iterations to complete and O(1) in space as each iteration holds its own state within the function arguments. (define (reverse sentence-to-reverse) (reverse-iter (sentence-to-reverse "")) (define (reverse-iter(sentence, reverse-sentence) (if (= 0 string-length sentence) reverse-sentence ( reverse-iter( remove-first-word(sentence), add-first-word(sentence, reverse-sentence))) *Note: I have written this in scheme which I am a complete novice, so apologies for lack of correct string manipulation.* remove-first-word finds the first word boundary of sentence, then takes that section of characters (including space and punctuation) and removes it and returns new sentence add-first-word finds the first word boundary of sentence, then takes that section of characters (including space and punctuation) and adds it to reverse-sentence and returns new reverse-sentence contents.
|c|memory-management|
|c|memory|
How to dispose a class in .net?
|.net|class|dispose|
The .net garbage collector will eventually free up memory, but what if you want that memory back immediately? What code do you need to use in a class <b>myclass</b> to call myclass.dispose and free up all the used space by variables and objects in <b>myclass</b>?
|.net|memorymanagement|
The .net garbage collector will eventually free up memory, but what if you want that memory back immediately? What code do you need to use in a class <b>myclass</b> to call myclass.dispose and free up all the used space by variables and objects in <b>myclass</b>? <hr/> **NOTE**: Several users have indicated that the accepted answer is incorrect. Please refer to this answer, which I believe to be correct: [http://beta.stackoverflow.com/questions/12368#12394][1] - [Jon][2] [1]: http://beta.stackoverflow.com/questions/12368#12394 [2]: http://beta.stackoverflow.com/users/5/jon-galloway
|.net|memory-management|
The .net garbage collector will eventually free up memory, but what if you want that memory back immediately? What code do you need to use in a class <b>myclass</b> to call myclass.dispose and free up all the used space by variables and objects in <b>myclass</b>?
|.net|memory-management|dispose|
|.net|memory|dispose|
PreviousPage property "The System.Web.UI.Page representing the page that transferred control to the current page." very useful
try clearing your local VS cache. find your project and delete the folder. the folder is created by VS for what reason I honestly don't understand. but I've had several occasions where clearing it and doing a re-build fixes things... hope this is all that you need as well. here C:\Documents and Settings\Administrator\Local Settings\Temp\VWDWebCache and possibly here C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\WebsiteCache
it would make deployment easier for clients that use godaddy where the database isn't in the app_data folder. also backing up those websites would be as simple as FTP the entire thing. i have concerns about possible collisions on saving. especially if I add something as simple as a click counter to say a list of mp3 files visitors to the site can access.
On Unix systems you can use [mlock(2)](http://linux.die.net/man/2/mlock) to lock memory pages into RAM, preventing them being paged. > mlock() and mlockall() respectively lock part or all of the calling > process’s virtual address space into RAM, preventing that memory from > being paged to the swap area. There is a limit to how much memory each process can lock, it can be shown with `ulimit -l` and is measured in kilobytes. On my system, the default limit is 32 kiB per process.
Yeah, the built-in [`isNaN(object)`][1] will be much faster than any regex parsing. Although the results are somewhat different to what you're looking for ([try it][2]): document.write(!isNaN('-1') + "<br />"); document.write(!isNaN('-1.5') + "<br />"); document.write(!isNaN('0') + "<br />"); document.write(!isNaN('0.42') + "<br />"); document.write(!isNaN('.42') + "<br />"); document.write(!isNaN('99,999') + "<br />"); document.write(!isNaN('0x89f') + "<br />"); document.write(!isNaN('#abcdef') + "<br />"); document.write(!isNaN('1.2.3') + "<br />"); document.write(!isNaN('') + "<br />"); document.write(!isNaN('blah') + "<br />"); true true true true true false true false false true false [1]: http://www.w3schools.com/jsref/jsref_isNaN.asp [2]: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_isnan
Yeah, the built-in [`isNaN(object)`][1] will be much faster than any regex parsing, because it's built-in and compiled, instead of interpreted on the fly. Although the results are somewhat different to what you're looking for ([try it][2]): document.write(!isNaN('-1') + "<br />"); document.write(!isNaN('-1.5') + "<br />"); document.write(!isNaN('0') + "<br />"); document.write(!isNaN('0.42') + "<br />"); document.write(!isNaN('.42') + "<br />"); document.write(!isNaN('99,999') + "<br />"); document.write(!isNaN('0x89f') + "<br />"); document.write(!isNaN('#abcdef') + "<br />"); document.write(!isNaN('1.2.3') + "<br />"); document.write(!isNaN('') + "<br />"); document.write(!isNaN('blah') + "<br />"); true true true true true false true false false true false [1]: http://www.w3schools.com/jsref/jsref_isNaN.asp [2]: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_isnan
What Jason Pratt posted is correct. >>> class Test(object): ... def a(self): ... pass ... >>> def b(self): ... pass ... >>> Test.b = b >>> type(b) <type 'function'> >>> type(Test.a) <type 'instancemethod'> >>> type(Test.b) <type 'instancemethod'> As you can see, Python doesn't consider b() any different than a(). In Python all methods are just variables that happen to be functions.
> malloc can return NULL if no memory is > available. You're not checking for > that. Right you are... I didn't think about that as I was monitoring the memory and it there was enough free. Is there any way for there to be available memory on the system but for malloc to fail? Either way...I will add that check :)
> malloc can return NULL if no memory is > available. You're not checking for > that. Right you are... I didn't think about that as I was monitoring the memory and it there was enough free. Is there any way for there to be available memory on the system but for malloc to fail? > Yes, if memory is fragmented. Also, when you say "monitoring memory," there may be something on the system which occasionally consumes a lot of memory and then releases it before you notice. If your call to `malloc` occurs then, there won't be any memory available. -- **Joel** Either way...I will add that check :)
What is the output of `which godi_confdir`? P.S. I remember having this exact same problem, but I don't remember precisely how I fixed it.
How do I do full-text searching in Ruby on Rails?
|ruby-on-rails|full-text-search|
I would like to do full-text searching of data in my Ruby on Rails application. What options exist?
Standards Document
|coding-style|
I am with writing a coding standards document for a team of about 15 with a load of between 10 and 15 projects a year. Amongst other sections (which I may post here as I get to them) I am writing a section on code formatting. So to start with, I think it wise that, for whatever reason, we establish some basic, consistent code formatting/naming standards. I've looked at roughly 10 projects written over the last 3 years from this team and I'm obviously finding a pretty wide range of styles. Contractors come in and out and at times, double the team size. I am looking for a few suggestions for code formatting and naming standards that have really paid off ... but that can also really be justified. I think consistency and shared-patterns go a long way to making the code more maintainable ... but are there other things I ought to consider when defining said standards? - How do you lineup parens? Do you follow the same paren guidelines when dealing with classes, methods, try catch blocks, switch statements, if else blocks etc. - Do you line up fields on a column? Do you notate private variables with an underscore? Do you follow any naming conventions to make it easier to find particulars in a file? How do you order the members of your class? What about suggestions for namespace, packaging or source code folder/organization standards? I tend to start with something like <com|org|...>.<company>.<app>.<layer>.<function>.ClassName and I'm curious to see if there are other more accepted practices that what I am accustomed to before I venture off dictating these standards. Links to standards published online would be great too - although I've done a bit of that already.
My 2cents, I am using eclipse for some months now with m2eclipse integration. It's easy to use and straight forward. Once you associate your project to maven and update the dependencies using m2eclipse, any change to pom.xml are reflected to entire project, even Java version definition causes it to be compiled in right JRE (if you have it installed, and properly configured into eclipse.) Another advantage I found is the maven plug-ins are easy to use integrated with eclipse (jetty being my best example, again, properly configured you can easily integrate maven, jetty-plug-in and Eclipse Debugger) Compilation, packaging and all other maven features are equally easy to use with a couple clicks or shortcuts. About q4e I have been reading a lot of good stuff about it and seems the next versions will do a lot more than m2eclipse, with a better dependency management and even visual graphs (!) but the general opinion is that m2eclipse is still better than q4e but q4e is getting better each new version and maybe will surpass m2eclipse soon.
You can use Ferret (which is Lucene written in Ruby). It integrates seamless with Rails using the acts_as_ferret mixin. Take a look at "[How to Integrate Ferret With Rails][1]". A alternative is [Sphinx][2]. Kind Regards [1]: http://wiki.rubyonrails.org/rails/pages/HowToIntegrateFerretWithRails [2]: http://www.slashdotdash.net/articles/2007/08/06/rails-searching-with-sphinx
Do you continue development in a branch or in the trunk?
|svn|version-control|releasing|
Suppose you're developing a software product that has periodic releases. What are the best practices with regard to branching and merging? Slicing off periodic release branches to the public (or whomever your customer is) and then continuing development on the trunk, or considering the trunk the stable version, tagging it as a release periodically, and doing your experimental work in branches. What do folks think is the trunk considered "gold" or considered a "sand box"?
The easiest way would be to use Automation thru the Microsoft.Office.Interop.<Application> libraries. You can create an instance of a Word application, for example. There are methods attached to the Application object that will allow you to open and close documents, plus pretty much anything else you can accomplish in VBA by recording a macro. You could also just write the VBA code in your Office application to do roughly the same thing. Both approaches are equally valid, depending on your comfort in programming in C#, VB.NET or VBA.
The trunk is generally the main development line. Releases are branched off and often times experimental or major work is done on branches then merged back to the trunk when it's ready to be integrated with the main development line.
The already mentioned [A List Apart][1] is really good. Another site I've used since I started web development is SitePoint.com. Here is their [CSS Reference][2]. If you want a good CSS book their's is one of my favorites. [1]: http://www.alistapart.com/ [2]: http://reference.sitepoint.com/css
I tend to take the "release branch" approach. The trunk is volatile. Once release time approaches, I'd make a release branch, which I would treat more cautiously. When that's finally done, I'd label/tag the state of the repository so I'd know the "official" released version. I understand there are other ways to do it - this is just the way I've done it in the past.
I'll add this [Url][1] to my post I found it today, it has some information regarding the subject but no real "performance" information. [1]: http://www.ibm.com/developerworks/web/library/wa-aj-jaxer/index.html?ca=dgr-jw64wa-aj-jaxer&S_TACT=105AGY46&S_CMP=GRsitejw64
Checklist for Database Schema Upgrades
|database|installation|version-control|
Having to upgrade a database schema makes installing a new release of software a lot trickier. What are the best practices for doing this? I'm looking for a checklist or timeline of action items, such as - shut down apps - modify schema - install new apps - restart db etc, showing how to minimize risk and downtime. Issues such as - backing out of the upgrade if things go awry - minimizing impact to existing apps - "hot" updates while the database is running - promoting from devel to test to production servers are especially of interest.
Having to upgrade a database schema makes installing a new release of software a lot trickier. What are the best practices for doing this? I'm looking for a checklist or timeline of action items, such as - 8:30 shut down apps - 8:45 modify schema - 9:15 install new apps - 9:30 restart db etc, showing how to minimize risk and downtime. Issues such as - backing out of the upgrade if things go awry - minimizing impact to existing apps - "hot" updates while the database is running - promoting from devel to test to production servers are especially of interest.
You can use multiple inheritance in your html elements (e.g. `<div class="one two">`) but I'm not aware of a way of having constants in the CSS files themselves. This link (the first found when googling your question) seems to have a fairly indepth look at the issue: <http://icant.co.uk/articles/cssconstants/>
You should comma seperate each id or class for example: h1,h2 { color: #fff; }
It may not include files that you normally wouldn't see. Or, the files may be there, but you may be unable to see them when reopening the .zip file in explorer, because they are hidden. You may go into Tools->Folder Options, go to the View tab, and select the radio button to view hidden files and folders.
A write lock doesn't help if the file upload failed part way through and the sender hasn't tried resending (and relocking) the file yet.
Stack objects are handled automatically by the compiler. When the scope is left, it is deleted. { obj a; } // a is destroyed here When you do the same with a 'newed' object you get a memory leak : { obj* b = new obj; } b is not destroyed, so we lost the ability to reclaim the memory b owns. And maybe worse, the object cannot clean itself up. In C the following is common : { FILE* pF = fopen( ... ); // ... do sth with pF fclose( pF ); } In C++ we write this : { std::fstream f( ... ); // do sth with f } // here f gets auto magically destroyed and the destructor frees the file When we forget to call fclose in the C sample the file is not closed and may not be used by other programs. (e.g. it cannot be deleted). Another example, demonstrating the object string, which can be constructed, assigned to and which is destroyed on exiting the scope. { string v( "bob" ); string k; v = k // v now contains "bob" } // v + k are destroyed here, and any memory used by v + k is freed
I was recently wanting to put Drag and Drop functionality in my project and I hadn't come across this issue, but I was intrigued and really wanted to see if I could come up with a better method than the one described in the page you linked to. I hope I clearly understood everything you wanted to do and overall I think I succeeded in solving the problem in a much more elegant and simple fashion. On a quick side note, for problems like this it would be great if you provide some code so we can see exactly what it is you are trying to do. I say this only because I assumed a few things about your code in my solution...so hopefully it's pretty close. Here's the code, which I will explain below: this.LabelDrag.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.LabelDrag_QueryContinueDrag); this.LabelDrag.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelDrag_MouseDown); this.LabelDrag.MouseUp += new System.Windows.Forms.MouseEventHandler(this.LabelDrag_MouseUp); this.LabelDrop.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDrop_DragDrop); this.LabelDrop.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelMain_DragEnter); public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void LabelDrop_DragDrop(object sender, DragEventArgs e) { LabelDrop.Text = e.Data.GetData(DataFormats.Text).ToString(); } private void LabelMain_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } private void LabelDrag_MouseDown(object sender, MouseEventArgs e) { //EXTREMELY IMPORTANT - MUST CALL LabelDrag's DoDragDrop method!! //Calling the Form's DoDragDrop WILL NOT allow QueryContinueDrag to fire! ((Label)sender).DoDragDrop(TextMain.Text, DragDropEffects.Copy); } private void LabelDrag_MouseUp(object sender, MouseEventArgs e) { LabelDrop.Text = "LabelDrag_MouseUp"; } private void LabelDrag_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) { //Get rect of LabelDrop Rectangle rect = new Rectangle(LabelDrop.Location, new Size(LabelDrop.Width, LabelDrop.Height)); //If the left mouse button is up and the mouse is currently over LabelDrop if (Control.MouseButtons != MouseButtons.Left && !rect.Contains(PointToClient(Control.MousePosition))) { //Cancel the DragDrop Action e.Action = DragAction.Cancel; //Manually fire the MouseUp event LabelDrag_MouseUp(sender, new MouseEventArgs(Control.MouseButtons, 0, Control.MousePosition.X, Control.MousePosition.Y, 0)); } } } I have left out most of the designer code, but included the Event Handler link up code so you can be sure what is linked to what. In my example, the drag/drop is occuring between the labels LabelDrag and LabelDrop. The main piece of my solution is using the QueryContinueDrag event. This event fires when the keyboard or mouse state changes after DoDragDrop has been called on that control. You may already be doing this, but it is very important that you call the DoDragDrop method of the control that is your source and not the method associated with the form. Otherwise QueryContinueDrag will NOT fire! One thing to note is that QueryContinueDrag will actually fire when you release the mouse *on the drop control* so we need to make sure we allow for that. This is handled by checking that the Mouse position (retrieved with the global Control.MousePosition property) is inside of the LabelDrop control rectangle. You must also be sure to convert MousePosition to a point relative to the Client Window with PointToClient as Control.MousePosition returns a *screen relative* position. So by checking that the mouse is *not* over the drop control and that the mouse button is now *up* we have effectively captured a MouseUp event for the LabelDrag control! :) Now, you could just do whatever processing you want to do here, but if you already have code you are using in the MouseUp event handler, this is not efficient. So just call your MouseUp event from here, passing it the necessary parameters and the MouseUp handler won't ever know the difference. Just a note though, as I call DoDragDrop from *within* the MouseDown event handler in my example, this code should *never* actually get a direct MouseUp event to fire. I just put that code in there to show that it is possible to do it. Hope that helps!
Elements can belong to more than one class, so you can do something like this: .DefaultBackColor { background-color: #123456; } .SomeOtherStyle { //other stuff here } .DefaultForeColor { color:#654321; } And then in the content portion somewhere: <div class="DefaultBackColor SomeOtherStyle DefaultForeColor">Your content</div> The weaknesses here are that it gets pretty wordy in the body and you're unlikely to be able to get it down to listing a color only once. But you might be able to do it only two or three times and you can group those colors together, perhaps in their own sheet. Now when you want to change the color scheme they're all together and the change is pretty simple. But, yeah, my biggest complain with CSS is the inability to define your own constants.
In my opinion, trying to parse HTML with anything other than an HTML parser is just asking for a world of pain. HTML is a *really* complex language (which is one of the major reasons that XHTML was created, which is much simpler than HTML). For example, this: <HTML / <HEAD / <TITLE / > / <P / > is a complete, 100% well-formed, 100% valid HTML document. (Well, it's missing the DOCTYPE declaration, but other than that ...) It is semantically equivalent to <html> <head> <title> &gt; </title> </head> <body> <p> &gt; </p> </body> </html> But it's nevertheless valid HTML that you're going to have to deal with. You *could*, of course, devise a regex to parse it, but, as others already suggested, using an actual HTML parser is just sooo much easier.
I don't have much PHP experience, although I'm using it at my current job. In general, I find that larger systems benefit from the readability and understandability that OO provides. But things like consistency (don't mix OO and non-OO) and your personal preferences (although only really on personal projects) are also important.
Can you be a bit more specific? For the example you give you need to use include in both ways. In case 1 you only include a file, in case 2 you need to include the class file (for instance user.class.php) to allow instantiation of the User class. It depends how the rest of the application is built, is it OO? Use OO.
There may be some confusion here about what "K&R C" is. The term refers to the language as documented in the first edition of "The C Programming Language." Roughly speaking: the input language of the Bell Labs C compiler from around 1969 to around 1988. Kernighan and Ritchie were involved in the ANSI standardization process. The "ANSI C" dialect superceded "K&R C" and subsequent editions of "The C Programming Language" adopt the ANSI conventions. "K&R C" is a "dead language," except to the extent that some compilers still accept legacy code.
First of all the [itertools module](http://docs.python.org/lib/module-itertools.html) is incredibly useful for all sorts of cases in which an iterator would be useful, but here is all you need to create an iterator in python: > yield Isn't that cool? Yield can be used to replace a normal **return** in a function. It returns the object just the same, but instead of destroying state and exiting, it saves state for when you want to execute the next iteration. Here is an example of it in action pulled directly from the [itertools function list](http://docs.python.org/lib/itertools-functions.html): def count(n=0): while True: yield n n += 1 As stated in the functions description (it's the **count()** function from the itertools module...) , it produces an iterator that returns consecutive integers starting with n. [Generator expressions](http://docs.python.org/ref/genexpr.html) are a whole other can of worms (awesome worms!). They may be used in place of a [List Comprehension](http://www.secnetix.de/olli/Python/list_comprehensions.hawk) to save memory (list comprehensions create a list in memory that is destroyed after use if not assigned to a variable, but generator expressions can create a Generator Object... which is a fancy way of saying Iterator). Here is an example of a generator expression definition: gen = (n for n in range(0,10)) This is very similar to our iterator definition above except the full range is predetermined to be between 0 and 10. One problem with this implementation of a count iterator compared to the function above, however, is that since our generator expression uses **range()** , it has to generate the list and keep it in memory while iterating.
First of all the [itertools module](http://docs.python.org/lib/module-itertools.html) is incredibly useful for all sorts of cases in which an iterator would be useful, but here is all you need to create an iterator in python: > yield Isn't that cool? Yield can be used to replace a normal **return** in a function. It returns the object just the same, but instead of destroying state and exiting, it saves state for when you want to execute the next iteration. Here is an example of it in action pulled directly from the [itertools function list](http://docs.python.org/lib/itertools-functions.html): def count(n=0): while True: yield n n += 1 As stated in the functions description (it's the **count()** function from the itertools module...) , it produces an iterator that returns consecutive integers starting with n. [Generator expressions](http://docs.python.org/ref/genexpr.html) are a whole other can of worms (awesome worms!). They may be used in place of a [List Comprehension](http://www.secnetix.de/olli/Python/list_comprehensions.hawk) to save memory (list comprehensions create a list in memory that is destroyed after use if not assigned to a variable, but generator expressions can create a Generator Object... which is a fancy way of saying Iterator). Here is an example of a generator expression definition: gen = (n for n in xrange(0,11)) This is very similar to our iterator definition above except the full range is predetermined to be between 0 and 10. I just found **xrange()** (suprised I hadn't seen it before...) and added it to the above example. **xrange()** is an iterable version of **range()** which has the advantage of not prebuilding the list. It would be very useful if you had a giant corpus of data to iterate over and only had so much memory to do it in.
You can force the keyboard focus to stay on the TextBox by handling the PreviewLostKeyBoardFocus event like this: <TextBox PreviewLostKeyboardFocus="TextBox_PreviewLostKeyboardFocus" /> private void TextBox_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { e.Handled = true; }
It obviously varies depending on languages and technologies. By the look of your example name space I am going to guess java, in which case <http://java.sun.com/docs/codeconv/> is a really good place to start. You might also want to look at something like maven's standard directory structure which will make all your projects look similar.
I can recommend Sphinx. Ryan Bates has a great [screencast][1] on using the Thinking Sphinx plugin to create a full-text search solution. [1]: http://railscasts.com/episodes/120-thinking-sphinx
Here's what I'd do : Put the data in a standard form (with no runat="server" attribute) and set the action of the form to post to the target off-site page. Before submitting I would submit the data to my server **using an XmlHttpRequest** and analyze the response. If the response means you should go ahead with the offsite POSTing then I (the JavaScript) would proceed with the post otherwise I would redirect to a page on my site
[Side by side comparison table of three maven plugins.][1] [1]: http://docs.codehaus.org/display/MAVENUSER/Eclipse+Integration
Where I work we use the following guidelines: - Each IDisposable class **must** have a finalizer - Whenever using an IDisposable object, it must be used inside a "using" block. The only exception is if the object is a member of another class, in which case the containing class must be IDisposable and must call the member's 'Dispose' method in its own implementation of 'Dispose'. This means 'Dispose' should never be called by the developer except for inside another 'Dispose' method, eliminating the bug described in the question. - The code in each Finalizer must begin with a warning/error log notifying us that the finalizer has been called. This way you have an extremely good chance of spotting such bugs as described above before releasing the code, plus it might be a hint for bugs occuring in your system. To make our lives easier, we also have a SafeDispose method in our infrastructure, which calls the the Dispose method of its argument within a try-catch block (with error logging), just in case (although Dispose methods are not supposed to throw exceptions). See also: [Chris Lyon][1]'s suggestions regarding IDisposable [1]: http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx
Where I work we use the following guidelines: - Each IDisposable class **must** have a finalizer - Whenever using an IDisposable object, it must be used inside a "using" block. The only exception is if the object is a member of another class, in which case the containing class must be IDisposable and must call the member's 'Dispose' method in its own implementation of 'Dispose'. This means 'Dispose' should never be called by the developer except for inside another 'Dispose' method, eliminating the bug described in the question. - The code in each Finalizer must begin with a warning/error log notifying us that the finalizer has been called. This way you have an extremely good chance of spotting such bugs as described above before releasing the code, plus it might be a hint for bugs occuring in your system. To make our lives easier, we also have a SafeDispose method in our infrastructure, which calls the the Dispose method of its argument within a try-catch block (with error logging), just in case (although Dispose methods are not supposed to throw exceptions). See also: [Chris Lyon][1]'s suggestions regarding IDisposable [1]: http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx Edit: @Quarrelsome: One thing you ought to do is call GC.SuppressFinalize inside 'Dispose', so that if the object was disposed, it wouldn't be "re-disposed". It is also usually advisable to hold a flag indicating whether the object has already been disposed or not. The follwoing pattern is usually pretty good: class MyDisposable: IDisposable { public void Dispose() { lock(this) { if (disposed) { return; } disposed = true; } GC.SuppressFinalize(this); // Do actual disposing here ... } private bool disposed = false; } Of course, locking is not always necessary, but if you're not sure if your class would be used in a multi-threaded environment or not, it is advisable to keep it.
I wound up just implementing the translation manually. The code's not too bad, but it did leave me wishing that they provided support for it directly. I could see such a method being useful in a lot of different circumstances. I guess that's why they added extension methods :)
I once was called upon to look at a mysql that had "stopped working". I discovered that the DB files were residing on a Network Appliance filer mounted with NFS2 and with a maximum file size of 2GB. And sure enough, the table that had stopped accepting transactions was exactly 2GB on disk. But with regards to the performance curve I'm told that it was working like a champ right up until it didn't work at all! This experience always serves for me as a nice reminder that there're always dimensions above and below the one you naturally suspect.
1. [Wikipedia Article](http://en.wikipedia.org/wiki/Inversion_of_control). To me, inversion of control is turning your sequentially written code and turning it into an delegation structure. Instead of your program explicitly controlling everything, your program sets up a class or library with certain functions to be called when certain things happen. 2. It solves code duplication. For example, in the old days you would manually write your own event loop, polling the system libraries for new events. Nowadays, most modern APIs you simply tell the system libraries what events you're interested in, and it will let you know when they happen. 3. Inversion of control is a practical way to reduce code duplication, and if you find yourself copying an entire method and only changing a small piece of the code, you can consider tackling it with inversion of control. Inversion of control is made easy in many languages through the concept of delegates, interfaces, or even raw function pointers. It is not appropriate to use in all cases, because the flow of a program can be harder to follow when written this way. It's a useful way to design methods when writing a library that will be reused, but it should be used sparingly in the core of your own program unless it really solves a code duplication problem.
You need to have Sharepoint 2007 service pack 1 -- or else there's no chance. (Sharepoint 2007 predates ajax 1.0 -- they built some support into service pack 1)
You need to have Sharepoint 2007 service pack 1 -- or else there's no chance. (Sharepoint 2007 predates ajax 1.0 -- they built some support into service pack 1) Next, from a trouble shooting point of view, test that the **exact** same code functions as expected when hosted in a regular asp.net page. (Literally copy and paste your code across into a fresh page, to rule out any typographical errors). Ruling sharepoint in or out of the problem area will help narrow down the solution space.
At work we use teraterm and realterm for checking serial data is correctly formatted. Also we have a hardware splitter with a switch so we can monitor traffic to our application via a cable back to another port. Windows allows you access to the serial port via CreateFile. That gives you a handle and from there you can configure access.
Some of the neat features are available in Visual Assist X, though not all of them. I've asked on their forums, but they haven't appeared as yet. VAX gets updated regularly on a rough 4 week period for bug fixes and a new feature every couple of months.
I think your second approach (e.g., tagging releases and doing experimental stuff in branches, considering the trunk stable) is the best approach. It should be clear that branches inherit all the bugs of a system at the point in time where it is branched: if fixes are applied to a trunk, you will have to go one by one to all branches if you maintain branches as a sort of release cycle terminator. If you have already had 20 releases and you discovered a bug that goes as far back as the first one, you'll have to reapply your fix 20 times. Branches are supposed to be the real sand boxes, although the trunk will have to play this role as well: tags will indicate whether the code is "gold" at that point in time, suitable for release.
How do you manage schema upgrades to a production database?
|database|administration|installation|
This seems to be an overlooked area that could really use some insight. What are your best practices for: - making an upgrade procedure - backing out in case of errors - syncing code and database changes - testing prior to deployment - mechanics of modifying the table etc...
|database|installation|administration|
The trunk should generally be your main development source. Otherwise you will spend a lot of time merging in new features. I've seen it done the other way and it usually leads to a lot of last minute integration headaches. We label our releases so we can quickly respond to production emergencies without distribing active development.
How to select an SQL database?