instruction
stringlengths
0
30k
int NumOfSetBits(int i); Assert.AreEqual(0, NumOfSetBits(0)); Assert.AreEqual(1, NumOfSetBits(1)); Assert.AreEqual(1, NumOfSetBits(2)); Assert.AreEqual(2, NumOfSetBits(3));
8 bits representing the number 7 look like this: 00000111 Three bits are set. What is the best algorithm to determine the number of set bits in a 32-bit integer?
|algorithm|integer|bitwise|bits|bitsets|
|algorithm|integer|bitwise|
|algorithm|bit-manipulation|integer|bitwise|
`setInterval()` returns an interval ID, which you can pass to `clearInterval()`. See the docs for [`setInterval()`](http://developer.mozilla.org/en/DOM/window.setInterval) and [`clearInterval()`](http://developer.mozilla.org/en/DOM/window.clearInterval).
`setInterval()` returns an interval ID, which you can pass to `clearInterval()`: var refreshIntervalId = setInterval(fname, 10000); // ... // later on, deep in the bowels of some event handler. // yes, event handlers have bowels. clearInterval(refreshIntervalId); See the docs f...
`setInterval()` returns an interval ID, which you can pass to `clearInterval()`: var refreshIntervalId = setInterval(fname, 10000); /* later */ clearInterval(refreshIntervalId); See the docs for [`setInterval()`](http://developer.mozilla.org/en/DOM/window.setInterval) and [`clearInterval()`](http:...
I don't really know what answer you expect but... yes :) Could you please rephrase your question if you hope for more specific answer?
Generally everything works fine. It will obviously depend on the client you're using - not everyone implement SOAP properly. P.S. Could you please rephrase your question if you hope for more specific answer?
That should fix the .mvc problem since the integrated pipeline is IIS7 strictly. But remember to change settings on the IIS7 website to use "2.0 Integrated Pipeline" otherwhise it will return false aswell. Also ofcouse setup the mapping of .mvc to the asp.net isapi dll, but Im guessing that you already know this. ...
[Modern C++][1] is one of the best introductions I've read. It covers actual useful examples of template metaprogramming. Also take a look at the companion library [Loki][2]. [1]: http://www.amazon.com/Modern-Design-Programming-Patterns-Depth/dp/0201704315 [2]: http://loki-lib.sourceforge.net/
Hmm... interesting question. Initially I'd point you at the FileSystemWatcher class. If you are going to have it work, however, on user request, then it would seem you might need to store off the directory info initially and then compare each time the user requests. I'd probably go with a FileSystemWatcher and just ...
Veldhuizen's original papers were good. If you up for a whole book, then there's Vandevoorde's book "C++ Templates Complete Guide". And when you're ready for the master's course, try Alexandrescu's Modern C++ Design.
[Modern C++ Design][1], a brilliant book and design pattern framework by Alexandrescu. Word of warning, after reading this book I stopped doing C++ and thought "What the heck, I can just pick a better language and get it for free". [1]: http://www.amazon.com/Modern-Design-Programming-Patterns-Depth/dp/0201704315
The concept of truthy and falsy values. You don't need to do something like if(someVar === undefined || someVar === null) ... Simply do: if(!someVar). Every value has a corresponding boolean representation.
If you are using descriptors on your classes Python completely bypasses `__dict__` for that key which makes it a nice place to store such values: >>> class User(object): ... def _get_username(self): ... return self.__dict__['username'] ... def _set_username(self, value): ... print 'user...
I think what you want is provided by the [FileSystemWatcher][1] class. This tutorial describes how to use it to monitor a directory for changes in a simple windows service; [How to implement a simple filewatcher Windows service in C#][2] [1]: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher...
I like @tovare's solution. Make a pointer array: int ptr[] = { 1, 2, 3 }; and then when you sort on numbers, swap the values in ptr instead of in numbers. Then access through the ptr array, like for (int i = 0; i < ptr.length; i++) { printf("%d %d\n", numbers[ptr[i]], colors[ptr[i]]); ...
Two good books that spring to mind are: - Modern C++ Design / Andrei Alexandrescu (It's actually 7 years old despite the name!) - C++ Templates: The Complete Guide / Vandevoorde & Josuttis It's quite an in-depth field, so a good book like one of these is definitely recommended over websites. Some of the mor...
IMO, it's perfectly acceptable to store things in the session. It's a great way to make data persistent. It's also, in many cases, more secure than storing everything in cookies. Here are a few concerns: - It's possible for someone to hijack a session, so if you're going to use it to keep track of user authorizatio...
Bazaar is IMHO easier to learn than git. Git has a nice support in github.com. I think you should try to use both and decide which suits you most.
If you're running on your own server, or in an environment where nobody can snoop on your files/memory on the server, session data are secure. They're stored on the server and just an identification cookie sent to the client. The problem is if other people can snatch the cookie and impersonate someone else, of course. ...
I don't want to get into writing code for this now but if I understand "frustum" correctly the following should work. 1. Intersect the Line with all given planes 2. If you have two intersections you're done. 3. If you have only one intersection calculate the front plane and intersect. 4. If you still have only on...
In Delphi, How do I get an enumerator from LocalPolicy.CurrentProfile.GloballyOpenPorts in the Firewall API
|delphi|firewall|
I am writing some code to see if there is a hole in the firewall exception list for WinXP and Vista for a specific port used by our client software. I can see that I can use the NetFwMgr.LocalPolicy.CurrentProfile.GloballyOpenPorts to get a list of the current Open port exceptions but can not figure out how to get ...
If you use SWT it has a native vista look and feel built in. However, if you are using swing I honestly do not know.
Is it worth the development time to output valid HTML?
|xhtml|strict|strict-html|valid-html|valid-xhtml|
Developing websites are time-consuming. To improve productivity, I would code a prototype to show to our clients. I don't worry about making the prototype comform to the standard. Most of the time, our clients would approve the prototype and give an unreasonable deadline. I usually end up using the prototype in product...
In continuous integration what is the best way to deal with external application dependencies
|continuous-integration|dependencies|teamcity|
In using our TeamCity Continuous Integration server we have uncovered some issues that we are unsure as to the best way to handle. Namely how to reference external applications that our application requires on the CI server. This was initially uncovered with a dependency on Crystal Reports, so we went and installed...
Have you thought about Visual Studio for Applications? I haven't heard much about it since .NET 1.1, but it might be worth a look. http://msdn.microsoft.com/en-us/library/ms974548.aspx
Based on Mike McAllister's idea, the following uses a derived table to achieve the desired result: select T.PARENT ,T.CHILD ,sys_connect_by_path(T.CDESC, '/') from ( select t2.parent as PARENT ,t2.child as CHILD ...
We used ViewVC for browsing both CVS and SVN repositories but since we switched to [FishEye][1] we finally have a really good solution for code browsing and examination. We also use other Atlassian products (Jira and Confluence) and integration between all of them is just marvelous! PS. I'm not an Atlassian emp...
How do I sort a VARCHAR column in SQL server that contains numbers?
|sql|t-sql|
I have a VARCHAR column in a SQL Server 2000 database that can contain either letters or numbers. It depends on how the application is configured on the front-end for the customer. When it does contain numbers, I want it to be sorted numerically, e.g. as "1", "2", "10" instead of "1", "10", "2". Fields containing j...
One gotcha I noticed the other day and it was a real "DUH!" moment for me. We have a third party search engine on our site and they use the GET method to post the search query to their code. In addition, I had some code that looked for possible SQL injection attacks in the querystring. My code was screwing everyth...
Supplementary development tools for Java
|java|supplementary|
What are your favorite supplementary tools for Java development? Mine are: 1) TotalCommander (due to the ability to search inside JARs). 2) JAD + Jadclipse (to decompile)
What are your favorite supplementary tools for Java development? Mine are: 1) Total Commander (due to the ability to search inside JARs). 2) JAD + Jadclipse (to understand and debug libraries)
|java|supplementary|
What are your favorite supplementary tools for Java development? Mine are: 1) Total Commander (due to the ability to search inside JARs). 2) JAD + Jadclipse (to understand and debug libraries) And of-course, Google. (can't really live without it)
Microsoft has an article up on MSDN that talks about [Migrating ASP Pages to ASP.NET][1]. They basically tell you to install .net on your computer/server and the transform one page at a time. ASP and ASP.NET can co-exist so can can rename each page to "aspx" as you go. You should note, however, that session state and a...
Even if there are tools to convert between classic ASP and ASP.NET, they're not going to generate very good results: the two environments are just too fundamentally different. A quick Google turns up a few results, mostly of the "we'll have our guys in India do it" variety. My advice would be not to touch your exist...
In C++ at any rate, the scope of an automatic variable is limited by the curly braces that surround it. Why would anyone expect this to be different by plunking down a try keyword outside the curly braces?
If the entities in the ArrayLists are Object types, you'll gain a little from not casting them to the correct type. If they're Value types (structs or primitives like Int32), then the boxing/unboxing process adds a lot of overhead, and Generic collections should be much faster. [Here's an MSDN article on the subje...
It is for optimization reasons. range() will create a list of values from start to end (0 .. 20 in your example). This will become an expensive operation on very large ranges. xrange() on the other hand is much more optimised. it will only compute the next value when needed (via an xrange sequence object) and doe...
I just implemented a quick test application and profiled it with ANTS 4. Spec: .Net 3.5 sp1 in 32bit Windows XP, code built in release mode. 3 million tests: - Switch: 1.842 seconds - If: 0.344 seconds. Furthermore, the switch statement results reveal (unsurprisingly) that longer names take longer. ...
You're on the right track. You will need to override the SnapLines property in your designr and do something like this: Public Overrides ReadOnly Property SnapLines() As System.Collections.IList Get Dim snapLinesList As ArrayList = TryCast(MyBase.SnapLines, ArrayList) Di...
http://www.maatkit.org/ has a mk-parallel-dump and mk-parallel-restore > If you’ve been wishing for multi-threaded mysqldump, wish no more. This tool dumps MySQL tables in parallel. It is a much smarter mysqldump that can either act as a wrapper for mysqldump (with sensible default behavior) or as a wrapper around S...
1. Use XML for data that the application should know - configuration, logging and what not. 2. Use databases(oracle, SQL server etc) for data that the user interacts with directly or indirectly - real data 3. Use SQLite if the user data is more of a serialized collection - like huge l...
**zacherates** writes: > I'd model Role as an association class between Users and Roles (...) I'd also reccomed this solution, but you can also make use of some syntactical sugar provided by Django: [ManyToMany relation with extra fields][1]. Example: class User(models.Model): name = models.CharF...
A lot of the old ANSI [Color Codes][1] work. The code for a red foreground is something like Escape-[31m. Escape is character 27, so that's "\033[31m" or "\x1B[31m", depending on your escaping scheme. [39m is the code to return to default color. It's also possible to specify multiple codes at once to set foregrou...
A lot of the old ANSI [Color Codes][1] work. The code for a red foreground is something like Escape-[31m. Escape is character 27, so that's "\033[31m" or "\x1B[31m", depending on your escaping scheme. [39m is the code to return to default color. It's also possible to specify multiple codes at once to set foregrou...
This is a fairly common thing to do, and the session is generally going to be faster than continuous database hits. They're also reasonably secure, as the PHP devs have worked hard to prevent Session Hijacking. The only issue is that you need to remember to rebuild the session entry when something changes. And, if ...
We had problems of Session when we did migrating the AnkerEx application to the new server. The new server had Microsoft Windows Server 2008 as operation system and Microsoft Internet Information Services 7. Also in the server were installed .NET Framework of versions 1.0.3705, 1.1.4322, 2.0.50727, 3.0 and 3.5. ...
We had problems of Session when we did migrating the AnkerEx application to the new server. The new server had Microsoft Windows Server 2008 as operation system and Microsoft Internet Information Services 7. Also in the server were installed .NET Framework of versions 1.0.3705, 1.1.4322, 2.0.50727, 3.0 and 3.5. ...
In Visual Studio 2008 SP1 the [XML Schema Explorer](http://msdn.microsoft.com/en-us/library/cc716766.aspx) can create an XML document with some basic sample data.
Isn't it (at least theoretically) possible, to read in the ZIP's Huffman coding and then translate the regexp into the Huffman code? Might this be more efficient than first de-compressing the data, then running the regexp? (Note: I know it wouldn't be quite that simple: you'd also have to deal with other aspects of ...
Another difference between java and C++, is that in C++, the namespace hierarchy does not need to mach the filesystem layout. So I tend to put an entire reusable library in a single namespace, and subsystems within the library in subdirectories: #include "lib/module1.h" #include "lib/module2.h" lib:...
How do I prevent the closing of modal popup window(ModalPopupExtender) on postback?
|asp.net|
I'm using Microsoft AjaxControlToolkit for modal popup window. And on a modal popup window, when a postback occured, the window was closing. How do i prevent from the closing action of the modal popup?
I found that ThreadPool.QueueUserWorkItem gives me an easy way to test such use cases ThreadPool.QueueUserWorkItem(x => { File.Open(fileName, FileMode.Open, FileAccess.Read); @event.WaitOne(); }); ThreadPool.QueueUserWorkItem(x => { try { File.Delete...
@ajmastrean, since unit test result must be predictable we need to synchronize threads somehow. I can't see a simple way to do it without using events. I found that ThreadPool.QueueUserWorkItem gives me an easy way to test such use cases ThreadPool.QueueUserWorkItem(x => { File.Open(fileName, File...
@ajmastrean, since unit test result must be predictable we need to synchronize threads somehow. I can't see a simple way to do it without using events. I found that ThreadPool.QueueUserWorkItem gives me an easy way to test such use cases ThreadPool.QueueUserWorkItem(x => { File.Open(fileName, File...
If you don't like using whitespace to denote scopes, you can use the C-style {} by issuing: from __future__ import braces
I would start with an existing project, such as the open source search engine from Wikia. [http://re.search.wikia.com/about/get_involved.html][1] -- Bruce [1]: http://re.search.wikia.com/about/get_involved.html
Hidden Features of C++
|c++|
No C++ love when it comes to the "hidden features of" line of questions? Figured I would throw it out there. What are some of the hidden features of C++?
|c++|discussion|
|c++|
|c++|hidden-features|
`__slots__` is a nice way to save memory, but it's very hard to get a dict of the values of the object. Imagine the following object: class Point(object): __slots__ = ('x', 'y') Now that object obviously has two attributes. Now we can create an instance of it and build a dict of it this way: ...
Andrei Alexandrescu's Modern C++ Design book covers a lot of this and other tricks for speedy and efficient modern C++ code and is the basis for the Loki library. Also worth mentioning is the Boost libraries, which heavily use these techniques and are usually of very high quality to learn from (although some are qui...
Andrei Alexandrescu's [Modern C++ Design][1] book covers a lot of this and other tricks for speedy and efficient modern C++ code and is the basis for the [Loki][2] library. Also worth mentioning is the [Boost][3] libraries, which heavily use these techniques and are usually of very high quality to learn from (althou...
Would it suffice to code your own sort method? A simple bubblesort would probably be quick to code (and get right). No need for extra classes or comparators.
Google Chrome broke ShellExecute() ?
|shellexecute|google-chrome|
For years I've been using ShellExecute() API to launch the default web browser from within my applications. Like this: ShellExecute( hwnd, _T("open"), _T("http://www.winability.com/home/"), NULL, NULL, SW_NORMAL ); It's been working fine until a couple of weeks ago, when Google released it...
An option you may consider, if an LL parser is ok to you, is to give [ANTLR][1] a try, it can generate python too (actually it is LL(*) as they name it, * stands for the quantity of lookahead it can cope with). [1]: http://www.antlr.org/wiki/display/ANTLR3/Antlr3PythonTarget
You solution is exactly what you should do. You can't be sure that your declaration was even reached in the try block, which would result in another exception in the catch block. It simply must work as separate scopes. try dim i as integer = 10 / 0 ''// Throw an exception dim s as string = "...
Its best to use it for every method intended as an override, and Java 6+, every method intended as an implementation of an interface. First, it catches mispellings like "hashcode" instead of "hashCode" at compile-time. It can be baffling to debug why the result of your method doesn't seem to match your code when the...
Given what Nicholas pointed me to I found this in the docs. It allows me to pick at runtime the bean contexts I'm interested in. GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions(new Clas...
If the assignment operation fails your catch statement will have a null reference back to the unassigned variable.
I don't think there's a better way to do it. Any solution including IQueryable would presumably need to iterate the collection internally so wouldn't be any faster. Performance is unlikely to be a problem anyway, so I wouldn't worry about the inefficiency. If you are doing it a lot, you could provide a wrapper t...
Oh ouch, did not know that :-|. That probably seals its case, then. Because mostly I was under the assumption that such a basic CSS2 property should definitely be supported in modern browsers, but if it didn't make it into CSS 2.1, then it makes a lot more sense that it isn't. For future reference, it doesn't show u...
Oh ouch, did not know that :-|. That probably seals its case, then. Because mostly I was under the assumption that such a basic CSS2 property should definitely be supported in modern browsers, but if it didn't make it into CSS 2.1, then it makes a lot more sense that it isn't. For future reference, it doesn't show u...
Use sys.dm_sql_referencing_entities Note that sp_depends is obsoleted. [MSDN Reference][1] [1]: http://msdn.microsoft.com/en-us/library/bb630351.aspx
**Database** Microsoft SQL Server **Defect** Huge licensing cost **Description** SQL Server has great features and it integrates very well with .NET development. The issue is that when you have to scale up from a shared database to a dedicated database, licensing costs are really high. This, in effect, leads t...
What I discovered is that Microsoft.SqlServer.Management.Smo.Server(ServerName).Settings.DefaultFile only returns non-null when there is no path explicitly defined. As soon as you specify a path which is not the default, then this function returns that path correctly. So, a simple workaround was to check...
Storing xml data in a cookie
|asp.net|c#|serialization|cookies|
I'm trying to store an xml serialized object in a cookie, but i get an error like this: A potentially dangerous Request.Cookies value was detected from the client (KundeContextCookie="<?xml version="1.0" ...") I know the problem from similiar cases when you try to store something that looks like javascript co...