instruction
stringlengths
0
30k
I like [An O(ND) Difference Algorithm and Its Variations][1] by Eugene Myers. I believe it's the algorithm that was used in GNU diff. For a good background see [Wikipedia][2]. This is quite theoretical and you might wish to find source code, but I'm not aware of any in VB. [1]: http://www.xmailserver.org/diff2.pdf [2]: http://en.wikipedia.org/wiki/Diff
I don't know for sure if it's the best diff algorithms but you might want to check out those links that talks about SOCT4 and SOCT6 [http://www.loria.fr/~molli/pmwiki/uploads/Main/so6group03.pdf][1] [http://www.loria.fr/~molli/pmwiki/uploads/Main/diffalgo.pdf][2] [1]: http://www.loria.fr/~molli/pmwiki/uploads/Main/so6group03.pdf [2]: http://www.loria.fr/~molli/pmwiki/uploads/Main/diffalgo.pdf
I don't know for sure if it's the best diff algorithms but you might want to check out those links that talks about SOCT4 and SOCT6 [http://www.loria.fr/~molli/pmwiki/uploads/Main/so6group03.pdf][1] [http://www.loria.fr/~molli/pmwiki/uploads/Main/diffalgo.pdf][2] [http://dev.libresource.org/home/doc/so6-user-manual/concepts][3] [1]: http://www.loria.fr/~molli/pmwiki/uploads/Main/so6group03.pdf [2]: http://www.loria.fr/~molli/pmwiki/uploads/Main/diffalgo.pdf [3]: http://dev.libresource.org/home/doc/so6-user-manual/concepts
Exactly. The code that you need to achieve this is: UIApplication *app = [UIApplication sharedApplication]; [app openURL:[[NSURL alloc] initWithString: @"http://maps.google.com/maps?g=London"]]; since [as per the documentation][1], UIApplication is only available in the Application Delegate unless you call sharedApplication. [1]: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/clm/UIApplication/sharedApplication
Exactly. The code that you need to achieve this is: UIApplication *app = [UIApplication sharedApplication]; [app openURL:[[NSURL alloc] initWithString: @"http://maps.google.com/maps?g=London"]]; since [as per the documentation][1], UIApplication is only available in the Application Delegate unless you call sharedApplication. [1]: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/clm/UIApplication/sharedApplication
As travis suggests, you could simply change the parameter or class property (depending on what you are passing back) to a string, the parse it as his example. You may also want to take a look at [this article][1]. It suggests that direct conversion for DateTime JSON serialization uses something more like the ticks property. [1]: http://www.nikhilk.net/DateSyntaxForJSON2.aspx
[Microsoft KB Article 320687][1] has a detailed answer to this question. Basically, you override the WndProc method to return HTCAPTION to the WM_NCHITTEST message when the point being tested is in the client area of the form -- which is, in effect, telling Windows to treat the click exactly the same as if it had occured on the caption of the form. <pre> private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; protected override void WndProc(ref Message m) { switch(m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; break; } base.WndProc(ref m); } </pre> [1]: http://support.microsoft.com/kb/320687 "KB Article 320687"
I've just started using OSX. Free editors of note that I've discovered: - [Komodo][1] by ActiveState. No debugger or regex editor (although one comes with Python, i.e. redemo.py) in free version but perfectly usable. - [ERIC][2], written in PyQT. - Eclipse with [PyDev][3] is my preferred option for editing Python on all platforms. Nice clean GUI, decent debugger. Good syntax parsing etc. [1]: http://www.activestate.com/Products/komodo_ide/index.mhtml [2]: http://www.die-offenbachs.de/eric/index.html [3]: http://pydev.sourceforge.net/
For very simple Linux support if you like TextMate, try just gedit loaded with the right plugins. Easy to set up and really customizable, I use it for just about everything. There's also a lot of talk about emacs plugins if you're already using that normally. Gedit: [How to set up like TextMate][1] [1]: http://crepuscular-homunculus.blogspot.com/2007/10/gedit-for-ruby-and-everything-else-on.html
The following code assumes that the ProgressBarForm form has a ProgressBar control with **Dock** property set to **Fill** public partial class ProgressBarForm : Form { private bool mouseDown; private Point lastPos; public ProgressBarForm() { InitializeComponent(); } private void progressBar1_MouseMove(object sender, MouseEventArgs e) { if (mouseDown) { int xoffset = MousePosition.X - lastPos.X; int yoffset = MousePosition.Y - lastPos.Y; Left += xoffset; Top += yoffset; lastPos = MousePosition; } } private void progressBar1_MouseDown(object sender, MouseEventArgs e) { mouseDown = true; lastPos = MousePosition; } private void progressBar1_MouseUp(object sender, MouseEventArgs e) { mouseDown = false; } }
I believe starting with an un-normalized database and moving toward normalized as you progress is usually easiest to get started. To the question of how far to normalize, my philosophy is to normalize until is starts to hurt. That may sound a little flippant, but it generally is a good way to gauge how far to take it.
We converted a home-grown web framework to stripes in about a week. We're using it in production at this time and it's a great framework. The community is extremely helpful, and the framework doesn't get in your way. It can be extended in many places to change the behavior as you see fit. The url binding feature is awesome as well. We implemented a robust security framework using annotations and interceptors. We're using spring for dependency injection and stripes has excellent support for that. I'd definitely use the new 1.5 release if you're going to use it. I'm a huge fan of the framework. I came from a struts background and it's the exact framework I was looking for. The other developers on our team really enjoy using the stripes framework. I just bought the stripes beta book from the pragmatic programmer's site. It's a great resource on Stripes 1.5.
Jeff has a pretty good overview of his philosophy on his blog: [Maybe normalization isn't normal][1]. The main thing is: don't overdo normalization. But I think an even bigger point to take away is that it probably doesn't matter too much. Unless you're running the next Google, you probably won't notice much of a difference until your application grows. [1]: http://www.codinghorror.com/blog/archives/001152.html
Database normizational I feel is an art form. You don't want to over normalize your database because you will have too many tables and it will cause your queries of even simple objects take longer than they should. A good rule of thumb I follow is to normalize the same information repeated over and over again. For example if you are creating a contact management application it would make sense to have Address (Street, City, State, Zip, etc. . ) as its own table. However if you have only 2 types of contacts, Business or personal, do you need a contact type table if you know you are only going to have 2? For me no. I would start by first figuring out the datatypes you need. Use a modeling program to help like Visio. You don't want to start with a non-normalized database because you will eventually normalize. Start by putting objects in there logical groupings, as you see data repeated take that data into a new table. I would keep up with that process until you feel you have the database designed. Let testing tell you if you need to combine tables. A well written query can cover any over normalization.
You want to start designing a normalized database up to 3rd normal form. As you develop the business logic layer you may decide you have to denormalize a bit but _never, never_ go below the 3rd form. Always, keep 1rd and 2nd form compliant. You want to denormalize for simplicity of code, not for performance. Use indexes and stored procedures for that :) The reason not "normalize as you go" is that you would have to modify the code you already have written most every time you modify the database design. There are a couple of good articles: http://www.agiledata.org/essays/dataNormalization.html http://codebetter.com/blogs/raymond.lewallen/archive/2006/01/04/136196.aspx
Another good Subversion book is [Pragmatic Version Control with Subversion][1], a Pragmatic Programmer book that goes out of its way to make key concepts of version control (from checkin & checkout to branching & merging) clear. [1]: http://www.pragprog.com/titles/svn2/pragmatic-version-control-using-subversion
How do you get the last record generated in a recursive CTE?
|sql|common-table-expression|recursion|sql-server|
In the code below I am using a recursive CTE(Common Table Expression) in SQL Server 2005 to try and find the top level parent of a basic hierarchical structure. The rule of this hierarchy is that every CustID has a ParentID and if the CustID has no parent then the ParentID = CustID and it is the highest level. DECLARE @LookupID int --Our test value SET @LookupID = 1 WITH cteLevelOne (ParentID, CustID) AS ( SELECT a.ParentID, a.CustID FROM tblCustomer AS a WHERE a.CustID = @LookupID UNION ALL SELECT a.ParentID, a.CustID FROM tblCustomer AS a INNER JOIN cteLevelOne AS c ON a.CustID = c.ParentID WHERE c.CustID <> a.CustomerID ) So if tblCustomer looks like this: <table> <tr> <th>ParentID</th> <th>CustID</th> </tr> <tr> <td> 5 </td> <td> 5 </td> </tr> <tr> <td> 1 </td> <td> 8 </td> </tr> <tr> <td> 5 </td> <td> 4 </td> </tr> <tr> <td> 4 </td> <td> 1 </td> </tr> </table> </br> The result I get from the code above is: <table> <tr> <th>ParentID</th> <th>CustID</th> </tr> <tr> <td> 4 </td> <td> 1 </td> </tr> <tr> <td> 5 </td> <td> 4 </td> </tr> <tr> <td> 5 </td> <td> 5 </td> </tr> </table> </br> What I want is just the last row of that result: <table border="1"> <tr> <th>ParentID</th> <th>CustID</th> </tr> <tr> <td> 5 </td> <td> 5 </td> </tr> </table> </br> How do I just return the last record generated in the CTE (which would be highest level CustID)? Also note that there are multiple unrelated CustID hierarchies in this table so I can't just do a SELECT * FROM tblCustomer WHERE ParentID = CustID
|sql|sql-server|recursion|common-table-expression|
In the code below I am using a recursive CTE(Common Table Expression) in SQL Server 2005 to try and find the top level parent of a basic hierarchical structure. The rule of this hierarchy is that every CustID has a ParentID and if the CustID has no parent then the ParentID = CustID and it is the highest level. DECLARE @LookupID int --Our test value SET @LookupID = 1 WITH cteLevelOne (ParentID, CustID) AS ( SELECT a.ParentID, a.CustID FROM tblCustomer AS a WHERE a.CustID = @LookupID UNION ALL SELECT a.ParentID, a.CustID FROM tblCustomer AS a INNER JOIN cteLevelOne AS c ON a.CustID = c.ParentID WHERE c.CustID <> a.CustomerID ) So if tblCustomer looks like this: ParentID CustID 5 5 1 8 5 4 4 1 The result I get from the code above is: ParentID CustID 4 1 5 4 5 5 What I want is just the last row of that result: ParentID CustID 5 5 How do I just return the last record generated in the CTE (which would be highest level CustID)? Also note that there are multiple unrelated CustID hierarchies in this table so I can't just do a SELECT * FROM tblCustomer WHERE ParentID = CustID. I can't order by ParentID or CustID because the ID number is not related to where it is in the hierarchy.
Well I've used the c# version on codeproject and its really good for what I wanted... http://www.codeproject.com/KB/recipes/diffengine.aspx You can probably get this translated into VB.net via an [online converter][1] if you can't do it yourself... [1]: http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
Well I've used the c# version on codeproject and its really good for what I wanted... <http://www.codeproject.com/KB/recipes/diffengine.aspx> You can probably get this translated into VB.net via an [online converter][1] if you can't do it yourself... [1]: http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
I think that it depends on what purpose the Extension methods serve. - Extension methods that relate to specific business needs of a project (whether they are connected to basic data types or custom objects) should not be included in a library that would be distributed across multiple projects. - Extension methods that relate to basic data types (int, string, etc) or generics that have a wider application could be packaged and distributed across projects. Take care not to globally include Extension methods that have little application, as they just clog up intellisense and can lead to confusion and/or misuse.
Itzik Ben-Gan in 'DATETIME Calculations, Part 1' (SQL Server Magazine, February 2007) shows three methods of performing such a conversion (**slowest to fastest**; the difference between second and third method is small): SELECT CAST(CONVERT(char(8), GETDATE(), 112) AS datetime) SELECT DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0) SELECT CAST(CAST(GETDATE() - 0.50000004 AS int) AS datetime) Your technique (casting to *float*) is suggested by a reader in the April issue of the magazine. According to him, it has performance comparable to that of second technique presented above.
I've been including my extension methods in with my Core libraries in the Utils class because people who are working with my framework are likely to find the methods useful, but for mass deployment where the end developer might have a choice of extension method libraries, I would advise putting all of your extensions into their own namespace, even their own project file, so that people can choose to add a reference or a using statement or simply where required, like so: Core.Extensions.Base64Encode(str); My Utils class is my bestest friend in the whole world, it was before extension methods came along and they have only helped to strengthen our relationship. The biggest rule I would go by is to give people choice over what extension framework they are using where possible.
Are you looking for an add-in like this to quickly navigate to a source file in your project: ![SonicFileFinder 1.8.5][1] You can try free Visual Studio 2005/2008 add-in [SonicFileFinder][2]. [1]: http://jens-schaller.de/files/images/SonicFileFinder/sonicFileFinderDialog.png [2]: http://jens-schaller.de/sonictools/sonicfilefinder/index.htm
Could you not apply the condition to the following rules, but with negation, as in (with some variation thereof, I'm not too good at remembering .htaccess rules, so the flags might be wrong): RewriteCond $1 !^(static|otherDir).*$ [NC] RewriteRule ^$ app/webroot/ [L] RewriteCond $1 !^(static|otherDir).*$ [NC] RewriteRule ^$ app/webroot/$1 [L]
Some good places to start are: * [Haskell Learning Trail](http://faculty.uaeu.ac.ae/brucem/haskell/exercise/chitchat.html) * [The Gentle Introduction To Haskell](http://www.cs.auckland.ac.nz/references/haskell/haskell-intro-html/intro.html) * [Problem Solving in Haskell](http://www.cs.kent.ac.uk/people/staff/sjt/Haskell_craft/probSolving.html) Other resources:<br> * Interesting blog entry on a [Study plan for Haskell](http://www.alpheccar.org/en/posts/show/67) * [HaskellWiki](http://www.haskell.org/) * [Generic Haskell User Guide (PDF)](http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=F620BE1F358D8EC82AE93B19C543CE3B?doi=10.1.1.13.5249&rep=rep1&type=pdf)
Does this happen when you run the javac command from the command line? You might want to try the [fork][1] attribute. [1]: http://ant.apache.org/manual/CoreTasks/javac.html
Hmm.. I don't think there is a way from within Visual Studio. For maximizing real estate and working on simultaneous files, I use that method plus viewing the files on Full Screen mode. Do you multiple monitors?
A MemoryStream is basically a byte array with a stream interface, e.g. sequential reading/writing and the concept of a current position.
You could stretch visual studio across both monitors then put two code windows next to each other. Basically, you are manually maximizing VS across both screens. Keith
It is not recommended that you rely on sessions for authentication without taking additional actions. Read more on [http://shiflett.org/articles/the-truth-about-sessions][1]. [1]: http://shiflett.org/articles/the-truth-about-sessions
Try adding some variation of these attributes to the javac line[1]: memoryinitialsize="256M" memorymaximumsize="1024M" You can also try fork="true", not sure if this allows you to set values for stack and heap (aka -Xm1024), but it may help (if it would work from the command line, but not in ant). Edit: References: [1] http://ant.apache.org/manual/CoreTasks/javac.html -- Would seem to suggest that the parameters avove require that you also set fork="true".
Try adding some variation of these attributes to the [ant javac task] line: memoryinitialsize="256M" memorymaximumsize="1024M" You can also try fork="true", not sure if this allows you to set values for stack and heap (aka -Xm1024), but it may help (if it would work from the command line, but not in ant). [Edit]: Added link -- the [ant javac task] page would seem to suggest that the parameters above require that you also set fork="true". [ant javac task]: http://ant.apache.org/manual/CoreTasks/javac.html
Creating your own table with CommandArgument buttons in ASP.NET MVC
|asp.net-mvc|
I'm trying to implement something like this: <div> <table> <thead> <tr> <td>Port name</td> <td>Current port version</td> <td>New port version</td> <td>Update</td> </tr> </thead> <% foreach (var ip in Ports) { %> <tr> <td><%= ip.PortName %></td> <td><%= ip.CurrentVersion %></td> <td><%= ip.NewVersion %></td> <td><asp:Button ID="btnUpdate" runat="server" Text="Update" CommandArgument="<% ip.PortName %>" /></td> </tr> <% } %> </table> </div> The button's CommandArgument property is where my code complains about not being able to resolve symbol 'ip'. Is there any way to do what I'm trying to do?
A multi-agent system is a concept borrowed from AI. It's almost like a virtual world where you have agents that are able to observe, communicate, and react. To give an example, you might have a memory allocation agent that you have to ask for memory and it decides whether or not to give it to you. Or you might have an agent that monitors a web server and restarts it if it hangs. The main goal behind multiagent systems is to have a more Smalltalk-like communication system between different parts of the system in order to get everything to work together, as opposed to more top-down directives that come from a central program.
Well, you can actually do local image processing in Silverlight 2... But there are no built in classes to help you. But you can load any image into a byte array, and start manipulating it, or implement your own image encoder. Joe Stegman got lots of great information about "editable images" in Silverlight over at [http://blogs.msdn.com/jstegman/][1]. He does things like applying filters to images, generating mandlebrots and more. This blog discuss a JPEG Silverilght Encoder (FJCore) you can use to resize and recompress photos client size: [http://fluxcapacity.net/2008/07/14/fjcore-to-the-rescue/][2] Another tool is "Fluxify" which lets you resize and upload photos using Silverilght 2. Can be found over at [http://fluxtools.net/][3] So yes, client side image processing can definetly be done in Silverilght 2. Happy hacking! [1]: http://blogs.msdn.com/jstegman/ [2]: http://fluxcapacity.net/2008/07/14/fjcore-to-the-rescue/ [3]: http://fluxtools.net/
Decision making in distributed applications
|distributed|
With a distributed application, where you have lots of clients and one main server, should you: - Make the clients dumb and the server smart: clients are fast and non-invasive. Business rules are needed in only 1 place - Make the clients smart and the server dumb: take as much load as possible off of the server Additional info: - Clients collect tons of data about the computer they are on. The server must analyze all of this info to determine the health of these computers - The owners of the client computers are temperamental and will shut down the clients if the client starts to consume too many resources (thus negating the purpose of the distributed app in helping diagnose problems)
Change Active Sound Card on the Fly
|windows|hardware|audio|
I currently have speakers set up both in my office and in my living room, connected to my PC via two sound cards, and would like to switch the set of speakers I'm outputting to on the fly. Anyone know an application or a windows API call that I can use to change the default sound output device? It is currently a bit of a pain to traverse the existing control panel system.
You should do as much client-side processing as possible. This will enable your application to scale better than doing processing server-side. To solve your temperamental user problem, you could look into making your client processes run at a very low priority so there's no noticeable decrease in performance on the part of the user.
I suspect it's (like you say) some custom javascript code. The original asp.net control works fine... you are going to have to check the code
Are you handling the textchanged event for the textbox? That would mean ASP.Net sets the textbox to cause a postback (submit the page) for anything the _might_ cause the textbox to lose focus, including the enter key.
Further to @Chris Karcher's answer - you can also automatically format the *whole document* by hitting Ctrl+K, Ctrl+D. These formatting features work on a variety of file formats - it works wonders on ugly HTML.
GETDATE() returns current date **and time**. If *last year* starts in midnight of current day last year (like in original example) you should use something like: DECLARE @start datetime SET @start = dbo.getdatewithouttime(DATEADD(year, -1, GETDATE())) -- cut time (hours, minutes, ect.) -- getdatewithouttime() function doesn't exist in MS SQL -- you have to write one SELECT column1, column2, ..., columnN FROM table WHERE date >= @start
I believe just tabular content. For example, if you printed out a database table or spreadsheet-like data to HTML.
When using a dynamically typed language, I occasionally use Apps Hungarian. For statically typed languages I don't. See my explanation [in the other thread](http://stackoverflow.com/questions/26086/how-do-you-make-wrong-code-look-wrong-what-patterns-do-you-use-to-avoid-semanti#26174).
![Real programmers set the universal constants at the start such that the universe evolves to contain the disk with the data they want.][1] [1]: http://imgs.xkcd.com/comics/real_programmers.png http://xkcd.com/378/
I will usually opt for tables to display form-type information (First Name, Last Name, Address, etc.) where lining labels and fields across multiple rows is important. DIVs I use for layout. Of course the table is wrapped in a DIV :)
Is the fact that ASP.net MVC is only in 'Preview 5' be a cause for concern when looking into it? I know that StackOverflow was created using it, but is there a chance that Microsoft could implement significant changes to the framework before it is officially out of beta/alpha/preview release?
I created a sample page with a TextBox and a Button and it worked fine for me: <asp:TextBox runat="server" ID="textbox1" TextMode="MultiLine" /> <br /> <br /> <asp:Button runat="server" ID="button1" Text="Button 1" onclick="button1_Click" /> So it most likely depends on either some other property you have set, or some other control on the form. Edit: TextChanged event is only triggered when the TextBox loses focus, so that can't be the issue.
When the data I am presenting is, indeed, tabular. I find it ridiculous that some web designers used divs on tabular data on some sites. One other use I would have for it would be forms, particularly label : textbox pairs. This could technically be done in div boxes, but it's much, much easier to do this in tables, and one can argue that label:textbox pairs are in fact tabular in nature.
You've already read about TDD; reading more isn't going to excite you. Instead, you need a genuine personal success story. Here's how. Grab some code from a core module, code that doesn't depend on external systems or too many other subroutines. Doesn't matter how complex or simple the routine is. Then start writing unit tests against it. (I'm assuming you have an xUnit or similar for your language.) Be really obnoxious with the tests -- test every boundary case, test max-int and min-int, test null's, test strings and lists with millions of elements, test strings with Korean and control characters and right-to-left Arabic and quotes and backslashes and periods and other things that tend to break things if not escaped. What you'll find is.... bugs! At first you might think these bugs aren't important -- you haven't run into these problems yet, your code probably would never do this, etc. etc.. But my experience is if you keep pushing forward you'll be amazed at the number of little problems. Eventually it becomes hard to believe that <i>none</i> of these bugs will <i>ever</i> cause a problem. Plus you get a great feeling of accomplishment with something is done really, really well. We know code is never perfect and rarely free of bugs, so it's nice when we've exhausted so many tests that we really do feel confident. Confidence is a nice feeling. Finally, I think the last event that will trigger the love will happen weeks or months later. Maybe you're fixing a bug or adding a feature or refactoring some code, and something you do will break a unit test. "Huh?" you'll say, not understanding why the new change was even relevant to the broken test. Then you'll find it, and find enlightenment. Because you <i>really didn't know</i> that you were breaking code, and the tests saved you. Hallelujah!
One word, practice! There is some overhead with doing TDD and the way to overcome it is to practice and make sure you are using tools to help the process. You need to learn the tools like the back of your hand. Once you learn the tools to go along with the process you are learning, then it will click and you will get fluent with writing tests first to flush the code out. Then you will be "test infected". I [answered][1] a question similar to this a while back. You may want to check it out also. I mention some tools and explain learning TDD. Out of these tools, Resharper and picking a good mocking framework are critical for doing TDD. I can't stress learning these tools to go along with the testing framework you are using enough. [1]: http://stackoverflow.com/questions/24965/beginning-tdd-challenges-solutions-recommendations#25203
My list includes: Herding Code, Deep Fried Bytes, Polymorohic Podcast, Pixel8, .Net Rocks, Hanselminutes, Powerscripting podcast. Full list: http://rtipton.wordpress.com/podcasts/
Rendering a PDF is hard, complex problem. However generating them, is not. Simply make up some entities, and generate. It's about same problem domain as generating HTML for webpage vs. displaying (rendering) it.
Learn about TDD to start, and then begin integrating it into your workflow. If you use the methodologies enough, you'll find that they become second nature and you'll start framing all of your development tasks within that framework.
Learn about TDD to start, and then begin integrating it into your workflow. If you use the methodologies enough, you'll find that they become second nature and you'll start framing all of your development tasks within that framework. Also, start using the J-Unit (or X-Unit) framework for your language of choice.
Further to Kyle's answer, I would strongly recommend *against* trying to use the Posix subsystem in Windows. It's implemented to an absolute bare minimum level such that Microsoft can claim "Posix support" on a feature sheet tick box. Perhaps somebody out there actually uses it, but I've never encountered it in real life. One can certainly write cross-platform C code, you just have to be aware of the differences between platforms, and test, test, test. Unit tests and a CI (continuous integration) solution will go a long way toward making sure your program works across all your target platforms. A good approach is to isolate the system-dependent stuff in one or a few modules at most. Provide a system-independent interface from that module. Then build everything else on top of that module, so it doesn't depend on the system you're compiling for.
I maintained for a number of years an ANSI C networking library that was ported to close to 30 different OS's and compilers. The library didn't have any GUI components, which made it easier. We ended up abstracting out into dedicated source files any routine that was not consistent across platforms, and used #defines where appropriate in those source files. This kept the code that was adjusted per platform isolated away from the main business logic of the library. We also made extensive use of typedefs and our own dedicated types so that we could easily change them per platform if needed. This made the port to 64-bit platforms fairly easy. If you are looking to have GUI components, I would suggest looking at GUI toolkits such as WxWindows or Qt (which are both C++ libraries). Steve
Try to write as much as you can with POSIX. Mac and Linux support POSIX natively and Windows has a system that can run it (as far as I know - I've never actually used it). If your app is graphical, both Mac and Linux support X11 libraries (Linux natively, Mac through X11.app) and there are numerous ways of getting X11 apps to run on Windows. However, if you're looking for true multi-platform deployment, you should probably switch to a language like Java or Python that's capable of running the same program on multiple systems with little or no change.
Try to write as much as you can with POSIX. Mac and Linux support POSIX natively and Windows has a system that can run it (as far as I know - I've never actually used it). If your app is graphical, both Mac and Linux support X11 libraries (Linux natively, Mac through X11.app) and there are numerous ways of getting X11 apps to run on Windows. However, if you're looking for true multi-platform deployment, you should probably switch to a language like Java or Python that's capable of running the same program on multiple systems with little or no change. Edit: I just downloaded the application and looked at the files. It does appear to have binaries for all 3 platforms in one directory. If your concern is in how to write apps that can be moved from machine to machine without losing settings, you should probably write all your configuration to a file in the same directory as the executable and not touch the Windows registry or create any dot directories in the home folder of the user that's running the program on Linux or Mac. And as far as creating a cross-distribution Linux binary, 32-bit POSIX/X11 would probably be the safest bet. I'm not sure what JungleDisk uses as I'm currently on a Mac.
I use [UnitTest++][1]. While the [example tutorial][2] is for Visual Studio 2005, the concepts are similar (try setting one up for VC6...). [1]: http://unittest-cpp.sourceforge.net/ [2]: http://unittest-cpp.sourceforge.net/money_tutorial/
Actionscript 3 - Fastest way to parse yyyy-mm-dd hh:mm:ss to a Date object?
|apache-flex|actionscript-3|
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss] into a Date object. Here are the 3 ways I have tried doing it and the times it takes each method to parse 50,000 date time strings. Does anyone know any faster ways of doing this or tips to speed up the methods? castMethod1 takes 3673 ms <br> castMethod2 takes 3812 ms <br> castMethod3 takes 3931 ms private function castMethod1(dateString:String):Date { if ( dateString == null ) { return null; } var year:int = int(dateString.substr(0,4)); var month:int = int(dateString.substr(5,2))-1; var day:int = int(dateString.substr(8,2)); if ( year == 0 && month == 0 && day == 0 ) { return null; } if ( dateString.length == 10 ) { return new Date(year, month, day); } var hour:int = int(dateString.substr(11,2)); var minute:int = int(dateString.substr(14,2)); var second:int = int(dateString.substr(17,2)); return new Date(year, month, day, hour, minute, second); } - private function castMethod2(dateString:String):Date { if ( dateString == null ) { return null; } if ( dateString.indexOf("0000-00-00") != -1 ) { return null; } dateString = dateString.split("-").join("/"); return new Date(Date.parse( dateString )); } - private function castMethod3(dateString:String):Date { if ( dateString == null ) { return null; } var mainParts:Array = dateString.split(" "); var dateParts:Array = mainParts[0].split("-"); if ( Number(dateParts[0])+Number(dateParts[1])+Number(dateParts[2]) == 0 ) { return null; } return new Date( Date.parse( dateParts.join("/")+(mainParts[1]?" "+mainParts[1]:" ") ) ); }
The way I have done this is to create a command script file and pass this on the command line via the /b command to psftp.exe. I have also tried this in Perl and have yet to find a neater way of doing it. I shall be watching this question incase anyone knows another way.
The way I have done this is to create a command script file and pass this on the command line via the /b command to psftp.exe. I have also tried this in Perl and have yet to find a neater way of doing it. There is an issue with this method, in that you already have to have accepted the RSA finger-print. If not, then the script will either wait for user input to accept it or will skip over it if you are running in full batch mode, with a failure. Also, if the server changes so that it's RSA finger-print changes (e.g. a cluster) then you need to re-accept the finger-print again. Not an ideal method, but the only one I know. I shall be watching this question incase anyone knows another way.
Usually whenever you're not using the table to provide a layout. Tables -> data Divs -> layout (mainly)
If you would like to have semantically correct HTML, then you should use tables only for tabular data. Otherwise you use tables for everything you want, but there probably is a way to do the same thing using `div`s and CSS.
Tables were designed for tabular content, not for layout. So, don't ever feel bad if you use them to display data.
1) For displaying tabular data. A calendar is one example of tabular data that isn't always obvious at first. 2) I work for a medical billing company, and nearly all of the layout for our internal work is done using CSS. However, from time to time we get paper forms from insurance companies that our billers have to use, and a program will convert them to an html format that they can fill out and print via the intranet. To make sure the forms are accepted they need to match the original paper version very closely. For these it's just simple to fall back to tables.
I can also vouch for Mercurial. Simple to use and powerful to boot!
Well, I think something is missing here. User wants to get data from the last year and not from the last 365 days. There is a huge diference. In my opinion, data from the last year is every data from 2007 (if I am in 2008 now). So the right answer would be: SELECT ... FROM ... WHERE YEAR(DATE) = YEAR(GETDATE) - 1 Then, if you want to restrict this query, you can add some other filter, but always searching in the last year SELECT ... FROM ... WHERE YEAR(DATE) = YEAR(GETDATE) - 1 AND DATE > '05/05/2007'
Agree with Thomas -- the general rule of thumb is if it makes sense on a spreedsheet, you can use a table. Otherwise not. Just don't use tables as your layout for the page, that's the main problem people have with them.
I've used [bazaar](http://bazaar-vcs.org/) for a little while now and love it. Trivial branching and merging back in give great confidence in using branches as they should be used. (I know that central vcs tools should allow this, but the common ones including subversion don't allow this easily). bzr supports quite a few different [workflows](http://bazaar-vcs.org/Workflows) from solo, through working as a centralised repository to fully distributed. With each branch (for a developer or a feature) able to be merged independently, code reviews can be done on a per branch basis. bzr also has a great plugin ([bzr-svn](http://bazaar-vcs.org/BzrForeignBranches/Subversion)) allowing you to work with a subversion repository. You can make a copy of the svn repo (which initially takes a while as it fetches the entire history for your local repo). You can then make branches for different features. If you want to do a quick fix to the trunk while half way through your feature, you can make an extra branch, work in that, and then merge back to trunk, leaving your half done feature untouched and outside of trunk. Wonderful. Working against subversion has been my main use so far. Note I've only used it on Linux, and mostly from the command line, though it is meant to work well on other platforms, has GUIs such as [TortoiseBZR](http://bazaar-vcs.org/TortoiseBzr) and a lot of work is being done on integration with [IDEs](http://bazaar-vcs.org/IDEIntegration) and the like.
@Hissohathair I suggest 1 change to @Hissohathair's answer. 6). ./bin/httpd -d <server path> (although it can be overridden in the config file) In apacheclt there is a variable for HTTPD where you could override to use it.
@GrizzlyGuru A wise man once told me "normalize till it hurts, denormalize till it works". It hasn't failed me yet :) I disagree about starting with it in un-normalized form however, in my experience its' been easier to adapt your application to deal with a less normalized database than a more-normalized one. It could also lead to situations where its' working "well enough" so you never get around to normalizing it (until its' too late!)
There is actually no unmanaged way to do that form of animation to the tray in native winforms, however you can P/Invoke shell32.dll to do it: Some good info here (In the comments not the post): http://blogs.msdn.com/jfoscoding/archive/2005/10/20/483300.aspx And here it is in C++: http://www.codeproject.com/KB/shell/minimizetotray.aspx You can use that to figure out what stuff to Pinvoke for your C# version. Also, drop the attitude and you might find people more willing to assist you.
Often if you normalize as far as your other software will let you, you'll be done. For example, when using Object-Relational mapping technology, you'll have a rich set of semantics for various many-to-one and many-to-many relationships. Under the hood that'll provide join tables with effectively 2 primary keys. While relatively rare, true normalization often gives you relations with 3 or more primary keys. In cases like this, I prefer to stick with the O/R and roll my own code to avoid the various DB anomalies.
Are mocks better than stubs?
|unit-testing|mocking|
A while ago I read the [Mocks Aren't Stubs][1] article by Martin Fowler and I must admit I'm a bit scared of external dependencies with regards to added complexity so I would like to ask: What is the best method to use when unit testing? Is it better to always use a mock framework to automatically mock the dependencies of the method being tested, or would you prefer to use simpler mechanisms like for instance test stubs? [1]: http://www.martinfowler.com/articles/mocksArentStubs.html
I concur with Jason's assessment of the initial solution I proposed, it can definitely be improved. My solution represents an older school javascript mentality (read, pre the emergence of ajax and json). There are always better ways to solve a problem, which one of the reasons why stackoverflow is so cool. Collectively we are better at the craft of programming than anyone of us on our own. Based on Jason's ideas I'd revise my initial code, and revise some of what Jason suggested. Implement a C# class with two properties, the img resource "id" and a property that contains the WebResourceUrl. Then, where I differ some from Jason is that rather than using a Dictionary<string, string> I'd propose using a List<MyImageResourceClass>, which you can then in turn serialize to JSON (using [DataContractJsonSerializer][1]), and emit the JSON as the dynamic script, rather than manually generating the javascript using a string buider. Why a List? I think you may find that dictionaries when serialized to json, at least using the DataContractJsonSerializer (fyi available with the 3.5 framework only, with the 2.0 or 3.0 framework you'd need to bolt on aspnet ajax and use is json serializer), are a little more cumbersome to work with than how a list would serialize. Although that is subjective. There are implications too with your client side code. Now on the client side you'll have an array of the json serialized MyImageResourceClass instances. You'd need to iterate through this array creating your "img" tags as you go. Hopefully these ideas and suggestions can help get you going! And no doubt there are other solutions. I'm interested to see what comes of this. [1]: http://msdn.microsoft.com/en-us/library/bb412170.aspx
@hoyhoy If a designer can make this work in html, then he can have this design. If he is a true master of web design, he will realize that this is a limitation of the media, as video is not possible in magazine ads. If he would like to simulate weight by giving the 2 columns equal importance, than change the borders, so that they appear to be of the same weight, and make the colors of the borders contrast to the font color of the columns. But as for making the physical elements the same height, you can only do that with a table construct, or setting the heights, at this point in time. To simulate them appearing the same size, they don't have to be the same size.
Seeking code highlighter recommendation for WordPress
|php|wordpress|codehighlighter|geshi|
Can anybody recommend a reliable and decently documented code highlighter for WordPress 2.6.1. I have tried Code Snippet by Roman Roan and Developer Formatter by Gilberto Saraiva. But they don't seem to work as described in the documentation and are mangling the code snippets instead of prettifying them.
Desktop search utility for pdf,chm and djvu files
|desktop-search|
I want to write a tool that helps me search pdf/chm/djvu files in linux. Any pointers on how to go about it? The major problem is reading/importing data from all these files. Can this be done with C and shell scripting?
I use [WP-Syntax][1] and it's worked very well for me. It's supported every language I've thrown at it so far, and the colors can be customized for a particular theme (though the defaults look just fine too) [1]: http://wordpress.org/extend/plugins/wp-syntax/
Your simplest answer lies in the next version of css (3), which currently no browser supports. For now you are relegated to calculating heights in javascript and setting them on the left side. I think you need to assess the need for this first, as it seems unneccessary. What is the need to have them align? If you speak to a usability expert (**not a designer an expert of usability**), I think they will agree that there is no benefit to doing so, and to do so is costly. If the navigation is so important to be positioned in such a way, run it along the top. you could also do a visual trick by moving the borders to the container and the bigger inner, and make it appear to be the same size.