instruction stringlengths 0 30k ⌀ |
|---|
You cannot prevent the process on the far end of a pipe from exiting, and if it exits before you've finished writing, you will get a SIGPIPE signal. If you SIG\_IGN the signal, then your write will return with an error - and you need to note and react to that error. Just catching and ignoring the signal in a handler ... |
"(n & (n - 1)) == 0" is best. However, note that it will incorrectly return true for n=0, so if that is possible, you will want to check for it explicitly.
http://www-graphics.stanford.edu/~seander/bithacks.html has a large collection of clever bit-twiddling algorithms, including this one. |
## Some test results
I've gotten a lot of good answers to this question--thanks folks--so I decided to run some tests and figure out which method is actually fastest. The five methods I tested are these:
* the "ContainsKey" method that I presented in [the question](http://stackoverflow.com/questions/81346/most-ef... |
## Some test results
I've gotten a lot of good answers to this question--thanks folks--so I decided to run some tests and figure out which method is actually fastest. The five methods I tested are these:
* the "ContainsKey" method that I presented in [the question](http://stackoverflow.com/questions/81346/most-ef... |
OpenWatcom costs nothing and compiles F77 on Win32, Win16, OS/2 and DOS.
(Just to give you a non mainstream option as well) |
How to convert a unmanaged double to a managed string? |
|c++|unmanaged|double|managed| |
From managed c++, I am calling an unmanaged c++ method which returns a double. How can I convert this double into a managed string?
Sorry if this is a stupid question, I'm still very new with C++ in .net.
Thanks! |
[SyncBack (free) or SyncBackSE ($$)][1] is another possible solution. SyncBackSE is one of the few programs I've ever *paid for*.
IMHO, NIH violates **Laziness** and **Impatience**, though it strongly supports **Hubris**.
[1]: http://www.2brightsparks.com/downloads.html |
[SyncBack (free) or SyncBackSE ($$)][1] is another possible solution. SyncBackSE is one of the few programs I've ever *paid for*. Health warning: Win only.
IMHO, NIH violates **Laziness** and **Impatience**, though it strongly supports **Hubris**.
[1]: http://www.2brightsparks.com/downloads.html |
Is it correct to use the backtick / coma idiom inside a (loop ...)? |
|lisp|iteration| |
I vave some code which collects points (consed integers) from a loop which looks something like this:
(loop
for x from 1 to 100
for y from 1 to 100 do
collect `(,x . ,y))
My question is, is it correct to use <code>`(,x . ,y)</code> in this situation? |
Is it correct to use the backtick / comma idiom inside a (loop ...)? |
I have some code which collects points (consed integers) from a loop which looks something like this:
(loop
for x from 1 to 100
for y from 1 to 100 do
collect `(,x . ,y))
My question is, is it correct to use <code>`(,x . ,y)</code> in this situation? |
I have some code which collects points (consed integers) from a loop which looks something like this:
(loop
for x from 1 to 100
for y from 1 to 100
collect `(,x . ,y))
My question is, is it correct to use <code>`(,x . ,y)</code> in this situation? |
I have some code which collects points (consed integers) from a loop which looks something like this:
(loop
for x from 1 to 100
for y from 100 downto 1
collect `(,x . ,y))
My question is, is it correct to use <code>`(,x . ,y)</code> in this situation?
Edit: This sample ... |
You really don't want to be working directly on a live web site, do you? That's just crazy. One little mistake and you've hosed the site.
Visual Studio now has it's own built in web server. You use that for testing. If you really don't want to use that you can use your local IIS or find a Dev/QA server somewhe... |
|oop|inversion-of-control|castle-windsor|di| |
I'm using castle windsor for a pet-project I'm working on. I'm starting to notice that I need to call the IoC container in different places in my code to create new objects. This dependency on the container makes my code harder to maintain.
There are two solutions I've used to solve this problem
I tried to create... |
According to <a href="http://uk.php.net/manual/en/function.is-writable.php">the documentation for is_writable</a> - but you said "folder", so this could be <a href="http://bugs.php.net/bug.php?id=27609">a Windows issue</a>. The comments suggest <a href="http://uk.php.net/manual/en/function.is-writable.php#68098">a work... |
According to <a href="http://uk.php.net/manual/en/function.is-writable.php">the documentation for is_writable</a>, it should just work - but you said "folder", so this could be <a href="http://bugs.php.net/bug.php?id=27609">a Windows issue</a>. The comments suggest <a href="http://uk.php.net/manual/en/function.is-writa... |
You can also add a content-expires page directive to your ASP.NET page (for different expire schedules):
@Outputcache
Or you can set the header inside your code (perhaps a base page class):
`Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));`
A good article on caching can be found on MSDN:
[http://... |
I recently built a system like this on top of git (http://git.or.cz/). Basically, write a program that takes all your input files, sends them to the server, reads the output back, and writes it to a set of output files. After the first run, commit the output files to git.
For future runs, your success is determine... |
iBATIS for Python? |
|python|orm|ibatis| |
At my current gig, we use iBATIS through Java to CRUD our databases. I like the abstract qualities of the tool, especially when working with legacy databases, as it doesn't impose its own syntax on you.
**I'm looking for a Python analogue to this library**, since the website only has Java/.NET/Ruby versions availab... |
It's reasonable for a constructor to throw an exception so long as it cleans itself up properly. If you follow the [RAII][1] paradigm (Resource Acquisition Is Initialization) then it **is** quite common for a constructor to do meaningful work; a well-written constructor will in turn clean up after itself if it can't f... |
In past experiences, I've kept database changes source controlled in such a way that for each release of the product any database changes were always scripted out and stored in the release that we're working on. The build process in place would automatically bring the database up to the current version based on a tabl... |
IT seems to me you should be able to implement something similar to Corporal Touchy's method a a vertex program rather than in a for loop, right? Maybe use a C API to GPU programming, such as [CUDA][1]?
[1]: http://www.nvidia.com/object/cuda_what_is.html |
Have you tried looking into Type Converters? This page looks worth a look: http://www.codeguru.com/columns/VB/article.php/c6529/
Also, Spring.Net seems to have a StringArrayConverter (http://www.springframework.net/doc-latest/reference/html/objects-misc.html - section 6.4) which, if you can feed it to ASP.net by dec... |
Backgrounding a process is a shell function, not an OS function.
If you want an app to start in the background, the typical trick is to write a shell script to launch it that launches it in the background.
#! /bin/sh
/path/to/myGuiApplication &
|
A firewall will do just fine. But if you won't settle for just a firewall you can configure apache to just listen on your loopback device, or tell it to just accept connections from a set of addresses on your lan. The first method is easier, but that way you can access the web pages only from the machine apache is runn... |
What happens to my app when my Mac goes to sleep? |
|macos|process-management|sleep| |
When Mac OS X goes to sleep, due to closing a laptop or selecting "Sleep" from the Apple menu, how does it suspend an executing process?
I suppose non-windowed processes are simply suspended at an arbitrary point of execution. Is that also true for Cocoa apps, or does the OS wait until control returns to the run lo... |
What is the semantic web, and why would I want to use it? |
|language-agnostic|semantic-web| |
Just like it reads. |
From [C# from a Java developer's perspective](http://www.25hoursaday.com/CsharpVsJava.html#generics) by Dare Obasanjo:
In certain cases, one may need create a method that can operate on data structures containing any type as opposed to those that contain a specific type (e.g. a method to print all the objects in a d... |
> tee seems to insist on waiting for the
> end of file before outputting anything
> to either stdout or the log file.
This should definitely not be happening - it would render tee nearly useless. Here's a simple test that I wrote that puts this to the test, and it's definitely not waiting for eof.
$ cat t... |
You should trap the error outside of your main loop.<br>
Or if you want to ship/locate your own assemblies you can try overriding the assembly probing: [Link][1].
[1]: https://blogs.msdn.com/junfeng/archive/2006/03/27/561775.aspx |
This post might be helpful: http://www.sharepointusecases.com/index.php/2008/08/office-2003-and-sharepoint-2007-comparision |
Another option would be to reverse engineer the DDL...
DBMS_METADATA.GET_DDL('CONSTRAINT', 'SYS_C003415')
Some examples here....
http://www.psoug.org/reference/dbms_metadata.html |
This is a great question. Doesn't MVC exist in the ASP.NET environment, without using the specific MVC pattern.
View = aspx
Controller = aspx.cs (codebehind)
Model = POCO (Plain Old C#/VB/.NET objects)
I'm wondering why the added functionality of MVC framework is helpful. I worked significantly with Jav... |
What you want to do is use reflection to check and see if the assembly can be loaded into memory. Wrap that up in a try..catch block and handle any of the specific exceptions that come from it.
Try
Assembly.Load("System.Data.SQLite, Version=1.0.22.0, Culture=neutral, PublicKeyToken=DB937BC2D44FF139");
... |
You could use a setup project to build an installer for your app. This would analyze all of the static dependencies and produce an installer that ensures that the target machine gets everything it needs. |
best way to get started in setting up Mono for ASP.NET on Mac |
|asp.net|macos|mono|developer-machine| |
I have recently gained access to a Mac. I am wondering if anyone has any tips/advice for setting up [Mono][1] on a mac for development and execution of ASP.NET? Most resources point to Linux implementations which tend to differ a lot from the way Mac's do things. Any tips or advice would be helpful
[1]: http://w... |
You really don't want to be working directly on a live web site, do you? That's just crazy. One little mistake and you've hosed the site.
Visual Studio now has it's own built in web server. You use that for testing. If you really don't want to use that you can put IIS on your local machine or set up a Dev/QA s... |
I would recommend a wiki wiht a "Wiki Gardener" role- someone who cleans up the duplicate entries and sorts.
Wiki technology with a Rich Text Editor option would useful if your Support Desk are not totally technical.
Having some structure is imperative, developing something in any Wiki that makes sense to the ge... |
If you combine the last 4 digits of the card number with the card holder's name (or just last name) and the expiration date you should have enough information to make the record unique. Hashing is nice for security, but wouldn't you need to store/recall the salt in order to replicate the hash for a duplicate check? |
There might be a limit of how many connections can be open at once, so if you have many user you might run out of SQL connections. In effect, users will see SQL errors instead of nice web pages.
It's better to open a connection to read data, then close it, then display data and once the user clicks "submit" you open... |
I added a mobile presentation layer to an operational site about a year ago. Based on the architecture of the site (hopefully this isn't too technology dependent for you) I added a new set of JSP's to accommodate mobile browsers (sidenote: see [http://wurfl.sourceforge.net/][1] for a great way to build mobile pages ind... |
Just because you redirect doesn't mean the script stops executing. A redirect is just a header being sent. If you don't exit() right after, the rest of your script will continue running. When the script does finish running, it will close off all open connections (or release them back to the pool if you're using pers... |
[http://e-docs.bea.com/wls/docs92/compatibility/compatibility.html][1]
>BEA WebLogic Server is one hundred percent J2EE 1.4 compatible
...which means that it supports the [servlet 2.4 specification][2].
[1]: http://e-docs.bea.com/wls/docs92/compatibility/compatibility.html
[2]: http://java.sun.com/produ... |
In past experiences, I've kept database changes source controlled in such a way that for each release of the product any database changes were always scripted out and stored in the release that we're working on. The build process in place would automatically bring the database up to the current version based on a tabl... |
In my opinion, the simplest case to make for refactoring is fixing overly complex code. Measure the McCabe cyclomatic complexity of the source code in question (Source Monitor is an excellent tool for such a problem). Source code with high cyclomatic complexity has a strong correlation defects and bad fixes. What th... |
GCC optimization flags for Intel Atom |
|optimization|gcc|intel-atom| |
I'm developing a performance critical application for Intel Atom processor.
What are the best gcc optimization flags for this CPU? |
If you want to do a complete cleanup and have the time to do it then the best solution is to delete all the #includes in all the files (except for obvious ones e.g. abc.h in abc.cpp) and then compile the project. Add the necessary forward declaration or header to fix the first error and then repeat until you comple cle... |
Assuming you're familiar with "include guards" (#ifdef at the begining of the header..), an additional way of speeding up build time is by using external include guards.
It was discussed in "Large Scale C++ Software Design" IIRC. The idea is that classic include guards, unlike #pragma once, do not spare you the prepro... |
Assuming you're familiar with "include guards" (#ifdef at the begining of the header..), an additional way of speeding up build time is by using external include guards.
It was discussed in "[Large Scale C++ Software Design][1]". The idea is that classic include guards, unlike #pragma once, do not spare you the prepro... |
Most of the daughterboards do quadrature downconversion and produce
analog I & Q. For those daughterboards we use 1 A/D for I and another
one for Q.
|
[PC-Lint][1] will go a long way to cleaning up spaghetti headers. Also it will solve other problems for you too like uninitialised variables going unseen, etc.
[1]: http://www.gimpel.com/ |
Checking for external dependances in vb.net |
|vb.net| |
Something i've never really done before, but what is the best way to make sure that any external assemblies/dll's that my application uses are available, and possibly the correct version.
I wrote an app that relies on the System.Data.SQLite.dll, i went to test it on a machine where that dll was missing, and my app j... |
|.net| |
Why use Mono on a Mac? Run Parallels, VMWare, or Boot Camp. |
Is it a good (correct) way to encapsulate a collection? |
|c++|collections|encapsulation| |
class MyContainedClass {
};
class MyClass {
public:
MyContainedClass * getElement() {
// ...
std::list<MyContainedClass>::iterator it = ... // retrieve somehow
return &(*it);
}
// other methods
private:
std::list<MyContainedClass> m_contai... |
A power of two will have just one bit set (for unsigned numbers). Something like
bool powerOfTwo = !(x & (x - 1));
Will work fine; one less than a power of two is all 1s in the less significant bits, so must AND to 0 bitwise.
|
A power of two will have just one bit set (for unsigned numbers). Something like
bool powerOfTwo = !(x == 0) && !(x & (x - 1));
Will work fine; one less than a power of two is all 1s in the less significant bits, so must AND to 0 bitwise.
As I was assuming unsigned numbers, the == 0 test (that I originally... |
There's no such thing as ColdFusion MX 2004, neither in name nor release year (CFMX 6.1 was released in 2003, and CFMX 7 was released in 2005).
<strong>[FusionDebug](http://www.fusion-reactor.com/fd/)</strong> supports all versions of CFMX from 6.1 onwards.
You may want to investigate <strong>[BlueDragon.NET]... |
Fluent NHibernate Many-to-Many |
|c#|nhibernate|fluent| |
I am using Fluent NHibernate and having some issues getting a many to many relationship setup with one of my classes. It's probably a stupid mistake but I've been stuck for a little bit trying to get it working. Anyways, I have a couple classes that have Many-Many relationships.
public class Person
{
... |
Well you can really shoot yourself in the foot with operator overloading. It's like with pointers people make stupid mistakes with them and so it was decided to take the scissors away.
At least I think that's the reason.
I'm on your side anyway. :) |
Yes, you can!
Here is the discussion about this on the FogBugz discussion forums:
[http://support.fogcreek.com/default.asp?fogbugz.4.27602.1][1]
and the subsequent FogBugz (version 6.x) Documentation that they refer to:
[http://www.fogcreek.com/FogBugz/docs/60/topics/customers/BugzScout.html][2]
[1]: h... |
How can I change the text color in the windows command prompt |
|windows|ruby|command-line|colors| |
I have a command line program, which outputs logging to the screen.
I want error lines to show up in red. Is there some special character codes I can output to switch the text color to red, then switch it back to white?
I'm using ruby but I imagine this would be the same in any other language.
Something like:
... |
To me it really depends on what you are doing with them, how many users/processes need access to them at the same time etc.
I work with large XML files all the time, but they are single process, import style items, that multi-user, or performance are not really needs.
SO really it is a balance. |
Try GeneTree. You can open a free account and build a family tree interactively. You can also find others whose DNA matches yours, who may be family members you did not know about before.
If the functionality is already there, and free, why write a program? |
@Jeff Hubbard:
> This actually inadvertantly provides me with the solution I want: I can set pvData to NULL on _HOOK_FREE and not run into problems with 0xFEEEFEEE for my pointer address.
If this is working for you, then it means that you are reading freed memory when you're testing for the NULL pointer (ie., the... |
Throwing an exception during construction is a great way to make your code way more complex. Things that would seem simple suddenly become hard. For example, let's say you have a stack. How do you pop the stack and return the top value? Well, if the objects in the stack can throw in their constructors (constructing... |
It's tricky. What you have to do is set the Response.Filter property to a custom stream class that you implement. The MVC Contrib project actually has examples of doing this. I'd poke around in there. |
MVC Preview 5 - Rendering A View To String For Testing |
|mvc|preview5|rendering|view|testing| |
I was reading a post by Brad Wilson ([http://bradwilson.typepad.com/blog/2008/08/partial-renderi.html][1]) on the new ViewEngine changes to MVC Preview 5 and thought that it would be great to be able to render a view to string for use in tests. I get the impression from the article that it may be possible to achieve th... |
|asp.net-mvc|testing|rendering|view| |
using fstream to read every character including spaces and newline |
|c++|newline|fstream|spaces| |
I wanted to use fstream to read a txt file.
I am using inFile >> characterToConvert, but the problem is that this omits any spaces and newline.
I am writing an encryption program so i need to include the spaces and newlines and was wondering what would be the proper way to go about accomplishing this.
Thanks i... |
Is there any good oracle podcasts |
|oracle-database|podcasts| |