instruction stringlengths 0 30k ⌀ |
|---|
You have described a [knapsack problem](http://en.wikipedia.org/wiki/Knapsack_problem), the only true solution is brute force. There are some approximation solutions which are faster, but they might not fit your needs. |
What I do is keep feature ideas on index cards and post the cards somewhere visible. When someone asks, "Could it also do XXX?" I write a new card. This is a better relationship building move than screaming "NO!" :-) It also has the advantage of not losing potentially good ideas. OTOH, I'm under no compulsion to implem... |
Here's an example for Gmail smtp:
http://tovare.com/articles/learnhowtosendemailviagmailfromjavain120seconds/
/*
*
*/
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
import com.sun.mail... |
Since you have dynamic values, you need to use an IF or CASE for the columns to be updated. It gets kinda ugly, but it should work.
Using your example, you could do it like:
<pre>
UPDATE table SET Col1 = CASE id
WHEN 1 THEN 1
WHEN 2 THEN 2
... |
php problem |
|php|-get| |
this is the problem i am having
i get data from a flash file and i see that on the top in the URL and then i run this loop.
foreach ($_GET as $field => $label)
{
$datarray[]=$_GET[$field];
echo "$_GET[$field]";
echo "<br>";
}
print_r($datarray);
----------------------------------------------------
... |
foreach ($_GET as $field => $label)
{
$datarray[]=$_GET[$field];
echo "$_GET[$field]";
echo "<br>";
}
print_r($datarray);
----------------------------------------------------
This is the output I am getting. I see the data is there in datarray but when
I echo $... |
Php $_GET issue |
|php|-get|arrays| |
|php|arrays| |
depends. it is supposed to be the full URL, but some browsers (Opera?) cache urls with different params.
best bet is to change the name of the file.
There is a very clever solution here (uses PHP, Apache)
[http://verens.com/archives/2008/04/09/javascript-cache-problem-solved/][1]
[1]: http://verens.com/... |
depends. it is supposed to be the full URL, but some browsers (Opera, Safari[2]) apply a different cache strategy for urls with different params.
**best bet is to change the name of the file**.
There is a very clever solution here (uses PHP, Apache)
[http://verens.com/archives/2008/04/09/javascript-cache-probl... |
To the best of my understanding, time.clock() has as much precision as your system will allow it. |
The contents of each window are directX surfaces and are only assembled by the window manager in the graphics card. You'd not be able to capture this unless you switch off the new interface (DWM) or code specifically for screen capture from the DWM.
Wikipedia has a good description of the [Desktop Window Manager ... |
There are several approaches here.
1) Create one table per pick list. Each of the tables would have the ID and Name columns; the value that was picked by the user would be stored based on the ID of the item that was selected.
2) Create a single table with all pick lists. Columns: ID; list ID (or list type); Nam... |
the add should probably look like this (add the '' around the string and add a ; to the end of the javascript statement).
lb.Attributes.Add("onclick", "setDDL('" + lb.Text + "');");
OR!
set the [OnClientClick property][1] on the linkbutton.
[1]: http://msdn.microsoft.com/en-us/library/system.web.ui... |
If you want to go big, choose Django and you are set. But if you want just to learn, roll your own framework using already mentioned [WebOb](http://pythonpaste.org/webob/) - this can be really fun and I am sure you'll learn much more (plus you can use components you like: template system, url dispatcher, database layer... |
Well, you could do something like this:
PickListContent
IdList IdPick Text
1 1 Apples
1 2 Oranges
1 3 Pears
2 1 Dogs
2 2 Cats
and optionally..
PickList
Id Description
1 Fruit
2 ... |
Create your own batch file (say clenv.bat), and call that instead of cl:
@echo off
:: Load compilation environment
call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
:: Invoke compiler with any options passed to this batch file
"C:\Program Files\Microsoft Visual Studio 9.0\V... |
One scary thing on singletons in for instance Java is that you *can* end up with multiple instances of the same singleton in some cases. The JVM uniquely identifies based on *two* elements: A class' fully qualified name, and the classloader responsible for loading it.
That means the same class can be loaded by two... |
I have multiple settings files.
* `settings_local.py` - host-specific configuration, such as database name, file paths, etc.
* `settings_development.py` - configuration used for development, e.g. `DEBUG = True`.
* `settings_production.py` - configuration used for production, e.g. `SERVER_EMAIL`.
I tie these all... |
Just use Resharper to create you Equals & GetHashCode methods. It creates the most comprehensive code for this purpose. |
Just use Resharper to create you Equals & GetHashCode methods. It creates the most comprehensive code for this purpose.
**Update**
I didn't post it on purpose - I prefer people to use Resharper's function instead of copy-pasting, because the code changes from class to class. As for developing C# without Resharper -... |
James Shora has two great links:
For hardware
<http://jamesshore.com/Blog/Continuous-Integration-on-a-Dollar-a-Day.html>
For "Humanware"
<http://jamesshore.com/Change-Diary/>
( The history of how he did it. The read is long but changing an organization is harder )
|
To make your first into one statement:
(0...8).collect { |n| value << (65 + rand(25)).chr }.join() |
That url does not work any more, so it's hard to test this. I wondered if this would work, and it turned up someone who has experience with it at [bytes.com][1]. If you put it up again, I can see if this really works with yours.
**Joerg Jooss** wrote: (*slightly modified for brevity* )
string responseTe... |
Here's an example for Gmail smtp:
http://tovare.com/articles/learnhowtosendemailviagmailfromjavain120seconds/
/*
*
*/
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.inte... |
You can do tons of things with pipes. For example for sites like digg or reddit, you can make one to bypass the site and go directly to the linked article (rewriting the RSS).
I like also to filter webcomics' feeds to keep just the comics, and then mix them all in only one feed |
What user account would you recommend running the SQL Server Express 2008 services in a development environment? |
|sql-server|installation|development-environment| |
The SQL Server Express 2008 setup allow you to assign different user account for each service.
For a development environment, would you use a domain user, local user, NT Authority\NETWORK SERCVICE, NT Authority\Local System or some other account and why?
|
|sql-server|installation|development-environment|account| |
Google Authentication API is a token based system to authenticate a valid user. It does not expose any of other interface that allows to get account holder information back to authorizer. |
#include <boost/serialization/version.hpp>
:-) |
Assuming this is served through IIS, I would tell IIS to authenticate via the domain, but I would keep authorization (what roles a user is associated with, accessible functionality, etc) within the application itself.
You can retreive the username used to authenticate via
Trim(Request.ServerVariables("LOGO... |
It depends greatly on your application. For example, some applications consist mostly of GUI code that cannot be unit tested. |
Be careful. I haven't used an OPC API yet that properly conforms to any sort of calling conventions, particularily in the area of freeing memory (COM, as documented, or otherwise). Expect a month of debugging memory leaks. |
There are a variety of ways of achieving this goal, some are clearer than others. For each of my examples, 'True' means that the string passed is valid, 'False' means it contains invalid characters.
First of all, there's the naive approach:
import string
allowed = string.letters + string.digits + '_' + '... |
There are a variety of ways of achieving this goal, some are clearer than others. For each of my examples, 'True' means that the string passed is valid, 'False' means it contains invalid characters.
First of all, there's the naive approach:
import string
allowed = string.letters + string.digits + '_' + '... |
Tables are not *in general* easier or more maintanable than CSS, Howere there are a few *specific* layout-problems where tables are indeed the simplest and most flexible solution.
CSS is clearly preferable in cases where presentational markup and CSS supports the same kind of design, No-one in their right mind would... |
Tables are not *in general* easier or more maintanable than CSS, However there are a few *specific* layout-problems where tables are indeed the simplest and most flexible solution.
CSS is clearly preferable in cases where presentational markup and CSS supports the same kind of design, No-one in their right mind woul... |
A basic approach is to use two panels on the page - one for the first form and another for the second.
You can change the visibility property of these panels depending on which form you want to display (during page_load or any time before rendering). |
That url does not work any more, so it's hard to test this directly. I wondered if this would work, and google turned up someone who has experience with it at [bytes.com][1]. If you put your website up again, I can see if this really works there.
**Joerg Jooss** wrote: (*slightly modified for brevity* )
... |
I have two files. `settings_base.py` which contains common/default settings, and which is checked into source control. Each deployment has a separate `settings.py`, which executes `from settings_base import *` at the beginning and then overrides as needed. |
My [blog][1], of course, is quite interesting - but will not be to everyone. TestingReflections is nice because it aggregates a bunch of random test blogs, but the problem is that it aggregates the bad with the good. Many of the posts that make it to the site don't have much use.
It also depends on what you're looki... |
Pack your shared classes into a Library (a DLL) and from each site right-click on add reference and select the library that you have created. |
Try this. I think you have to set the GridView's PageIndex property manually.
protected void CustomerView_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
CustomerView.PageIndex = e.NewPageIndex;
CustomerView.DataSource = Customer.GetAll();
Cus... |
If your socket code has to run on a BlackBerry, you cannot using standard Java sockets. You have to use the J2ME Connector.open API for creating both types of sockets (those that initiate connections from the BlackBerry, and those that listen for connections/pushes on the BlackBerry). Have a look at the examples that c... |
I think you're thinking of <a href="http://docs.python.org/lib/module-exceptions.html">Exception</a>s. Replace the word Error in your description with Exception and you should be good to go :-) |
I have made the switch to SQLite and I feel _much_ better knowing it's in a database.
There are a lot of other benefits from this:
* Adding new items is really simple
* Sorting by multiple columns
* Removing duplicates with a unique index
I've created 2 views, one for unread items and one for all items... |
You will need to pass some structure to the data access layer that identifies the current "activity". You might already have an "Activity"-class that makes sense, you might use a Logger-instance as [Sunny suggested][1] or you might use a third structure to keep track of the activity-context.
In any case, since your ... |
You will need to pass some structure to the data access layer that identifies the current "activity". You might already have an "Activity"-class that makes sense, you might use a Logger-instance as [Sunny suggested][1] or you might use a third structure to keep track of the activity-context.
In any case, since your ... |
Assuming this is T-SQL, use DATEPART to compare the month and date separately.
http://msdn.microsoft.com/en-us/library/ms174420.aspx
Alternatively, subtract January 1st of the current year from everyone's birthday, and then compare using the year 1900 (or whatever your epoch year is). |
Take a look at the project [RExchange][1] on github.
[1]: http://github.com/intabulas/rexchange/tree/master "RExchange" |
there are existing tools that reverse db's into java (and probably other languages). consider using one of them and converting that to c++. |
I've recently done both in a project and found:
1. I prefer writing annotations to XML (plays well with static typing of Java, auto-complete in IDE, refactoring, etc). I like seeing the stuff all woven together rather than going back and forth between code and XML.
1. Encodes db information in your classes. S... |
If this were a perfect world, 100% of code would be covered by unit tests. However, since this is NOT a perfect world, it's a matter of what you have time for. As a result, I recommend focusing less on a specific percentage, and focusing more on the critical areas. If your code is well-written (or at least a reasonabl... |
You can create a partial class for your DataContext and use the Created or what have you partial method to setup the log to the console.out wrapped in an #if DEBUG.. this will help you to see the queries executed while debugging any instance of the datacontext you are using.
I have found this useful while debugging ... |
I don't think there can be such a B/W rule.<br>
Code should be reviewed, with particular attention to the critical details.<br>
However, if it hasn't been tested, it has a bug! |
What is a reasonable code coverage % for unit tests? |
|unit-testing|code-coverage| |
If you were to mandate a minimum percentage code-coverage for unit tests, perhaps even as a requirement for committing to a repository, what would it be? |
|unit-testing|code-coverage| |
What is a reasonable code coverage % for unit tests (and why)? |
|unit-testing|code-coverage| |
If you were to mandate a minimum percentage code-coverage for unit tests, perhaps even as a requirement for committing to a repository, what would it be?
Please explain how you arrived at your answer (since if all you did was pick a number, then I could have done that all by myself ;) |
Short answer: 60-80%
Long answer:
I think it totally depends on the nature of your project. I typically start a project by unit testing every practical piece. By the first "release" of the project you should have a pretty good base percentage based on the type of programming you are doing. At that point you can ... |
Depending on the criticality of the code, anywhere from 75%-85% is a good rule of thumb.
Shipping code should definitely be tested more thoroughly than in house utilities, etc. |
You might want to try using a custom Batcher by setting the hibernate.jdbc.factory_class property. Making sure hibernate won't check the update count of batch operations might fix your problem, you can achieve that by making your custom Batcher extend the class BatchingBatcher, and then overriding the method doExecuteB... |
Yes, your secret key appears to be missing. Without it, you will not be able to decrypt the files.
Do you have the key backed up somewhere?
Re-creating the keys, whether you use the same passphrase or not, will not work. Each key pair is unique. |
I would say: create a stored procedure, probably has the best performance.
Or if you have a maximum number of levels, you could create subqueries, but they will have a very poort performance.
(Or you could get MS SQL Server 2008 and get the new hierarchy functions... ;) ) |
I don't know if the following is correct, but I would say that in the case of an Address object, we want to use it as a Value Object instead of an Entity because changes to the entity would be reflected on all linked objects (a Person for instance).
Take this case: You are living in your house with some other people... |
You can have multiple forms, it's just only one form may have the runat="server" attribute.
There are a bunch of answers to getting paypal to work; but as it's a learning vehicle that may be cheating. In all honesty I'd look at the full blown paypal API rather than use the somewhat simplistic forms method (with the ... |
Maybe I'm misunderstanding the question, but can't you simply have 2 divs inside the form, where only one is visible at any time. e.g.
<form id="Form1" method="post" runat="server">
<div id="getUserInput" visible="true">
<asp:button id="btnSubmitFirst" />
</div>
<div id=... |
I initially tried this approach, but found it caused problems:
- When the presentation was used from a laptop not connected to the network.
- If the user did not have access to the UNC.
- If the flash file was renamed, moved or deleted.
I found a better approach was to embed the file into the Powerpoint f... |
Most of these solutions are close, but you have to remember a few extra scenarios. When working with birthdays and a sliding scale, you must be able to handle the transition into the next month.
For example Stephens example works great for birthdays up until the last 4 days of the month. Then you have a logic fau... |
Unfortunately, CSS Zen Garden can no longer be used as an example of good HTML/CSS design. Virtually all of their recent designs use graphics for section heading. These graphic files are specified in the CSS.
Hence, a website whose purpose is to show the advantage of keeping design out of content, now regularly co... |
C++ does begin/end/rbegin/rend execute in constant time for std::set, std::map, etc? |
|c++|stl| |
For data types such as std::set and std::map where lookup occurs in logarithmic time, is the implementation required to maintain the begin and end iterators? Does accessing begin and end imply a lookup that could occur in logarithmic time?
I have always assumed that begin and end always occur in constant time, howev... |
You also could look into temporarily dropping the unique index and adding it back when you're done. |
I'm wondering what could cause this. Aside from filesystem bugs, it could be caused by a non-ascii chararacter that got through somehow. In that case, use another language with easier string semantics to do the operation.
It would be interesting to see what would be the output of this ruby snippet:
ruby -e 'p... |
The best thing to do is to use the algorithm remove_if and isspace:
remove_if(str.begin(), str.end(), isspace);
Now the algorithm itself can't change the container(only modify the values), so it actually shuffles the values around and returns a pointer to where the end now should be. So we have to call string::... |
The best thing to do is to use the algorithm remove_if and isspace:
remove_if(str.begin(), str.end(), isspace);
Now the algorithm itself can't change the container(only modify the values), so it actually shuffles the values around and returns a pointer to where the end now should be. So we have to call string::... |
For most software development (think desktop applications) the answer is probably that you don't know and don't care.
In safety-critical systems (think nuclear power plants and commercial avionics) you *do* care and regulatory agencies will require you to prove it. In my experience, you can do this one of two ways:
... |
As Microsoft says,
> A common error in overloads of
> operator == is to use (a == b), (a ==
> null), or (b == null) to check for
> reference equality. This instead
> results in a call to the overloaded
> operator ==, causing an infinite loop.
> Use ReferenceEquals or cast the type
> to Object, to avoid the lo... |
Wrap the map in a DIV, give that DIV a z-index of 1. Wrap your drop-down in a DIV and give it a higher value. |
Not that I know of. I would just roll my own. It's not that hard to do, maybe something like this:
#!/usr/bin/env jruby
import java.sql.DriverManager
# TODO some magic to load the driver
conn = DriverManager.getConnection(ARGV[0], ARGV[1], ARGV[2])
res = conn.executeQuery ARGV[3]
... |
Not that I know of. I would just roll my own. It's not that hard to do, maybe something like this:
#!/usr/bin/env jruby
import java.sql.DriverManager
# TODO some magic to load the driver
conn = DriverManager.getConnection(ARGV[0], ARGV[1], ARGV[2])
res = conn.executeQuery ARGV[3]
... |
Color reduction (in Java) |
|java|colors|image-manipulation|reduce| |
I would like to find a way to take JPEG (or GIF/PNG) images and reduce the amount of colors to e.g. 20. Could someone recommend some library or other reference? Also source codes in other languages are welcome. |
What is the best C# to VB.net converter? |
|c#|vb.net|converters| |
While searching the interweb for a solution for my VB.net problems I often find helpful articles on a specific topic, but the code is C#. That is no big problem but it cost some time to convert it to VB manually.
There are some sites that offer code converters from C# to VB and vice versa, but to fix all the flaws aft... |
Nope. There is speculation it might be added with CF9, but that's a fair way off.
You don't need to rewrite the whole function, you can do this:
<cffunction name="foo" returntype="string" output="false" access="private">
<cfscript>
return "bar";
</cfscript>
</cffunction> |
ctrl-space inside the parens |
So if I understand, then I think I would have the app create a transform (MST) that has the content files and apply that to the base MSI. I'm still not convinced that I understand though. :) |
I don't have any concrete references, but you might want to look into the Owicki-Gries theory (if you like theorem proving) or process theory/algebra (for which there are also various model-checking tools available). |