instruction
stringlengths
0
30k
I'm looking for a .Net library that will accept an image or filename and an aspect ratio, and crop the image to that aspect ratio. That's the easy part: I could do it myself. But I also want it to show a little intelligence in choosing exactly what content gets cropped, even if it's just picking which edge to slice. This is for a personal project, and the pain isn't high enough to justify spending any money on it, but if you can recommend a for-pay tool go ahead. Maybe someone else will find the suggestion useful.
WPF DatePicker: Whats the best?
|wpf|
I need a Datepicker for a WPF application. What is considered to be the best one? Thank you
WPF DatePicker: What is the best?
He may be correct for the specific use case he is thinking of. A stored procedure will probably execute faster for some complex set of SQL, that can be arbitrarily tuned. However, something you get from things like hibernate is caching. This may prove much faster for the lifetime of your actual application.
Multimap in Scala
|generics|scala|
The term slug comes from the newspaper/publishing business. It's a short title that's used to identify a story in progress. People interested in URL semantics started using a short, abbreviated title in their URLs. It also pays off in SEO land, as keywords in URLs add importance to a page. Ironically, lots of websites have started place a **full** serialized-with-hyphens version of the titles in their URLs for strictly SEO purposes, which means the term slug no longer quite applies. This also rankles semantic purists, as many implementations just tack this serialized version of the title at the end of their URLs.
If I understand correctly, you want a heuristic to estimate the number of comments in an HTML page which is known to be a blog post, yes? Very often, a specific blog will have some features which make it easy to work out. If you look at mine over at [http://kstruct.com/][1] you'll see that all the pages with comments say 'X Responses', so if you were able to do some work on a per blog basis, it's probably not really difficult. If you needed something generic, I guess there are a few common features that comments have that you might be able to detect. For one, any links in them are quite likely to have rel="nofollow" attributes, so seeing that within a block might imply that it's a comment. The main interesting thing to look for would be changes in the structure of posts for m the same site. For example, there's also a very good chance that each comment will have its own anchor so people can link directly to it, so you could look at the differing numbers of <a name="XXX"> tags in a given page on the same site to get an idea of the relative numbers of comments. As Michael Stum pointed out, if the pages have a Comment-RSS feed, your life is made a lot easier because you can get the comment data in a structured format. All in all, though, I think it's going to be quite a challenging problem to solve in general. [1]: http://kstruct.com/
To elaborate on Accordion Guy's response: Notice that `Proc.new` creates a proc out by being passed a block. I believe that `lambda {...}` is parsed as a sort of literal, rather than a method call which passes a block. `return`ing from inside a block attached to a method call will return from the method, not the block, and the `Proc.new` case is an example of this at play. (This is 1.8. I don't know how this translates to 1.9.)
I sure as hell can't. Small errors explode into pages and pages of unreadable junk. Usually early in the morning, before coffee. :( My only advice is to take a deep breath, start at the top and try and parse the important pieces of information. (I know, easier said than done, right?).
In the embedded world, the "modulus" operations you need to do are often the ones that break down nicely into bit operations that you can do with '&' and '|' and sometimes '>>'.
I want to look into emacs further, but I just can't use it for long stretches of time; it hurts my hands. Am I doing something horribly wrong?
Is there an alternative to using % (modulus) in C/C++?
|c|c++|modulo|
I read somewhere once that the modulus operator is inefficient on small embedded devices such as 8 bit micros without integer division operator. Perhaps someone can confirm this but I thought the difference is 5-10 time slower than with an integer division operation.<p> Is there another way to do this other than keeping a counter variable and manually overflowing to 0 at the mod point?<p> <pre><code> const int FIZZ = 6; for(int x = 0; x < MAX_CONT; x++) { if(!(x % FIZZ)) print("Fizz\n"); // slow on some systems } </code></pre> vs: The way I am currently doing it: <pre><code> const int FIZZ = 6; int fizz_count = 1; for(int x = 1; x < MAX_CONT; x++) { if(fizz_count >= FIZZ) { print("Fizz\n"); fizz_count = 0; } } </code></pre>
How to make the process of debugging an APS.NET application less time consuming?
|asp.net|debugging|
I'm comparing it Java where you can start your application server in debug mode, then attach your IDE to the server. And you can change your code "on the fly" without restarting the serer. As long as your changes don't affect any method signatures or fields you can just hit recompile for a class and the application server (servlet container) will reload the class. I suppose this is impossible in ASP.NET since all classes are packed into assemblies and you cannot unload/reload assemblies, can you ? So when you have an .aspx page and an assembly deployed to GAC and your codebehind changes you have to redeploy the assembly and reset IIS. I'm talking about Sharepoint applications in particular and I'm not sure whether you have to do iisreset for private assemblies but I guess you have too. So the best way to debug aspx pages with code behind I guess would be to get rid of the codebehind for the time of active debugging and move into the page, then when it is more or less working move it back to codebehind. ( This would be applicable only for application pages in Sharepoint, site pages don't allow inline code ) How do you approach debugging of your ASP.NET applications to make it less time consuming?
How to make the process of debugging an ASP.NET Sharepoint applications less time consuming?
|asp.net|debugging|sharepoint|
I'm comparing it Java where you can start your application server in debug mode, then attach your IDE to the server. And you can change your code "on the fly" without restarting the server. As long as your changes don't affect any method signatures or fields you can just hit recompile for a class and the application server (servlet container) will reload the class. I suppose this is impossible in ASP.NET since all classes are packed into assemblies and you cannot unload/reload assemblies, can you ? So when you have an .aspx page and an assembly deployed to GAC and your codebehind changes you have to redeploy the assembly and reset IIS. I'm talking about Sharepoint applications in particular and I'm not sure whether you have to do iisreset for private assemblies but I guess you have too. So the best way to debug aspx pages with code behind I guess would be to get rid of the codebehind for the time of active debugging and move into the page, then when it is more or less working move it back to codebehind. (This would be applicable only for application pages in Sharepoint, site pages don't allow inline code ) How do you approach debugging of your ASP.NET applications to make it less time consuming?
How to make the process of debugging ASP.NET Sharepoint applications less time consuming?
|asp.net|sharepoint|debugging|
I posted a question which might help you as it discusses some of the issues: [should-i-be-worried-about-obfuscating-my-net-code][1] [1]: http://beta.stackoverflow.com/questions/12075/should-i-be-worried-about-obfuscating-my-net-code
I would look at the configuration of your logger. (Or provide it with one, if it is using a default config) For example, when using Hibernate with an active Log4J setup, Hibernate will automatically join in with the Log4J instance that you set up in your own application It can be tuned, as per the normal Log4J config. This example uses the properties configuration style: log4j.category.org.hibernate=WARN Hibernate may well join in with other logging mechanisms via the apache commons logging API. Look at how to configure your own logger and tune out the org.hibernate.* frequencies. n.b. When debugging, switching on log4j.category.org.hibernate.SQL=INFO or DEBUG can be useful.
This will be per-sign-up and not per-post, right? Because that would just kill the site, even with jQuery automation.
Use [libxml](http://xmlsoft.org/), which performs validation *and* has a streaming mode.
You can use WMI to figure this out. The [Win32_BootConfiguration][1] class will tell you both the logical drive and the physical device from which Windows boots. Specifically, the Caption property will tell you which *device* you're booting from. For example, in powershell, just type **gwmi Win32_BootConfiguration** to get your answer. [1]: http://msdn.microsoft.com/en-us/library/aa394078.aspx
Request.RawUrl
From <http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc34982_1500/html/mig_gde/mig_gde160.htm>: Inner and outer tables The terms outer table and inner table describe the placement of the tables in an outer join: * In a left join, the outer table and inner table are the left and right tables respectively. The outer table and inner table are also referred to as the row-preserving and null-supplying tables, respectively. * In a right join, the outer table and inner table are the right and left tables respectively. For example, in the queries below, T1 is the outer table and T2 is the inner table: * T1 left join T2 * T2 right join T1 Or, using Transact-SQL syntax: * T1 *= T2 * T2 =* T1
You need to change the ProductCode between each version, if you don't do this you will get the behavior you are seeing. The ProductCode is seen in the project properties. Check out the [MSDN Online Help for ProductCode][1] to understand better. [1]: http://msdn.microsoft.com/en-us/library/aafz9hx4.aspx
Use a simple text captcha and then ask the users to enter the answer backwards or only the first letter, or the last, or another random thing. Another idea is to make a ascii image, like this (from Portal game end sequence): .,---. ,/XM#MMMX;, -%##########M%, -@######% $###@= .,--, -H#######$ $###M: ,;$M###MMX; .;##########$;HM###X= ,/@##########H= ;################+ -+#############M/, %##############+ %M###############= /##############: H################ .M#############;. @###############M ,@###########M:. X################, -$=X#######@: /@##################%- +######$- .;##################X .X#####+, .;H################/ -X####+. ,;X##############, .MM/ ,:+$H@M#######M#$- .$$= .,-=;+$@###X: ;/=. .,/X$; .::, ., .. And give the user some options like: IS A, LIE, BROKEN HEART, CAKE
Insert current date in Excel template at creation
|excel|templates|
I'm building an excel template (*.xlt) for a user here, and one of the things I want to do is have it insert the current date when a new document is created (ie, when they double-click the file in windows explorer). How do I do this?
If it works without a hitch then you don't need .NET 3.5 Framework for now. Installing .NET 3.5 Framework is easy enough to do along with later versions of your software *if and only if your software stops working at that point*.
So there are two levels of "work with Boo". One would be all the code (namely, the Controllers), and the other would be the views. For the code, I assume Boo compiles to standard .NET assemblies, so simply properly following the naming conventions using by ASP.NET MVC should allow you to write Controllers. You will probably need to start with a C# or VB version of the MVC web application project template and port some of the boilerplate code over into Boo to get the solution entirely in Boo (I presume Boo supports Web Application projects?). The other half is views. Someone will need to port the Brail view engine over to the ASP.NET MVC view engine system. This may already be done, but I don't know for sure. If it's not, then this is probably a significant amount of work to be done. Probably the best place to get answers to these kinds of questions is the [MvcContrib community on CodePlex][1]. [1]: http://www.codeplex.com/MVCContrib
Yeah - In a way you're both asking and answering the question your self.. But that is one of the two options I can think of. The reasons that might be a problem is that you loose some of the features/control you get from the MediaElement control. Another option is to do this: 1. Add your MediaElement to your page. 2. Draw a Rectangle on top of it and set wanted corner radius 3. Right click the rectangle in Blend and choose "Create Clipping Path" 4. Apply the clipping path to your MediaElement That way you're still using a MediaElement control, but you can "clip" away what ever you want to get the desired rounded effect.
Yeah - In a way you're both asking and answering the question your self.. But that is one of the two options I can think of. The reasons that might be a problem is that you loose some of the features/control you get from the MediaElement control. Another option is to do this: 1. Add your MediaElement to your page. 2. Draw a Rectangle on top of it and set wanted corner radius 3. Right click the rectangle in Blend and choose "Create Clipping Path" 4. Apply the clipping path to your MediaElement That way you're still using a MediaElement control, but you can "clip" away what ever you want to get the desired rounded effect. This example shows a clipped MediaElement. I know it's not easy to picture the vector path, but if you open it open in Blend you will see a rounded MediaElement. <MediaElement Height="132" Width="176" Source="Egypt2007.wmv" Clip="M0.5,24.5 C0.5,11.245166 11.245166,0.5 24.5,0.5 L151.5,0.5 C164.75484,0.5 175.5,11.245166 175.5,24.5 L175.5,107.5 C175.5, 120.75484 164.75484,131.5 151.5,131.5 L24.5,131.5 C11.245166, 131.5 0.5,120.75484 0.5,107.5 z"/>
Kibbee, you were right! It was two files with the same name in different folders. I was setting the breakpoint in the correct file on line 58 - it was putting the breakpoint on the other file at line 58. I was finally able to set a breakpoint by using the "Debug-->New Breakpoint-->Break at Function Name" menu option and entering my function name. It stopped exactly like it should have then. I agree - so much for namespaces, right? Damn thing cost me a couple of hours. Oh, well...at least it's solved and I know why. Thx for the answer and thx to Matt for his reply, too!
If you just use GET and POST, it's still RESTful. Your web service may only do things which only required GET or POST, so that's fine.
What language is this? It doesnt overflow anything in c... Also, you can try creating a lookup table on the heap, or use a map
Why is String.Format static?
|.net|string|
Compare String.Format("Hello {0}", "World"); with "Hello {0}".Format("World"); Why .Net designers choose static method over instance method? What do you think?
|.net|string|
Compare String.Format("Hello {0}", "World"); with "Hello {0}".Format("World"); Why did the .Net designers choose a static method over an instance method? What do you think?
Yes, you can live without PUT and DELETE. This article tells you why: <http://www.artima.com/lejava/articles/why_put_and_delete.html> While to true RESTafrians this may be heresy, in the real world you do what you can, with what you have. Be as rational as you can and as consistent with your own convention as you can, but you can definitely build a good RESTful system without P and D. rp
If its not hurting the performance of the site, I think its a good thing. If you had 1000 clients to the same site all doing that, yeah, block it. But if the site was built for that client, I think its fair enough they do that.
caching is generally a good idea for this kind of thing. Since fibonacci numbers are constant, you can cache the result once you have calculated it. A quick c/pseudocode example class fibstorage { bool has-result(int n) { return fibresults.contains(n); } int get-result(int n) { return fibresult.find(n).value; } void add-result(int n, int v) { fibresults.add(n,v); } map<int, int> fibresults; } fib(int n ) { if(n==0 || n==1) return 1; if (fibstorage.has-result(n)) { return fibstorage.get-result(n-1); } return ( (fibstorage.has-result(n-1) ? fibstorage.get-result(n-1) : fib(n-1) ) + (fibstorage.has-result(n-2) ? fibstorage.get-result(n-2) : fib(n-2) ) ); } calcfib(n) { v = fib(n); fibstorage.add-result(n,v); } This would be quite slow, as every recursion results in 3 lookups, however this should illustrate the general idea
Try [ruby2ruby][1] [1]: http://seattlerb.rubyforge.org/ruby2ruby/
The first thing I did when I got to upgrade to VS2008 and C#3, was to do this public static string F( this string format, params object[] args ) { return String.Format(format, args); } So I can now change my code from String.Format("Hello {0}", Name); to "Hello {0}".F(Name); which I find vastly superior. As for why the .NET designers chose it? Who knows. It's _entirely_ subjective. My money is on either * Copying Java * The guy writing it at the time subjectively liked it more. There aren't really any other valid reasons that I can find
|c++|c|modulo|
I read somewhere once that the modulus operator is inefficient on small embedded devices such as 8 bit micros without integer division operator. Perhaps someone can confirm this but I thought the difference is 5-10 time slower than with an integer division operation.<p> Is there another way to do this other than keeping a counter variable and manually overflowing to 0 at the mod point?<p> const int FIZZ = 6; for(int x = 0; x < MAXCOUNT; x++) { if(!(x % FIZZ)) print("Fizz\n"); // slow on some systems } vs: The way I am currently doing it: const int FIZZ = 6; int fizzcount = 1; for(int x = 1; x < MAXCOUNT; x++) { if(fizzcount >= FIZZ) { print("Fizz\n"); fizzcount = 0; } }
These are the ones I use daily. - prop - try - if - else - for - foreach - mbox - Message box stub - The ability to role your own. I have one for Property that are saved in the view state, methods a custom class example.
Depending on how you code, you *may* see a productivity increase. For background, I'm also a long-time vim user, but I learned emacs about 2 years ago, and now use them interchangeably. What drove me to the point of actually learning emacs was its useful ability to have a large number of files open at once, and to easily switch between them. I was in the middle of introducing a feature that added and touched a large number of classes. (This was C++, so there were typically two files per class.) Since I was still firming up the interface, I would typically be in the middle of updating one file when I would realize that I needed to change another. With gvim, it was easiest to open a new window for each file, which was starting to get unwieldy. With Emacs, though, it was simple to open a new file in the same window (Ctrl-x, Ctrl-f). Once Emacs has a file open, it's very easy to switch back and forth between the open buffers (Ctrl-x, Ctrl-b). Taking that one step further, a single emacs session may open many windows, so in addition to splitting the window vertically, I could decide, without interrupting work on a file, to open another next to it, letting me effectively work side-by-side while still keeping each window at the default 80-character width. There are still some things that I find easier in vim (e.g. block-select mode, simple macro recording, diff mode), and things that are easier in Emacs (line alignment, file/buffer management, window/screen management). Therefore, I find myself alternating between the two (and sometimes using both simultaneously), depending the editing task I anticipate. If you're still unsure, I'd suggest trying it out. Run through the Emacs tutorial and then use it to write code for a morning or a day, leaning heavily on the help. If you still don't like what you see, stay with vim. Regardless of what the editor brings to the table, your familiarity and knowledge of the tool will by far be the most important factor in your productivity.
I've always used the term "magic number" differently, as an obscure value stored within a data structure which can be verified as a quick validity check. For example gzip files contain 0x1f8b08 as their first three bytes, Java class files start with 0xcafebabe, etc. You often see magic numbers embedded in file formats, because files can be sent around rather promiscuously and lose any metadata about how they were created. However magic numbers are also sometimes used for in-memory data structures, like ioctl() calls. A quick check of the magic number before processing the file or data structure allows one to signal errors early, rather than schlep all the way through potentially lengthy processing in order to announce that the input was complete balderdash.
I'm trying to mixin the MultiMap trait with a HashMap like so: val children:MultiMap[Integer, TreeNode] = new HashMap[Integer, Set[TreeNode]] with MultiMap[Integer, TreeNode] The definition for the MultiMap trait is: trait MultiMap[A, B] extends Map[A, Set[B]] Meaning that a MultiMap of types A & B is a Map of types A & Set[B], or so it seems to me. However, the compiler complains: > C:\...\TestTreeDataModel.scala:87: error: illegal inheritance; > template $anon inherits different type instances of trait Map: > scala.collection.mutable.Map[Integer,scala.collection.mutable.Set[package.TreeNode]] and scala.collection.mutable.Map[Integer,Set[package.TreeNode]] > new HashMap[Integer, Set[TreeNode]] with MultiMap[Integer, TreeNode] > ^ one error found It seems that generics are tripping me up again.
[CompareIt][1] is good, I find using the command line interface for svn, that it merges more for me, where tortoise picks up on things and asks you. [1]: http://www.grigsoft.com/wincmp3.htm
It's risky to spawn threads from the code-behind of an ASP.NET page, because the worker process will get recycled occasionally and your thread will die. If you need to kick off long-running processes as a result of user actions on web pages, your best bet is to drop a message off in MSMQ and have a separate background service monitoring the queue. The service could take as long as it wants to accomplish the task, and the web page would be finished with its work almost immediately. You could accomplish the same thing with an asynch call to a web method, but don't rely on getting the response when the web method is finished working. From code-behind, it needs to be a quick fire-and-forget.
If all you need is source control, TFS is overkill. My previous employer had TFS, VSS, and Subversion in their enterprise. We didn't have Active Directory or Exchange Server 2003 in our enterprise, so we ended up creating separate users on the TFS server so developers could use it. We had the same sorts of problems with merging that Ben Schierman mentioned, along with other buggy behavior that pushed us toward Subversion. Whether TFS is the right call for you will depend in part on your budget, the size of your development team, and the amount of time and personnel available for configuration/maintenance of your solution. If you want the additional issue tracking, work item, and project statistics capabilities that TFS provides, it may be worth your while to look at other alternatives. Products like JIRA (from Atlassian Systems) or Trac integrate well with Subversion and provide the sort of oversight a project or program manager might at a lower price. In an ideal environment, with Active Directory, Exchange Server 2003 or higher, and dedicated staff for the repository, TFS is more likely to be a good choice.
To me primary difference between BDD and TDD is focus and wording. And words are important for communicating your intent. TDD directs focus on testing. And since in "old waterfall world" tests come after implementation, then this mindset leads to wrong understanding and behaviour. BDD directs focus on behaviour and specification, and so waterfall minds are distracted. So BDD is more easily understood as design practice and not as testing practice.
Int32.TryParse is probably a tad easier: public static int? ToNullableInt32(this string s) { int i; if (Int32.TryParse(s, out i)) return i; return null; } **Edit** @Glenn Int32.TryParse is "built into the framework". It and Int32.Parse are *the* way to parse strings to ints.
How do you retrieve the commit message and file list for a particular revision?
|svn|version-control|
I need to deploy a few files that were checked in sometime ago (can't remember the exact ones), so I'm looking to get a list so I can deploy just those files. What is the svn command to do this?
>>> import datetime >>> datetime.date (2000, 2, 1) - datetime.timedelta (days = 1) datetime.date(2000, 1, 31) >>>
EDIT: See @[Blair Conrad's answer](#43663) for a cleaner solution --- >>> import datetime >>> datetime.date (2000, 2, 1) - datetime.timedelta (days = 1) datetime.date(2000, 1, 31) >>>
`svn log` has a `--verbose` parameter. I don't have a repository here to test with, but does that return a list of modified files? You can also use `svn diff -r <revision>` to retrieve the full change details, which you can parse or read manually to find out which files were changed.
Not in the case you describe, But the GC will call the **Finalizer** for you, if you have one. HOWEVER. The next garbage collection ,instead of being collected, the object will go into the finalization que, everything gets collected, then it's finalizer called. The next collection after that it will be freed. Depending on the memory pressure of your app, you may not have a gc for that object generation for a while. So in the case of say, a file stream or a db connection, you may have to wait a while for the unmanaged resource to be freed in the finalizer call for a while, causing some issues.
The .Net Garbage Collector calls the Object.Finalize method of an object on garbage collection. By **default** this does **nothing** and must be overidden if you want to free additional resources. Dispose is NOT automatically called and must be **explicity** called if resources are to be released, such as within a 'using' or 'try finally' block see http://msdn.microsoft.com/en-us/library/system.object.finalize.aspx for more information
No, it's not called. But this makes easy to don't forget to dispose your objects. Just use the `using` keyword. I did the following test for this: class Program { static void Main(string[] args) { Foo foo = new Foo(); foo = null; Console.WriteLine("foo is null"); GC.Collect(); Console.WriteLine("GC Called"); Console.ReadLine(); } } class Foo : IDisposable { public void Dispose() { Console.WriteLine("Disposed!"); }
reassign value to query string parameter
I'm building an excel template (*.xlt) for a user here, and one of the things I want to do is have it insert the current date when a new document is created (ie, when they double-click the file in windows explorer). How do I do this? **Update:** I should have added that I would prefer not to use any vba (macro). If that's the only option, then so be it, but I'd really like to avoid forcing my user to remember to click some 'allow macro content' button.
You could also make the ListView ownerdraw. You then have complete control over how the items look whether they are selected or not or whether the ListView itself is enabled or not. The DrawListViewItemEventArgs provides a way to ask the ListView to draw individual parts of the item so you only have to draw the bits you're interested in. For example, you can draw the background of the item but leave it up to the ListView to draw the text.
@Thomas Kammeyer: Note that Atan(1.0) is quite often hardcoded, so 4*Atan(1.0) is not really an 'algorithm' if you're calling a library Atan function (an quite a few already suggested indeed proceed by replacing Atan(x) by a series (or infinite product) for it, then evaluating it at x=1. Also, **there are very few cases where you'd need pi at more precision than a few tens of bits** (which can be easily hardcoded!). I've worked on applications in mathematics where, to compute some (quite complicated) mathematical objects (which were polynomial with integer coefficients), I had to do arithmetic on real and complex numbers (including computing pi) with a precision of up to a few million bits... but this is not very frequent 'in real life' :) You can look up the following example [code][1]. [1]: http://gmplib.org/pi-with-gmp.html
Possible to create REST web service with ASP.NET 2.0
|web-services|rest|
Is it possible to create a REST web service using ASP.NET 2.0? The articles and blog entries I am finding all seem to indicate that ASP.NET 3.5 with WCF is required to create REST web services with ASP.NET. If it is possible to create REST web services in ASP.NET 2.0 can you provide an example. Thanks!
if you need the full URL as everything from the http to the querystring you will need to concatenate the following variables Request.ServerVariables("HTTPS") // to check if it's HTTP or HTTPS Request.ServerVariables("SERVER_NAME") Request.ServerVariables("SCRIPT_NAME") Request.ServerVariables("QUERY_STRING")
[This][1] is a good article (be sure to read the other linked article in it) that discusses looking at th scheduled tasks on remote machines. It is not exactly what you were asking for but it should get you headed in the right direction. [1]: http://myitforum.com/cs2/blogs/yli628/archive/2008/07/28/powershell-script-to-retrieve-scheduled-tasks-on-a-remote-machine-task-scheduler-api.aspx
Having a single exit point reduces [Cyclomatic Complexity][1] and therefore, *in theory*, reduces the probability that you will introduce bugs into your code when you change it. Practice however, tends to suggest that a more pragmatic approach is needed. I therefore tend to aim to have a single exit point, but allow my code to have several if that is more readable. [1]: http://en.wikipedia.org/wiki/Cyclomatic_complexity
I would only add a couple things to Rob's answer: First, Make sure the amount of data involved in the test cases is similiar to production values. In other words if your queries are normally against tables with hundreds of thousands or rows, then create such a test environment. Second, make everything else equal except for the use of an nHibernate generated query and a s'proc call. Hopefully you can execute the test by simply swapping out a provider. Finally, realize that there is usually a lot more at stake than just stored procedures vs. ORM. With that in mind the test should look at all of the factors: execution time, memory consumption, scalability, debugging ability, etc.
WScript.Shell and blocking execution?
|shell|vbscript|wsh|
I'm using WScript to automate some tasks, by using WScript.Shell to call external programs. However, right now it does not wait for the external program to finish, and instead moves on. This causes issues because I have some tasks dependant on others finishing first. I am using code like: ZipCommand = "7za.exe a -r -y " & ZipDest & BuildLabel & ".zip " & buildSourceDir Set wshShell = WScript.CreateObject("Wscript.Shell") wshShell.run ZipCommand Is there a way to do this so it blocks until the shell executed program returns?
Using JQuery, what is the best way to set onclick event listeners for radio buttons?
|javascript|jquery|
For the following HTML: <form name="myForm"> <label>One<input name="area" type="radio" value="S" /></label> <label>Two<input name="area" type="radio" value="R" /></label> <label>Three<input name="area" type="radio" value="O" /></label> <label>Four<input name="area" type="radio" value="U" /></label> </form> Changing from the following javascript code: $(function() { var myForm = document.myForm ; var radios = myForm.radio ; // Loop through radio buttons for (var i=0; i<radios.length; i++) { if (radios[i].value == "S") { radios[i].checked = true ; // Selected when form displays radioClicks() ; // Execute the function, initial setup } radios[i].onclick = radioClicks ; // Assign to run when clicked } }); Thanks
For the following HTML: <form name="myForm"> <label>One<input name="area" type="radio" value="S" /></label> <label>Two<input name="area" type="radio" value="R" /></label> <label>Three<input name="area" type="radio" value="O" /></label> <label>Four<input name="area" type="radio" value="U" /></label> </form> Changing from the following javascript code: $(function() { var myForm = document.myForm ; var radios = myForm.area ; // Loop through radio buttons for (var i=0; i<radios.length; i++) { if (radios[i].value == "S") { radios[i].checked = true ; // Selected when form displays radioClicks() ; // Execute the function, initial setup } radios[i].onclick = radioClicks ; // Assign to run when clicked } }); Thanks
For the following HTML: <form name="myForm"> <label>One<input name="area" type="radio" value="S" /></label> <label>Two<input name="area" type="radio" value="R" /></label> <label>Three<input name="area" type="radio" value="O" /></label> <label>Four<input name="area" type="radio" value="U" /></label> </form> Changing from the following javascript code: $(function() { var myForm = document.myForm ; var radios = myForm.area ; // Loop through radio buttons for (var i=0; i<radios.length; i++) { if (radios[i].value == "S") { radios[i].checked = true ; // Selected when form displays radioClicks() ; // Execute the function, initial setup } radios[i].onclick = radioClicks ; // Assign to run when clicked } }); Thanks EDIT: The response I selected answers the question I asked, however I like the answer that uses bind() because it also shows how to distinguish the group of radio buttons
I can think of situations where either of the first two flavours makes sense: 1. If the needle needs pre-processing, like in the Knuth-Morris-Pratt algorithm, <code>needle.findIn(haystack)</code> (or <code>pattern.findIn(text)</code>)makes sense, because the needle object holds the intermediate tables created for the algorithm to work effectively 2. If the haystack needs pre-processing, like say in a trie, the <code>haystack.find(needle)</code> (or <code>words.hasAWordWithPrefix(prefix)</code>) works better. In both the above cases, one of needle or haystack is aware of the search. Also, they both are aware of each other. If you want the needle and haystack not to be aware of each other or of the search, <code>searcher.find(needle, haystack)</code> would be appropriate.
Use [lxml][1] which is the best xml/html library for python. import lxml.html t = lxml.html.fromstring("...") t.text_content() And if you just want to sanitize the html look at the lxml.html.clean [module][2] [1]: http://codespeak.net/lxml/lxmlhtml.html [2]: http://codespeak.net/lxml/lxmlhtml.html#cleaning-up-html
Is this minimum spanning tree algorithm correct?
|algorithm|correctness|
The minimum spanning tree problem is to take a connected weighted graph and find the sub set of it's edges with the lowest total weight that keeps the connected restriction but results in an acyclic graph. The algorithm I am considering is: - Find all cycles. - remove the largest edge from each cycle. The impetus for this version is an environment that is restricted to "rule satisfaction" without any iterative constructs. It might also be applicable to insanely parallel hardware.
The minimum spanning tree problem is to take a connected weighted graph and find the sub set of it's edges with the lowest total weight that keeps the connected restriction but results in an acyclic graph. The algorithm I am considering is: - Find all cycles. - remove the largest edge from each cycle. The impetus for this version is an environment that is restricted to "rule satisfaction" without any iterative constructs. It might also be applicable to insanely parallel hardware. Edits: The above is done in a stateless manor (all edges that are not the larges edge in some cycle are selected)
The minimum spanning tree problem is to take a connected weighted graph and find the sub set of it's edges with the lowest total weight that keeps the connected restriction but results in an acyclic graph. The algorithm I am considering is: - Find all cycles. - remove the largest edge from each cycle. The impetus for this version is an environment that is restricted to "rule satisfaction" without any iterative constructs. It might also be applicable to insanely parallel hardware. Edits: The above is done in a stateless manor (all edges that are not the largest edge in any cycle are selected/kept, all others are removed)