instruction
stringlengths
0
30k
[Code Craft][1] by Pete Goodliffe is a good read! ![Code Craft][2] [1]: http://www.amazon.com/Code-Craft-Practice-Writing-Excellent/dp/1593271190/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1221320928&sr=8-1 [2]: http://ecx.images-amazon.com/images/I/51WZ9AEC3GL._SL500_BO2,204,203,200_PIsitb-dp-500-arrow,TopRight,...
How to replace WinAPI functions calls in the MS VC++ project with my own implementation (name and parametrs set are the same)?
|c++|winapi|visual-c++|
I need to replace all WinAPI calls of the - CreateFile, - ReadFile, - SetFilePointer, - CloseHandle with my own implementation (which use low-level file reading via Bluetooth). The code, where functions will be replaced, is Video File Player and it already works with the regular hdd files. It is also ne...
IMHO... Restricting "C_UD" operations to stored procedures can keep the data integrity logic in one place. This can also be done by restricting"C_UD" operations to a single middle ware layer. Read operations can be provided to the application so they can join only the tables / columns they need.
I've done this for internal apps by creating a VB Script harness that launches the setup executable, waits for it to close, and then launches the second program. You could also accomplish this with a little more polish using a few Win API calls in a C executable.
Overlapped I/O on anonymous pipe
|winapi|pipe|
Is it possible to use overlapped I/O with an anonymous pipe? CreatePipe() does not have any way of specifying FILE\_FLAG\_OVERLAPPED, so I assume ReadFile() will block, even if I supply an OVERLAPPED-structure.
Remember in SQL Server all single statement CRUD operations are in an implicit transaction by default. You just need to turn on explict transactions (BEGIN TRAN) if you need to make multiple statements act as an atomic unit.
How can I tell if I have an open relay?
|smtp|
I'm trying to work out if I have an open relay on my server. How do I do that? I've tried http://www.abuse.net/relay.html and it reports: Hmmn, at first glance, host appeared to accept a message for relay. THIS MAY OR MAY NOT MEAN THAT IT'S AN OPEN RELAY. Some systems appear to accept relay mail, but then re...
ASP.NET - Is it possible to trigger a postback from server code?
|asp.net|postback|
Is it possible to to programmatically trigger a postback from server code in ASP.NET? I know that it is possible to do a Response.Redirect or Server.Transfer to redirect to a page, but is there a way to trigger a postback to the same page in server code (_i.e._ without using javascript trickery to submit a form)?
I'm not aware of any specific flag that does exactly what you want, but <pre>--print-data-base</pre> sounds like it might be useful.
At the end of the day this is a question that only you can answer for yourself. Based on the fact that you said "I can't see a reason why I would ever choose to use shell scripting , ..." then it's probably the case that you should never choose it right now. But if I were you I would pick a scripting language lik...
How about using Linq to NHibernate as discussed in <a href="http://www.ayende.com/Blog/archive/2007/03/20/Linq-For-NHibernate-Orderring-and-Paging.aspx">this blog post</a> by Ayende? Code Sample: (from c in nwnd.Customers select c.CustomerID) .Skip(10).Take(10).ToList();
How about using Linq to NHibernate as discussed in <a href="http://www.ayende.com/Blog/archive/2007/03/20/Linq-For-NHibernate-Orderring-and-Paging.aspx">this blog post</a> by Ayende? Code Sample: (from c in nwnd.Customers select c.CustomerID) .Skip(10).Take(10).ToList(); And here is a detaile...
You can [set up prerequisites in a clickonce app][1], which would check for specific assemblies in the GAC before allowing users to install. You would still need to manually install an app that includes the required office dll outside of ClickOnce, but you would at least avoid throwing errors. [1]: http://msdn....
The official answer is no, there is not a dedicated Mac client, other than Safari :) There's a [command line version][1] that runs on Linux, Windows, and Mac. There are also plans for an iPhone version although I'm not technically supposed to announce features before they are done or even spec'd so pretend I didn...
What is the correct .NET exception to throw when try to insert a duplicate object into a collection?
|c#|exception|collections|
I have an Asset object that has a property AssignedSoftware, which is a collection. I want to make sure that the same piece of Software is not assigned to an Asset more than once. In Add method I check to see if the Software already exist, and if it does, I want to throw an exception. Is there a standard .NET...
Is it possible to build MSBuild files (visual studio sln) from the command line in Mono?
|mono|
Is it possible to build Visual Studio solutions without having to fire up MonoDevelop?
This can be done using the following script tag: <pre><code> &lt;script&gt; function pageLoad() { $find('TextBox1_DropDownExtender')._dropWrapperHoverBehavior_onhover(); $find('TextBox1_DropDownExtender').unhover = VisibleMe; } function VisibleMe() { $find('Te...
In C++, the standard does not define a divide-by-zero exception, and implementations tend to not throw them.
As you've probably discovered, [Word has events][1], but they're for really coarse actions like a document open or a switch to another document. I'm guessing MS did this intentionally to prevent a crappy macro from slowing down typing. In short, there's no great way to do what you want. [A Word MVP confirms that i...
Can only guess with seeing your output. A few suggestions: If you are using the DrawTextEx function, have you have experimented with DT_INTERNAL et al? Are you accidentally putting in a blank image/icon. Does it look ok in classic screen mode? If so I would look at XP Theme functions to see if some thing...
Can only guess without seeing your output. A few suggestions: If you are using the DrawTextEx function, have you have experimented with DT_INTERNAL et al? Are you accidentally putting in a blank image/icon. Does it look ok in classic screen mode? If so I would look at XP Theme functions to see if some th...
Can only guess without seeing your output. A few suggestions: If you are using the DrawTextEx function, have you have experimented with DT_INTERNAL et al? Are you accidentally putting in a blank image/icon. Does it look ok in classic screen mode? If so I would look at XP Theme functions to see if some th...
Determine file type of an image
|.net|image|mime-types|content-type|
I'm downloading some images from a service that doesn't always include a content-type and doesn't provide an extension for the file I'm downloading (ugh, don't ask). What's the best way to determine the image format in .NET? The application that is reading these downloaded images needs to have a proper file exten...
There is no reason you cannot have a script tag in the body, even though it is preferable for it to be in the head. Just emit the script tag before you emit your tag's markup. The only thing to consider is that you do not want to include the script more than once if you use the jsp tag on the page more than once. The ...
I think I've worked out why - the route includes {year} so the generated routes always will too.. If anyone can confirm this?
Cycle count measurement
|profiling|
I have a MS Visual Studio 2005 application solution. All the code is in C. I want to measure the number of cycles taken for execution by particular functions. Is there any Win32 API which i can use to get the cycle count. I have used gettimeofday() to get time in micro secs, but i want to know the cycles consumed? ...
By using Eclipse with the ActionScript plugin you get full code hinting in the same format that you do with intellisense. Or you can use [FlashDevelop][1] that has both intellisense and can [debug (trace) your code][2]. [1]: http://www.flashdevelop.org/community/ [2]: http://www.flashdevelop.org/community...
It's not clear why you need a bridge language. Why don't you start working with C directly? C is a very simple language itself. I think that hardest part for C learner is pointers and everything else related to memory management. Also C lang is oriented on structured programming, so you will need to learn how to implem...
It's not clear why you need a bridge language. Why don't you start working with C directly? C is a very simple language itself. I think that hardest part for C learner is pointers and everything else related to memory management. Also C lang is oriented on structured programming, so you will need to learn how to implem...
After reading through this twice, I'm not quite sure what's wrong. Can you provide the actual route, and the actual usage, rather than samples?
You have a couple problems, I think. First, your route doesn't have a default value for "year", so the URL "/News.mvc/Archive" is actually not valid for routing purposes. Second, you're expect form values to show up as route parameters, but that's not how HTML works. If you use a plain form with a select and a su...
|javascript|jquery|prototype|
I have written a site in Prototype but want to switch to jQuery. Any ideas on how best make the switch?
Best way to convert a Ruby string range to a Range object
|ruby|
I have some Ruby code which takes dates on the command line in the format: -d 20080101,20080201..20080229,20080301 Which means I want to run for all dates between 20080201 and 20080229 (inclusive) and the other dates present in the list. Given I can get the string 20080201..20080229 what is the best way to con...
I have some Ruby code which takes dates on the command line in the format: -d 20080101,20080201..20080229,20080301 Which means I want to run for all dates between 20080201 and 20080229 (inclusive) and the other dates present in the list. Given I can get the string 20080201..20080229 what is the best way to con...
I'd second Gishu's point that there's another way. Wouldn't it be better to abstact the common/"public" part of the EXE out into DLL create a wrapper EXE to run it? This is certainly the more usual pattern of development. Only the stuff that you wish to consume would go into the DLL, and the EXE would do all the stu...
An empty list is itself considered false in true value testing (see [python documentation][1]): a = [] if a: print "not empty" [1]: http://docs.python.org/lib/truth.html
An empty list is itself considered false in true value testing (see [python documentation][1]): a = [] if a: print "not empty" @Daren Thomas > EDIT: Another point against testing > the empty list as False: What about > polymorphism? You shouldn't depend on > a list being a list. It should j...
Personally, I like to take things in steps, so I would start by using both, like this: jQuery.noConflict(); // Put all your code in your document ready area jQuery(document).ready(function($){ // Do jQuery stuff using $ $("div").hide(); }); // Use Prototype...
What's the best way to combine results sets from disparate data sources in SSRS? In my particular example, I need to write a report that pulls data from SQL Server and combines it with another set of data that comes from a DB2 database. In the end, I need to join these separate data sets together so I have one comb...
A closure is a function that can reference state in another function. For example, in Python, this uses the closure "inner": def outer (a): b = "variable in outer()" def inner (c): print a, b, c return inner # Now the return value from outer() can be saved for l...
A good summary is available in [Implementation Strategies for First-Class Continuations][1], an article by Clinger, Hartheimer, and Ost. I recommend looking at Chez Scheme's implementation in particular. Stack copying isn't that complex and there are a number of well-understood techniques available to improve perfo...
Unit tests in Python
|python|unit-testing|
Does Python have a unit testing framework compatible with the standard xUnit style of test framework? If so, what is it, where is it, and is it any good?
Python has several testing frameworks, including `unittest`, `doctest`, and `nose`. The most xUnit-like is `unittest`, which is documented on Python.org. * [`unittest` documentation](http://docs.python.org/lib/module-unittest.html) * [`doctest` documentation](http://docs.python.org/lib/module-doctest.html)
[Martin Fowler][1] is currently writing a book on DSL. Here is a [presentation][2] he gave on the topic. [1]: http://www.martinfowler.com/dslwip/ [2]: http://www.infoq.com/presentations/domain-specific-languages
In the past, I’ve used the profiler that ships with [Visual Studio Team System][1]. [1]: http://en.wikipedia.org/wiki/VSTS_Profiler
I second that. Krypton all the way. Some of their controls actually outperform the same Telerik control, too.
What we're looking at here is called "data remanence." In fact, most of the technologies that overwrite repeatedly are (harmlessly) overdoing what's actually necessary. There have been attempts to recover data from disks that have had data overwritten and with the exception of a few lab cases, there are really no exam...
What we're looking at here is called "data remanence." In fact, most of the technologies that overwrite repeatedly are (harmlessly) doing more than what's actually necessary. There have been attempts to recover data from disks that have had data overwritten and with the exception of a few lab cases, there are really n...
Shift-Delete also works. Select a line and hit Shift-Delete it will remove the line and place that line in your clipboard.
There is a difference between early performance optimization and using a best practice type of rule. If you are creating new tables where you will always have a fixed length field, it makes sense to use CHAR, you should be using it in that case. This isn't early optimization, but rather implementing a rule of thumb (...
I don't think this is best practice but it should work if you put it in an include file that's included everywhere the function you want to change is called: #define CreateFile MyCreateFile HRESULT MyCreateFile(whatever the params are); Implementation of MyCreateFile looks something like this: #...
Yes global primitives are initialized to NULL. Example: int x; int main(int argc, char**argv) { assert(x == 0); int y; //assert(y == 0); <-- wrong can't assume this. } You cannot make any assumptions about classes, structs, arrays, blocks of memory on the hea...
You could try setting up a email client to sent email through your server, from an email address that isn't hosted on the same server. If you can successfuly send mail, from an email address at a different domain, without entering a login and password for your SMTP server, then it's probably an open relay.
Eh? As your link tells you, register for the site and it will give you an address @abuse.net, valid for 24 hours. Enter that address into the testing form. If your abuse.net account receives the test email, you have an open relay.
How about [Facebook's Thrift](http://incubator.apache.org/thrift/)? > Thrift is a software framework for scalable cross-language services development. It combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, ...
If you're trying to intercept calls to these APIs from another application, consider [Detours](http://research.microsoft.com/sn/detours/).
Remember that serialized classes must have default (i.e. parameterless) constructors. If you have no constructor at all, that's fine; but if you have a constructor with a parameter, you'll need to add the default one too.
Asp.net Postbacks are initiated from the client (typically form submission). I am not sure what you are trying to achieve. Some of the server side [page lifecyle][1] events are already executed and what you are trying to do is raise the previous event handlers again. [1]: http://www.15seconds.com/issue/020102.ht...
Coming from the embedded world... Your code gets compiled into three types of memory: 1. .data: initialized memory 2. .text: constants and code 3. .bss: uninitialized memory (initialized to 0 in C++ if not explicitly initialized) Globals go in .data if initialized. If not they are placed in .bs...
Track when user hits back button on the browser
|javascript|php|browser|
Is it possible to detect when the user clicks on the browser's back button? I have an Ajax application and if I can detect when the user clicks on the back button I can display the appropriate data back Any solution using PHP, JavaScript is preferable. Hell a solution in any language is fine, just need something...
Try loading the stream into a System.IO.BinaryReader. Then you will need to refer to the specifications for each image format you need, and load the header byte by byte to compare against the specifications. For example here are the [PNG specifications](http://www.libpng.org/pub/png/pngdocs.html) Added: The a...
I have built stored procedure based applications in the past. In your case there maybe a way to keep authentication at the database layer and have your business logic in C#. Use views to limit data (you only see the rows you have authority to). These views can be used in LINQ with the same ease as tables. You set y...
If you are using a strong hash algorithm (SHA-2) and a strong Encryption algorithm (AES), you will do fine with this approach.
Php function argument error suppression
|php|error-handling|error-suppression|
I'm pretty sure the answer to this question is no, but in case there's some PHP guru I've written a convenience function that checks to see if a variable has a non-empty value if so return that value otherwise use the other variable: function defaultValue($value, $default) { return $value ? $value : $de...
I'm pretty sure the answer to this question is no, but in case there's some PHP guru I've written a convenience function that checks to see if a variable has a non-empty value if so return that value otherwise use the other variable: function defaultValue($value, $default) { return $value ? $value : $de...
I put everything except the JDK and IDE in source control. Tony's philosophy is sound. Don't forget database creation scripts and data structure update scripts. Before wikis came out, I used to even store our documentation in source control.
We store the libraries in source control because we want to be able to build a project by simply checking out the source code and running the build script. If you aren't able to get latest and build in one step then you're only going to run into problems later on.
Populating a list of integers in .NET
|c#|.net|list|integer|
I need a list of integers from 1 to x where x is set by the user. I could build it with a for loop eg assuming x is an integer set previously: List<int> iList = new List<int>(); for (int i = 1; i <= x; i++) { iList.Add(i); } This seems dumb, surely there's a more elegant way to do thi...
Store third party libraries in source control so they are available if you check your code out to a new development environment. Any "includes" or build commands that you may have in build scripts should also reference these "local" copies. As well as ensuring that third party code or libraries that you depend on a...
I'm feeling your pain, I also learned PHP first and I'm trying to learn C++, it's not easy, and I am really struggling, It's been 2 years since I started on c++ and Still the extent of what I can do is cout, cin, and math. If anyone reads this and wonders where to start, START LOWER.
If your using .Net 3.5, [Enumerable.Range][1] is what you need. > Generates a sequence of integral > numbers within a specified range. [1]: http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx
Both Intel and AMD offer windows libraries and tools to access the performance counters on their cpus. These give access not only to cycle counts, but also to cache line hits and misses and TLB flush counts. The Intel tools are marketed under the name VTune, while AMD calls theirs CodeAnalyst.
How can I map a list of strings to my entity using NHibernate?