instruction stringlengths 0 30k ⌀ |
|---|
As always: look up at [C++ FAQ lite: virtual functions](http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8).
It will explain not only "virtual constructor" but destructors/functions too!
This of course, if you wanted C++ in the first place... |
GetHashCode's result is supposed to be:
1. As fast as possible.
2. As unique as possible.
Bearing those in mind, I would go with something like this:
((ulong)str1.GetHashCode() | ((ulong)str2.GetHashCode() << 32)).GetHashCode() |
GetHashCode's result is supposed to be:
1. As fast as possible.
2. As unique as possible.
Bearing those in mind, I would go with something like this:
if (str1 == null)
if (str2 == null)
return 0;
else
return str2.GetHashCode();
else
if (str2 == nu... |
If you already know a bit of perl, <a href="http://www.perlmonks.org/">PerlMonks</a> is a great online resource. You can ask questions in their <a href="http://www.perlmonks.org/?node=Seekers%20of%20Perl%20Wisdom">Seekers of Perl Wisdom</a> section and the answers are often of very high quality. Many people who keep ... |
|java|web-services|jsf|paging| |
I have a JSF application that I am converting over to use webservices instead of straight up database queries. There are some extremely long lists that *before* could be returned easily with a simple sql query. I'd like to figured out how implement the paging using JSF/web services. Is there a good design pattern for d... |
There are certainly ways to do this -- this is how we develop for the PS3 with sony's toolchain (which is based on gcc). I don't know exactly how that works, but it integrates pretty seamlessly into VS.
I think what you need to do is either set it up to build with a makefile (probably easiest) or to write a wrapper ... |
Originally, it was envisioned that professional designers would work in Expression Blend, and developers would work in Visual Studio, making changes to a single shared set of source files. While it is certainly possible to do that (so long as you are careful to check regularly that you haven't broken something expected... |
Stored procedures reverse engineering |
|database|stored-procedures|legacy|reverse-engineering| |
We're having problem with a huge number of legacy stored procedures at work. Do you guys recommend any tool the can help better understand those procedures? Some kind of reverse engineering that indentifies inter-procedure dependencies and/or procedure vs. tables dependencies. Can be a free or commercial tool.
Thank... |
What's the best way to hash a url in ruby? |
|ruby| |
I'm writing a web app that points to external links. I'm looking to create a non-sequential, non-guessable id for each document that I can use in the URL. I did the obvious thing: treating the url as a string and str#crypt on it, but that seems to choke on any non-alphanumberic characters, like the slashes, dots and ... |
The other approach is to use a 'flat', C-style API. You might as well use `extern "C"` to prevent accidental overloading. Use a DEF file to explicitly name the exported functions, so they're definitely not decorated in any way (C++ functions are 'decorated' with an encoding of the parameter types in the export table).
... |
Using the disable-output-escaping attribute (a boolean) is probably the easiest way of accomplishing this. Notice that you can use this not only on <xsl:value-of/> but also with <xsl:text>, which might be cleaner, depending on your specific case.
Here's the relevant part of the spec: [http://www.w3.org/... |
Cocoa Programming for Mac OS X, by Aaron Hillegass.
|
If you ensure that the field is placed in the same place in each such structure, you can simply cast a pointer to get at the field. This technique is used in lots of low level system libraries e.g. BSD sockets.
struct person {
int index;
}
struct clown {
int index;
char *hat;... |
If you ensure that the field is placed in the same place in each such structure, you can simply cast a pointer to get at the field. This technique is used in lots of low level system libraries e.g. BSD sockets.
struct person {
int index;
};
struct clown {
int index;
char *h... |
Strictly it should match
[A-Za-z][-A-Za-z0-9_:.]+
But jquery seams to have problems with colons so it might be better to avoid that. |
Logging image downloads |
|download|session| |
I'm trying to find a way of finding out who is downloading what image from an image gallery. Users can download using a button beside the thumbnail or right click and use the "save link as" Is it possible to relate a user session or ID to a "save link as" action from all browsers using either PHP or JavaScript. |
What is the minimum client footprint required to connect C# to an Oracle database? |
|c#|oracle-database|client| |
I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008) by downloading and installing the client administration tools and Visual Studio 2008 on my laptop.
The installation footprint for Oracle Client tools was over 200Mb, and quite long winded.
Does anyone know what the minimum work... |
Here is one that will give you a visual file chooser to pick the folder you want to save the files to and also lets you choose the CSV delimiter (I use pipes '|' because my fields contain commas and I don't want to deal with quotes):
<code>
' ---------------------- Directory Choosing Helper Functions --------------... |
[XML Copy Editor][1] is free and GPL
[1]: http://xml-copy-editor.sourceforge.net/ |
Get the current mouse coordinates |
|c++|winapi|mouse|lcd| |
I have an iMac, and I want to be able to turn off the monitor when I go to sleep,. Alas, the iMac has no switch for this. I do not want to put the iMac into sleep mode, i want to write a "expose" like application or service, which when the mouse is put into the upper left hand corner of my screen, the display will sl... |
Best way for a Swing GUI to communicate with domain logic? |
|java|user-interface|swing| |
I have some domain logic implemented in a number of POJOs. I want to write a Swing user interface to allow the user to initiate and see the results of various domain actions.
What's the best pattern/framework/library for communications between the UI and the domain? This boils down into:
- the UI being able to ... |
WPF: Org Chart TreeView Conditional Formatting |
|wpf|xaml| |
The company has the traditional complex organizational structure, defining the amount of levels using the letter 'n' rather than an actual number. I will try and express the structure I'm trying to achieve in mono-spaced font:
Alice
,--------|-------,------,------,
Bob Fred Jack K... |
Yes - it resolves down to file access permissions as well as read/write. You can't execute any type of data update stuff (you'll get "operation requires an updateable query") unless the user supplies credentials that allow them to write, or you allow write on the file.
Running a query requires only read access. |
|sql-server|database| |
I need to copy about 40 databases from one server to another. The new databases should have new names, but all the same tables, data and indexes as the original databases. So far I've been:
1) creating each destination database
2) using the "[Tasks->Export Data][1]" command to create and populate tables for e... |
There are some pretty serious concerns here for how to send email automatically, and here are a few:
Use an email library. Python includes one called 'email'. This is your friend, it will stop you from doing anything tragically wrong. Read an example from <a href="http://docs.python.org/lib/node161.html">the Python ... |
Backup -> Restore is the simplest, if not to use the replication. |
try using JCalendar |
Try
<pre><code>
[ DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden ),
EditorBrowsable( EditorBrowsableState.Advanced ),
Browsable( false ) ]
public BindingContext BindingContext {
...
}
[ ParenthesizePropertyName( true ),
RefreshProperties( RefreshProperties.All ),
Designe... |
I have used a commercial tool called [QAC][1]. The tool is able to enforce [MISRA][2]
It has a command-line interface, so you can set it up to run from a automated build environment. The rules to be applied are configurable, but expect to have someone spending some time setting it u. The MISRA enforcement is pret... |
At it's very basic level it will be using `createElement` to create the elements to insert into the page and `appendChild` or `insertBefore` to insert them into the page. |
Use [Digest::MD5][1] from Ruby's standard library:
Digest::MD5.hexdigest(my_url)
[1]: http://ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html |
I'd advise against using `hook_nodeapi` for that. Adding CSS and Javascript is related to layout so `hook_nodeapi` is not the place for it: use themeing. This way, you *can* override those files when you're going to develop a new theme. Doing that with the nodeapi approach would be a bit harder (you'd have to search th... |
It sounds like you're asking about how to use source control to manage releases.
Here's some general guidance that's not specific to websites:
- Use a local copy for developing changes
- Compile (if applicable) and test your changes before checking in
- Run automated builds and tests as often as possible ... |
Here is one that will give you a visual file chooser to pick the folder you want to save the files to and also lets you choose the CSV delimiter (I use pipes '|' because my fields contain commas and I don't want to deal with quotes):
' ---------------------- Directory Choosing Helper Functions ------------------... |
<pre>
my @l1 = qw/1 2 3/;
my @l2 = qw/7 8 9/;
my @out;
push @out, shift @l1, shift @l2 while ( @l1 || @l2 );
</pre>
If the lists are a different length, this will put 'undef' in the extra slots but you can easily remedy this if you don't wish to do this. Something like ( @l1[0] && shift @l1 ) would do it.
Hop... |
You can cheat it a little (and I stress a little) by using java.lang.reflect.Proxy instances.
This really just allows you to add extra interfaces and delegate their calls to another instance at runtime.
As someone who mentors and tutors new developers I would be horrified if somebody showed me code that did this... |
From the HTML 4 spec...
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
EDIT: d'oh! Beaten to the button, again! |
I learned from the [Python Tutorial][1]!
[1]: http://docs.python.org/tut/tut.html |
+1 for [Dive Into Python][1]
[1]: http://www.diveintopython.org/ "Dive Into Python" |
There's a Rails plugin called [WebORB for Ruby on Rails][1] which uses remoting with AMF.
[1]: http://www.themidnightcoders.com/weborb/rubyonrails/index.htm |
I don't think the real difference became clear in the above answers.
First to get the terms right:
- A nested class is a class which is contained in another class at the source code level.
- It is static if you declare it with the **static** modifier.
- A non-static nested class is called inner class. (I s... |
public override int GetHashCode()
{
unchecked
{
return(str1 != null ? str1.GetHashCode() : 0) ^ (str2 != null ? str2.GetHashCode() : 0);
}
}
|
If you need to learn python from scratch - you can start here: http://docs.python.org/tut/tut.html - good begginers guide
If you need to extend your knowledge - continue here http://diveintopython.org/ - good intermediate level book
If you need perfect skills - complete this http://www.pythonchallenge.com/ - outs... |
There is [WebORB][1] or [RubyAMF][2] which you can use to respond in AMF from Rails, the approaches are a bit different for each one so it depends on your needs. RubyAMF is discussed in the closing chapters of the [Flexible Rails][3] eBook which is a good resource on using Rails with Flex.
[1]: http://www.themid... |
The constructor can not be virtual by definition. At the time of constructor call there is no object created yet, so the polymorphism does not make any sense. |
Good pattern or framework for adding auditing to an existing app? |
|java|jakarta-ee|aop|audit|crud| |
I have an existing J2EE enterprise application to which I need to add auditing, i.e. be able to record CRUD operations on several important domain types (Employee, AdministratorRights, etc.).
The application has a standard n-tier architecture:
- Web interface
- Business operations encapsulated within a mixtu... |
I'm not a C# programmer, but the way you've asked this question is slightly misleading. The only way to know when your data has been "received", for any useful definition of "received", is to have a specific acknowledgment message in your protocol which indicates the data has been fully processed.
The data does not... |
What's the best way to do fixed-point math? |
|c++|fixed-point| |
I need to speed up a program for the Nintendo DS which doesn't have an FPU, so I need to change floating-point math (which is emulated and slow) to fixed-point.
How I started was I changed floats to ints and whenever I needed to convert them, I used **x>>8** to convert the fixed-point variable x to the actual number... |
You can do this with a parameterized macro but most coding policies will frown on that.
<pre><code>
#include <stdio.h>
#define getfield(s, name) ((s).name)
typedef struct{
int x;
}Bob;
typedef struct{
int y;
}Fred;
int main(int argc, char**argv){
Bob b;
b.x=6;
Fred f;
f.y=7;
... |
If you're not executing the code in the context of a browser, why do the tests need to be written in Javascript? It's hard to understand the bigger picture of what you're trying to accomplish here. |
One downside is that server side controls can get renamed, depending on their containers. For example, you might have:
<asp:panel id="panel1" runat="server"></asp:panel>
This may be rendered to the page as:
<div id="ctl00$panel1"></div>
So if you write jQuery using `$('#panel1')` as a selector, it w... |
That document is a little more about Solaris threading than the Java threading model. All JVMs call the native thread API of the OS they're written for so there is always one Java thread for an OS thread. The diagram in the document shows that it's not until the threads are in the OS space that they change. Each OS can... |
The closest thing to a real answer to you question is to use the Enumerable method each_with_index instead of each, thusly:
my_array = [foo, baz, bar]
my_array.each_with_index do |item, index|
if item.class != Array
puts "#{my_array[index]} wasn't an Array. It was a/an #{item.class}"
... |
Well, I made a page like this:
<html>
<body>
<script type="text/javascript">
var a = new function() {
alert("method 1");
return "test";
};
var b = (function() {
alert("method 2");
return "test";
})();
alert(a); //a is a ... |
Brian gives a nice solution for converting it to a strongly typed collection.
Most of the CSV parsing methods given don't take into account escaping fields or some of the other subtleties of CSV files (like trimming fields). Here is the code I personally use. It's a bit rough around the edges and has pretty much no ... |
Backup the databases using the standard SQL backup tool in Enterprise Manager, then when you restore on the second server you can specify the name of the new database.
This is the best way to maintain the schema in its entirety. |
use backups to restore the databases to the new server with the new names. |
It seems that this is not doable in a cross-platform fashion without using the native interfaces.
On Windows, you can use the free [JIntellitype](http://melloware.com/products/jintellitype/index.html) library. |
SQL Profiler to get the query and the time, and also Execution Path in Query analyzer to see where the bottlenecks are. |
I think adding people to a team may speed up a project more than adding them to the project itself.
I often run into the problem of having too many concurrent projects. Any one of those projects could be completed faster if I could focus on that project alone. By adding team members, I could transition off other... |
Maybe the easiest is to detach/reattach. Right-click in the server manager on the DB, tasks --> detach. Then copy the MDF/LDF files to the new server and then reattach by clicking on the server icon and tasks-->attach. It will ask you for the MDF file - make sure the name etc is accurate.
|
Wildcards for resources in a Tomcat Servlet's context.xml |
|java|tomcat| |
I'm not overly familiar with Tomcat, but my team has inherited a complex project that revolves around a Java Servlet being hosted in Tomcat across many servers. Custom configuration management software is used to write out the server.xml, and various resources (connection pools, beans, server variables, etc) written in... |
You can take the hybrid approach of iterating through the bytes of the int, use a lookup table to determine the indexes of the set bits in each byte (broken up into nibbles). Then you would need to add an offset to the indexes to reflect its position in the integer.
i.e. Suppose you started with the MSB of a 32 bit ... |
Not really the answer you seem to be looking for, but cant you do this via the power save option and/or the screen saver - can it be set to nothing. |
In Leopard, you can just go to "System Preferences" and "Desktop & Screensaver". Click the Screensaver tab, click "Hot Corners", selected the corner you want to change, then chose "Sleep display". Does that not work? |
Check out the [Wikipedia article][1] on HMMs: they have a pretty solid example after all the theory stuff. If you want to get some practice on it, [Ruby Quiz][2] has some great Markov model implementations that you can try changing to be HMMs.
[1]: http://en.wikipedia.org/wiki/Hidden_Markov_model#A_concrete_exam... |
The original query was how to return the WidgetHolder as const if the containing class was const. C++ uses const as part of the function signature and therefore you can have const and none const versions of the same function. The none const one is called when the instance is none const, and the const one is called when... |
What you have is fine. A case statement would also work equally well. It's just a matter of how expressive you wish to be.
Your solution, indexing, works fine if the select encodings don't have any special meaning (a memory address selector for example). If the select encodings do have some special semantic mea... |
Although I haven't done it, you can probably use the WebBrowser control found in WPF 3.5 sp1 to wrap your Flash content within WPF. I'm not sure how the transparency will be affected though. |
Sounds like web service is the way to go. You could do something like the following:
- Have the WebForms app create some data in its database with a key of some kind associated to it.
- Pass that key in the URL to the NVelocity MVC application.
- Allow the NVMVC application to call a web service (REST,XML-RP... |
It has to do with the way the different compilers perform name-mangling. A C++ compiler will mangle the name of a symbol exported from the header file in a completely different way than a C compiler would, so when you try to link, you would get a linker error saying there were missing symbols.
To resolve this, we te... |
We also have a database system that is used exclusively within the organisation and use Window NT logins. This function returns the current users login name:
CREATE FUNCTION dbo.UserName() RETURNS varchar(50)
AS
BEGIN
RETURN (SELECT nt_username FROM master.dbo.sysprocesses WHERE spid =... |
We use stripes now on all our production sites, and have been for about a year now. It is an awesome product compared to struts, which we used to use before that. Just the fact that there are literally no XML config files and that you can set it all up with a minimal amount of classes and annotations is awesome.
In ... |
We use stripes now on all our production sites, and have been for about a year now. It is an awesome product compared to struts, which we used to use before that. Just the fact that there are literally no XML config files and that you can set it all up with a minimal amount of classes and annotations is awesome.
In ... |
[The python manual][1]
[1]: http://www.python.org/doc/current/tut/tut.html
Its a bit long winded sometimes but it tells you all you need to know to get going. |
Rather than using xcopy we managed to use the -source:dirpath command with UNC addresses to the servers with msdeploy. The key was the ignoreAcls=true and removing calls to username and password in the msdeploy string:
msdeploy -verb:sync -source:dirpath=\\build\e$\app -dest:dirpath=\\live\d$\app,ignoreAcls=true... |
You need to be careful to distinguish interface inheritance (essentially inheritance of a contract to provide particular facilities) from implementation inheritance (inheritance of implementation mechanisms).
Java provides interface inheritance by the *implements* mechanism and you *can* have multiple interface inh... |
Refactoring two basic classes |