instruction
stringlengths 0
30k
⌀ |
---|
I use it whenever [StyleCop][1] tells me to. [StyleCop][2] must be obeyed. Oh yes.
[1]: http://code.msdn.microsoft.com/sourceanalysis
[2]: http://code.msdn.microsoft.com/sourceanalysis |
Okay, I feel like I'm taking crazy pills here, looking at some of these answers. Well, maybe I am.
**String.Format has to be a static method because strings are immutable.** Making it an instance method would imply you could use it to "format" or modify the value of an existing string. This you can't do, and making it an instance method that returned a new string would make no sense. Hence, it's a static method.
|
Is this any use?
http://msdn.microsoft.com/en-us/library/bb774085(VS.85).aspx |
Is this any use?
Oops:
http://msdn.microsoft.com/en-us/library/bb774096(VS.85).aspx |
Is this any use?
Oops:
http://msdn.microsoft.com/en-us/library/bb774096(VS.85).aspx |
Cool - I'll try those options, as they're probably better defaults given my intentions. Unfortunately, I know my device is there and I'll eventually need read/write access later on (once I inspect the descriptors and have verifed it is infact my device).
Which means that my real goal IS to know what's using it, so I can inform the customer/user: "Hey man, 'iexplore.exe' is currently using your SuperWidget device. You'll have to close that down in order to use SuperWidget application." (if not at the application-level, then at least at the phone support level.)
I forgot to mention that the windows error reported by GetLastError() is:
> 0x20. The process cannot access the file because it is being used by another process.
(So your sharing alternatives will probably get the file open, assuming no FILE_SHARE_NONE on behalf of the other process). |
Cool - I'll try those options, as they're probably better defaults given my intentions. Unfortunately, I know my device is there and I'll eventually need read/write access later on (once I inspect the descriptors and have verifed it is infact my device).
Which means that my real goal IS to know what's using it, so I can inform the customer/user: "Hey man, 'iexplore.exe' is currently using your SuperWidget device. You'll have to close that down in order to use SuperWidget application." (if not at the application-level, then at least at the phone support level.)
I forgot to mention that the windows error reported by GetLastError() is:
> 0x20. The process cannot access the file because it is being used by another process.
(So your sharing alternatives will probably get the file open, assuming no FILE_SHARE_NONE on behalf of the other process).
[edit]
> Yeah, it's a painful alright. I have seen mice and keyboards get locked by whatever Windows uses to read from them. I've also seen a lot of people have trouble inside a VM like Paralells on OS X, where the HID class driver has the device open exclusively preventing the VM from using standard USB requests.
>I've seen some code that recreates what *ProcessMonitor* does. Maybe SysInternals is just electing to ignore device handles, but the same method (or a slight variation) can be employed here to determine the PID.
> **Mike** |
Tag-based web sites often suffer from the delicacy of language such as synonyms, homonyms, etc. For programmers looking for information, say on SO, concrete examples are:
- Subversion or SVN (or svn, with case-sensitive tags)
- .NET or Mono
- [Will add more]
The problem is that we *do* want to preserve our delicacy of language and make the machine deal with it as good as possible.
A site like del.icio.us sees its tag base grow a lot, thus probably hindering usage or search. Searching for SVN-related entries will probably list a majority of entries with both subversion and svn tags, but I can think of three issues:
1. A search is incomplete as many entries may not have both tags (which are 'synonyms').
2. A search is less useful as Q/A often lead to more Qs! Notably for newbies on a given topic.
3. Tagging a question (note: or an answer separately, sounds useful) becomes philosophical: 'Did I Tag the Right Way?'
One way to address these issues is to create semantic links between tags, so that subversion and svn are automatically bound by the system, not by poor users.
*Is it an approach that sounds good/feasible/attractive/useful? How to implement it efficiently?* |
|stackoverflow|tags|del.icio.us|folksonomy| |
After some research I came up with the following:
string pmt = dr["Payment"].ToString();
double dblPmt = System.Convert.ToDouble(pmt);
this.txtPayment.Text = dblPmt.ToString("c",CultureInfo.CurrentCulture.NumberFormat);
I am going to test all code samples given. If I can solve this with one line of code then thats what I am going to do.
|
As always, it depends on their implementation. If they decide to mess with the rendering engine, we could be looking at a whole new list of browser "quirks" which will mean WebDev's will be uber-pissed.
If they stay standards-compliant (which TBH, I expect they will) it could be a really good thing to heat up the competition.
Be interesting to see how the sandbox mode affects plugin compat, and of course, the tight Gears integration..
That fact that its OSS is a really good thing.. Since any of the above issues could easily be fixed with a patch as soon as the dev community get on to it. :) |
You should be able to use the IN clause (assuming your database supports it):
`UPDATE foo
SET flag=true
WHERE id in (1, 2, 3, 5, 6)` |
Beta Testing |
|beta|testing| |
I have a project that I would like to start beta testing soon, it is a PHP/MySQL site for programmers.<br />
I have beta tested sites before however it was always in-house, and I have never done betas that could/should be seen by someone other then those associated with the project.<br /><br />So, how should I go about starting the beta, and what problems, aside from those the beta is supposed to expose, should I be prepared for? |
I have a project that I would like to start beta testing soon, it is a PHP/MySQL site for programmers.<br />
I have beta tested sites before however it was always in-house, and I have never done betas that could/should be seen by someone other then those associated with the project.<br /><br />So, how should I go about starting the beta, and what problems, aside from those the beta is supposed to expose, should I be prepared for?
Yes I'm hoping for some input from Jeff and the rest of the SO crew. |
DateFormat.parse(String) |
In brief...
DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
Date date = (Date)formatter.parse("01/29/02");
See [http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html][1] for more.
[1]: http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html |
Which jstl url should I reference in my jsps? |
|java|jsp|web-applications|jstl| |
I'm getting the following error when trying to run a jsp.
I'm using Tomcat 6.0.18, and I'd like to use the latest version of jstl.
What version of jstl should I use, and which URL goes with which version of jstl?
I'm getting this error
"According to TLD or attribute directive in tag file, attribute key does not accept any expressions"
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
I'll just say I had this working, but I want to switch the jstl jar file that has the tld files in the jar file. (instead of having to deploy them somewhere in the web application and define the references in web.xml).
|
This should help
[DefaultValue(typeof(Color),"InactiveBorder")] |
This should help
[DefaultValue(typeof(Color),"InactiveBorder")]
You need to replace SystemColors with Color.
It seems that there is no type converter for SystemColors type, only for Color type. |
You need to change first argument from SystemColors to Color.
It seems that there is no type converter for SystemColors type, only for Color type.
[DefaultValue(typeof(Color),"InactiveBorder")]
|
This page shows some examples of open-source rules engines in C#: [http://csharp-source.net/open-source/rule-engines][1]
[1]: http://csharp-source.net/open-source/rule-engines |
There is the Microsoft Business Rules Engine: <http://msdn.microsoft.com/en-us/library/aa561216.aspx>. Not sure if it can only be used inside Biztalk - it does says it is a .Net Class Library. |
I believe that it is a matter of preference at this point. The words that you mention are basically synonyms in today's languages and for the most part people will understand what you mean if you say either "method" or "function". If you use "message", which is only used really in OOP, then you may confuse what you are attempting to convey.For example: "I need to create a message to send an email message." Other terms that could be synonymous, and this isn't a complete list, are subroutine, action, procedure, operation (although usually mathematical in nature), subprogram, command... |
ZedGraph is not WinForms only, there's a web control too. It's very good. |
How do I best populate an HTML table in ASP.NET? |
|asp.net|vb.net|html| |
|asp.net|html|vb.net| |
Kokos,
Couple of things wrong there. First, doing it that way means I have to construct the Foos first, then feed their values to the mock reader which does nothing to *reduce* the amount of code I'm writing. Second, if the values pass through the reader, the Foos won't be the *same* Foos (reference equality). They might be *equal*, but even that's assuming too much of the Foo class that I don't dare touch at this point. |
If you don't/can't keep the connection open you could use [screen][1], if you have the rights to install it.
[1]: http://www.gnu.org/software/screen/ |
The Version class does not support versions with commas in it, so the solution presented by [Darren Kopp](http://stackoverflow.com/questions/30494#30510) is not sufficient.
Here is a version that is as simple as possible (but no simpler).
It uses System.Version but achieves compatibility with version numbers like "1, 2, 3, 4" by doing a search-replace before comparing.
/// <summary>
/// Compare versions of form "1,2,3,4" or "1.2.3.4". Throws FormatException
/// in case of invalid version.
/// </summary>
/// <param name="strA">the first version</param>
/// <param name="strB">the second version</param>
/// <returns>less than zero if strA is less than strB, equal to zero if
/// strA equals strB, and greater than zero if strA is greater than strB</returns>
public static int CompareVersions(String strA, String strB)
{
Version vA = new Version(strA.Replace(",", "."));
Version vB = new Version(strB.Replace(",", "."));
return vA.CompareTo(vB);
}
The code has been tested with:
static void Main(string[] args)
{
Test("1.0.0.0", "1.0.0.1", -1);
Test("1.0.0.1", "1.0.0.0", 1);
Test("1.0.0.0", "1.0.0.0", 0);
Test("1, 0.0.0", "1.0.0.0", 0);
Test("9, 5, 1, 44", "3.4.5.6", 1);
Test("1, 5, 1, 44", "3.4.5.6", -1);
Test("6,5,4,3", "6.5.4.3", 0);
try
{
CompareVersions("2, 3, 4 - 4", "1,2,3,4");
Console.WriteLine("Exception should have been thrown");
}
catch (FormatException e)
{
Console.WriteLine("Got exception as expected.");
}
Console.ReadLine();
}
private static void Test(string lhs, string rhs, int expected)
{
int result = CompareVersions(lhs, rhs);
Console.WriteLine("Test(\"" + lhs + "\", \"" + rhs + "\", " + expected +
(result.Equals(expected) ? " succeeded." : " failed."));
}
|
The [System.Version](http://msdn.microsoft.com/en-us/library/system.version.aspx) class does not support versions with commas in it, so the solution presented by [Darren Kopp](http://stackoverflow.com/questions/30494#30510) is not sufficient.
Here is a version that is as simple as possible (but no simpler).
It uses [System.Version](http://msdn.microsoft.com/en-us/library/system.version.aspx) but achieves compatibility with version numbers like "1, 2, 3, 4" by doing a search-replace before comparing.
/// <summary>
/// Compare versions of form "1,2,3,4" or "1.2.3.4". Throws FormatException
/// in case of invalid version.
/// </summary>
/// <param name="strA">the first version</param>
/// <param name="strB">the second version</param>
/// <returns>less than zero if strA is less than strB, equal to zero if
/// strA equals strB, and greater than zero if strA is greater than strB</returns>
public static int CompareVersions(String strA, String strB)
{
Version vA = new Version(strA.Replace(",", "."));
Version vB = new Version(strB.Replace(",", "."));
return vA.CompareTo(vB);
}
The code has been tested with:
static void Main(string[] args)
{
Test("1.0.0.0", "1.0.0.1", -1);
Test("1.0.0.1", "1.0.0.0", 1);
Test("1.0.0.0", "1.0.0.0", 0);
Test("1, 0.0.0", "1.0.0.0", 0);
Test("9, 5, 1, 44", "3.4.5.6", 1);
Test("1, 5, 1, 44", "3.4.5.6", -1);
Test("6,5,4,3", "6.5.4.3", 0);
try
{
CompareVersions("2, 3, 4 - 4", "1,2,3,4");
Console.WriteLine("Exception should have been thrown");
}
catch (FormatException e)
{
Console.WriteLine("Got exception as expected.");
}
Console.ReadLine();
}
private static void Test(string lhs, string rhs, int expected)
{
int result = CompareVersions(lhs, rhs);
Console.WriteLine("Test(\"" + lhs + "\", \"" + rhs + "\", " + expected +
(result.Equals(expected) ? " succeeded." : " failed."));
}
|
This CSS snippet should remove the vertical scrollbar:
body {
overflow-x: hidden;
overflow-y: hidden;
}
I'm not sure yet about having it take up as much vertical space as it needs, but I'll see if I can't figure it out. |
I don't think either of these answers are definitive. The 4guysfromrolla reference is helpful.
Deploying .NET 3.5 to 100+ sites will be a pain. You can't just upgrade the server to the new framework, you have to upgrade the web.config of each site. As far as I can tell, there is no command line tool to do it. |
How to keep a "things done" count in a recursive algorithm in Java? |
|java|coding-style|recursion|integer|final| |
I have a recursive algorithm which steps through a string, character by character, and parses it to create a tree-like structure. I want to be able to keep track of the character index the parser is currently at (for error messages as much as anything else) but am not keen on implementing something like a tuple to handle multiple returned types.
I tried using an Integer type, declared outside the method and passed into the recursive method, but because it's final, recursive call increments are "forgotten" when I return. (Because the increment of the Integer value makes the passed-by-value object reference point at a new object)
Is there a way to get something similar to work which won't pollute my code? |
The previous answers point out the XML syntax perfectly. I just wanted to throw in my recommendation for the [free (and open-source) nDoc help library generator][1] that parses all comments in a project.
[1]: http://ndoc.sourceforge.net/ |
It's kind of a hack, but sometimes I use an AtomicInteger, which is mutable, to do things like this. I've also seen cases where an int[] of size 1 is passed in. |
The _float:left;_ doesn't work in IE7. You still lose the bullet. I'm not really keen on using a background image either. |
The _float:left;_ doesn't work in IE7. You still lose the bullet. I'm not really keen on using a background image either.
At the moment I think I'm just gonna go with &bull; |
That's why you have to avoid:
catch (Exception ex)
{
throw ex;
}
As that basically cloaks your exception in a new one.
If you use:
catch (Exception ex)
{
throw; //note: no ex
}
It keeps the original exception and stack trace. |
As far as I've seen, there isn't a significant performance difference between the two. I'm reasonably certain that in most cases it will be 'compiled' down to the same code.
If you're not sure, try writing a test application that does each method a million times or so, all the while timing how long it takes. That's the only way to be certain (although it may vary on different architecture.) |
The current solution I am using is:
int[] counter = {0};
and then pass it to the recursive algorithm:
public List<Thing> doIt (String aString, int[] counter) { ... }
and when I want to increment it:
counter[0]++;
Not super elegant, but it works...
|
|.net|exception|c#| |
|c#|.net|exception| |
I'm maintaining a .NET 1.1 application, and one of the things I've been tasked with is making sure the user doesn't see any unfriendly error notifications.
I've added handlers to Application.ThreadException and AppDomain.CurrentDomain.UnhandledException, which do get called. My problem is that the standard CLR error dialog is still displayed (before the exception handler is called).
Jeff talks about this problem on his blog [here][1] and [here][2]. But there's no solution. So what is the standard way in .NET 1.1 to handle uncaught exceptions and display a friendly dialog box?
**Edit**: Jeff's response was marked as the correct answer, because the link he provided has the most complete information on how to do what's required.
[1]: http://www.codinghorror.com/blog/archives/000201.html
[2]: http://www.codinghorror.com/blog/archives/000216.html |
There's not really enough information to go on here.
svn merge -r 67212:67213 https://my.svn.repository/trunk .
will merge any files changed in the revision 67212 in the folder /trunk on the repository and merge them into your current working directory. If you do:
svn log -r 67212
What files does it show changed? Merge will only pull changes from the first argument, and apply them to the second. It does not upload back to the server in the first argument.
If this doesn't answer your question, could you post more details as to what exactly is happening? |
When I was first learning Java we had to make Yahtzee (yawn) and I thought it would be cool to create custom Swing components and containers instead of just drawing everything on one JPanel. The benefit of extending Swing components, of course, is to have the ability to add support for keyboard shortcuts and other accessibility features that you can' do just by having a paint() method print a pretty picture. It may not be done the best way however, but it may be a good starting point for you.
![alt text][1]<br>
![alt text][2]<br>
![alt text][3]
I haven't looked at this code in a while but I have a feeling there was something super tricky that gave me quite a few headaches trying to figure out. That's why I'm going to post the whole source code at the end of this post. But here's some basic steps:
1. Create a class that extends JComponent
2. Call parent constructor super() in your constructors
3. It's a button so you'll need mouse input...make sure you class implements MouseListener
4. Put this in constructor:<br>
enableInputMethods(true);
addMouseListener(this);
5. Add these to your object (important!)<br>
public Dimension getPreferredSize()<br>
public Dimension getMinimumSize()<br>
public Dimension getMaximumSize()
6. Add this method to your class now: public void paintComponent(Graphics g)
The amount of space you have to work with when drawing your button is defined by getPreferredSize(). Well, assuming getMinimumSize() and getMaximumSize() return the same value... I haven't experimented too much with this but, depending on the layout you use for your GUI your button could look completely different...
And finally, the [source code][4]. In case I missed anything.
[1]: http://www.kevinx.net/tf2/uploads/dice.jpg
[2]: http://www.kevinx.net/tf2/uploads/dice2.jpg
[3]: http://www.kevinx.net/tf2/uploads/dice3.jpg
[4]: http://kevinx.net/labs/java/yahtzee/Dice.java |
Cool - I'll try those options, as they're probably better defaults given my intentions. Unfortunately, I know my device is there and I'll eventually need read/write access later on (once I inspect the descriptors and have verifed it is infact my device).
Which means that my real goal IS to know what's using it, so I can inform the customer/user: "Hey man, 'iexplore.exe' is currently using your SuperWidget device. You'll have to close that down in order to use SuperWidget application." (if not at the application-level, then at least at the phone support level.)
I forgot to mention that the windows error reported by GetLastError() is:
> 0x20. The process cannot access the file because it is being used by another process.
(So your sharing alternatives will probably get the file open, assuming no FILE_SHARE_NONE on behalf of the other process).
[edit]
> Yeah, it's painful alright. I have seen mice and keyboards get locked by whatever Windows uses to read from them. I've also seen a lot of people have trouble inside a VM like Paralells on OS X, where the HID class driver has the device open exclusively preventing the VM from using standard USB requests.
>I've seen some code that recreates what *ProcessMonitor* does. Maybe SysInternals is just electing to ignore device handles, but the same method (or a slight variation) can be employed here to determine the PID.
> **Mike** |
Anything but Visual Source Safe; preferably one which supports the concepts of branching and merging. As others have said, Subversion is a great choice, especially with the TortoiseSVN client.
Be sure to check out (pardon the pun) [Eric Sink's classic series of Source Control HOWTO articles][1].
[1]: http://www.ericsink.com/scm/source_control.html |
The integrated debuggers where you can watch the values of variable change as you step through code are really cool. They do, however, require software setup on the server and a certain amount of configuration on the client. Both of which require periodic maintenance to keep in good working order.
A print_r is easy to write and is guaranteed to work in any setup. |
[@mercutio](http://stackoverflow.com/questions/23217/whats-the-purpose-if-any-of-javascript-in-event-handler-tags#23242)
>>That's ridiculous.
No, it's not ridiculous, javascript: is a pseudo protocol that can indeed only be used as the subject of a link, so he's quite right. Your suggestion is indeed better, but the best way of all is to use unobtrusive javascript techniques to iterate over HTML elements and add behaviour programmatically, as used in libraries like jQuery. |
x = number_of_dimensions_left;
while (x > 1)
{
switch (x)
{
case 20:
reduce20DimensionTable();
x--;
break;
case 19:
.....
}
}
(Sorry, couldn't resist.) |
x = number_of_dimensions;
while (x > 1)
{
switch (x)
{
case 20:
reduce20DimensionArray();
x--;
break;
case 19:
.....
}
}
(Sorry, couldn't resist.) |
You definitely want to test physically pulling the cable out. Lots of networking code will throw different exceptions in that scenario vs when the connection has just been lost. |
Tomcat is primarily an application server, which serves requests to custom-built Java servlets or JSP files on your server. It is usually used in conjunction with the Apache HTTP server (at least in my experience). Use it to manually process incoming requests.
The HTTP server, by itself, is best for serving up static content... html files, images, etc. |
I do development on 64 bit machines for 32 bit Windows. It's not a problem. You should make sure that your projects are set to compile in x86 mode in order to be conservative. You'll want to go through each project in the solution and double check this. You could also use the AnyCPU setting but that's a little riskier since it will run differently on your dev machine than a 32 bit machine. You want to avoid the 64bit mode, of course.
The problems I've run into are drivers that don't work when the app is compiled for 64 bit (explicitly 64 bit or AnyCPU compiled and running on 64 bit Windows). Those problems are completely avoidable by sticking with x86 compilation. That should reveal all flaws on your dev machines.
Ideally, you could set up a build and test environment that could be executed against frequently on a 32 bit machine. That should reassure your management and let you avoid the VM as your desktop.
|
[Many][1] [have][2] [asked][3], but to date there remains no cold fusion code coverage tool.
The latest Cold Fusion features .NET integration in addition to J2EE integration, so if you require code coverage metrics (ie, customer requirements) then (aside from choosing something other than coldfusion) you might define what parts need such coverage and break them out into .NET or J2EE objects which you can profile with readily available tools.
Alternately, you can do some analysis yourself - use a parser to insert [cftrace][4] tags after every control statement and then parse the results.
Lastly, coldfusion does have some [basic stack trace][5] ability - I don't know if it goes deeper than that, but it's worth exploring to see what you can parse from that.
I hope this helps!
-Adam Davis
[1]: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:53046
[2]: http://www.pbell.com/index.cfm/2006/10/20/What-is-Code-Coverage-Analysis--and-why-should-you-care
[3]: http://coolskool.blog-city.com/what_coldfusion_tools_do_you_want.htm
[4]: http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001221.htm
[5]: http://www.bennadel.com/blog/116-Finding-Template-Execution-Stack-in-ColdFusion.htm |
Divide your services by resource requirements at the very least. For example, if you are running a photo album site, separate your image download server from your image upload server. The download server will have many more requests, and because most people have a lower upload speed the upload server will have longer lasting connections. Similarly, and image manipulation server would probably have few connections, but it should fork off threads to perform the CPU intensive image manipulation tasks asynchronously from the web user interface.
If you have the hardware to do it, it's a lot easier to manage many separate tomcat instances with one application each than a few instances with many applications. |
What is wrong with native Delphi enums? They are type safe.
type
TMyEnum = (Item1, Item2, Item3);
if MyEnum <> Item1 then...
Since Delphi 2005 you can have consts in a class, but Delphi 5 can not.
type
TMyEnum = sealed class
public
const Item1 = 0;
const Item2 = 1;
const Item3 = 2;
end; |
|testing|beta| |
I haven't ever seen a way to do that other than your foreach loop.
But, if $list is in any way gotten from the user, you should stick to using the prepared statement and just updating a row at a time (assuming someone doesn't have a way to update several rows with a prepared statement). Otherwise, you are wide open to sql injection. |
Use join/implode to make a comma-delimited list to end up with:
UPDATE foo SET flag=true WHERE id IN (1,2,3,4) |
No, you can't use passwords, but you could use password hashes. However, Google Docs are all about sharing, so such a method would require storing a copy of the document for each user. |
This would achieve the same thing, but probably won't yield much of a speed increase, but looks nicer.
mysql_query("UPDATE foo SET flag=true WHERE id IN (".implode(', ',$list).")"); |
you can jam you update with case statements but you will have to build the query on your own.
UPDATE foo
SET flag=CASE ID WHEN 5 THEN true ELSE flag END
,flag=CASE ID WHEN 6 THEN false ELSE flag END
WHERE id in (5,6)
The where can be omitted but saves you from a full table update. |
**VB.NET code:**
dim delimitedIdList as string = arrayToString(listOfIds)
dim SQL as string = " UPDATE foo SET flag=true WHERE id in (" + delimitedIdList + ")"
runSql(SQL) |
Use IN statement. Provide comma separated list of key values. You can easily do so using `implode` function.
UPDATE foo SET flag = true WHERE id IN (1, 2, 3, 4, 5, ...)
Alternatively you can use condition:
UPDATE foo SET flag = true WHERE flag = false
or subquery:
UPDATE foo SET flag = true WHERE id IN (SELECT id FROM foo WHERE .....)
|
I think Carl, nailed it on the head, but I wanted to say that with any website, if you are providing it any confidential/personal/privileged information then you have to have a certain level of trust, and it is the responsibility of the service provider to establish this trust. This is one of those questions that has been asked many times, across the internet since it's inception, and it will only continue to grow until we all have our own SSL certs encoded on our fingerprint, and even then we will have to ask the question 'How do I know that the finger is still attached to the user?'. |
I'd stay away from the SQL Query. Instead, I'd either use the API or Web Services. Here's an example API call to retrieve and edit a work item:
<a href="http://msdn.microsoft.com/en-us/library/bb130323.aspx">http://msdn.microsoft.com/en-us/library/bb130323.aspx</a>
You could modify that to add the links. Would be much safer, easier, and much more supported than going directly to the database. |
Well, I'd consider a process similar to Amazons AWS. You authenticate with a private password that is not saved remotely. Just a hash is used to validate the user. Then you generate a certificate with one of the main and long-tested algorithms and provide this from a secure page. Then a public/private key algorithm can be used to encrypt things for the users.
But the main problem remains the same: If someone with enough privileges can access the data (say: hacked your server), you're lost. Given enough time and power, everything could be breaked. It's just a matter of time.
But I think algorithms and applications like GPG/PGP and similar are very well known and can be implemented in a way that secure web applications - and keep the usability at a score that the average user can handle.
**edit** I want to catch up with [@Carl][1] and [Unkwntech][2] and add their statement: If you don't trust the site itself, don't give private data away. That's even before someone hacks their servers... ;-)
[1]: http://stackoverflow.com/users/2095/carl-seleborg
[2]: http://stackoverflow.com/users/115/unkwntech |
When I was first learning Java we had to make Yahtzee (yawn) and I thought it would be cool to create custom Swing components and containers instead of just drawing everything on one JPanel. The benefit of extending Swing components, of course, is to have the ability to add support for keyboard shortcuts and other accessibility features that you can' do just by having a paint() method print a pretty picture. It may not be done the best way however, but it may be a good starting point for you.
Edit 8/6 - If it wasn't apparent from the images, each Die is a button you can click --- this will move it to the DiceContainer below. Looking at the source code (below) you can see that each Die button is drawn dynamically, based on its value.
![alt text][1]<br>
![alt text][2]<br>
![alt text][3]
I haven't looked at this code in a while but I have a feeling there was something super tricky that gave me quite a few headaches trying to figure out. That's why I'm going to post the whole source code at the end of this post. But here's some basic steps:
1. Create a class that extends JComponent
2. Call parent constructor super() in your constructors
3. It's a button so you'll need mouse input...make sure you class implements MouseListener
4. Put this in constructor:<br>
enableInputMethods(true);
addMouseListener(this);
5. Add these to your object (important!)<br>
public Dimension getPreferredSize()<br>
public Dimension getMinimumSize()<br>
public Dimension getMaximumSize()
6. Add this method to your class now: public void paintComponent(Graphics g)
The amount of space you have to work with when drawing your button is defined by getPreferredSize(). Well, assuming getMinimumSize() and getMaximumSize() return the same value... I haven't experimented too much with this but, depending on the layout you use for your GUI your button could look completely different...
And finally, the [source code][4]. In case I missed anything.
[1]: http://www.kevinx.net/tf2/uploads/dice.jpg
[2]: http://www.kevinx.net/tf2/uploads/dice2.jpg
[3]: http://www.kevinx.net/tf2/uploads/dice3.jpg
[4]: http://kevinx.net/labs/java/yahtzee/Dice.java |
If you are talking about MS SQL Server tables, I like the diagram support in SQL Server Management Studio. You just drag the tables from the explorer onto the canvas, and they are laid out for you along with lines for relationships. You'll have to do some adjusting by hand for the best looking diagrams, but it is a decent way to get diagrams. |
The simple answer is, do you like Undo buttons? The answer is of course yes, because we as human being make mistakes all the time.
As programmers, its often the case though that it can take several hours of testing, code changes, overwrites, deletions, file moves and renames before we work out the method we are trying to use to fix a problem is entirely the wrong one and the code is more broken than when we started.
As such, Source Control is a massive Undo button to revert the code to an earlier time when the grass was green and the food plentiful. And not only that, because of how source control works, you can still keep a copy of your broken code, in case a few weeks down the line you want to refer to it again and cherry pick any good ideas that did come out of it.
I personally (though it could be called overkill) use a free Single user license version of Source Gear Fortress (which is their Vault source control product with bug tracking features). I find the UI really simple to use, it supports both the checkout > edit > checkin model and the edit > merge > commit model. It can be a little tricky to set up though, requiring you to run a local copy of ISS and SQL server. You might want to try a smaller program, like those recommended by other answers here. See what you like and what you can afford. |
Going all the way down to the basics for Map and Reduce.
----------
**Map** is a function which "transforms" items in some kind of list to another kind of item and put them back in the same kind of list.
suppose I have a list of numbers: [1,2,3] and I want to double every number, in this case, the function to "double every number" is function x = x * 2. And without mappings, I could write a simple loop, say
A = [1, 2, 3]
foreach (item in A) A[item] = A[item] * 2
and I'd have A = [2, 4, 6] but instead of writing loops, if I have a map function I could write
A = [1, 2, 3].Map(x => x * 2)
the x => x * 2 is a function to be executed against the elements in [1,2,3]. What happens is that the program takes each item, execute (x => x * 2) against it by making x equals to each item, and produce a list of the results.
1 : 1 => 1 * 2 : 2
2 : 2 => 2 * 2 : 4
3 : 3 => 3 * 2 : 6
so after executing the map function with (x => x * 2) you'd have [2, 4, 6].
----------
**Reduce** is a function which "collects" the items in lists and perform some computation on _all_ of them, thus reducing them to a single value.
Finding a sum or finding averages are all instances of a reduce function. Such as if you have a list of numbers, say [7, 8, 9] and you want them summed up, you'd write a loop like this
A = [7, 8, 9]
sum = 0
foreach (item in A) sum = sum + A[item]
But, if you have access to a reduce function, you could write it like this
A = [7, 8, 9]
sum = A.reduce( x, y, 0 => x + y )
Now it's a little confusing why there are 3 arguments (x, y and 0) passed. For a reduce function to be useful, it must be able to take 2 items, compute something and "reduce" that 2 items to just one single value, thus the program could reduce each pair until we have a single value.
the execution would follows:
result = 0
7 : result = result + 7 = 0 + 7 = 7
8 : result = result + 8 = 7 + 8 = 15
9 : result = result + 9 = 15 + 9 = 24
But you don't want to start with zeroes all the time, so there are the third argument to lets you specify a seed value, as in the first line.
say you want to sum 2 lists, it might look like this:
A = [7, 8, 9]
B = [1, 2, 3]
sum = 0
sum = A.reduce( (x, y, sum) => x + y )
sum = B.reduce( (x, y, sum) => x + y )
----------
Its a good thing in a DB because you do not need to know how the data are stored in a DB to use it, thats what a DB engine is for. You just need to be able to "tell" the engine what you want by supplying them with either a Map or a Reduce function and then the DB engine could find its way around the data, apply your function, and come up with the results you want all without you knowing how it goes over all the records.
Same goes for parallel programming, if you only specify what you want to do with the data instead of actually implementing the looping code, then the underlying infrastructure could "parallelize" and execute your function simultaneously for you.
p.s. sorry if that was too long, I think I'm addicted to stackoverflow =.= gotta get to sleep. |
It's important to keep in mind that MVC and WebForms are not competing, and one is not better than the other. They are simply different tools. Most people seem to approach MVC vs WebForms as "one must be a better hammer than the other". That is wrong. One is a hammer, the other is a screwdriver. Both are used in the process of putting things together, but have different strengths and weaknesses.
If one left you with a bad taste, you were probably trying to use a screwdriver to pound a nail. Certain problems are cumbersome with WebForms that become elegant and simple with MVC, and vice-versa. |
This is what I've got. It works. But, is there a simpler or better way?
ASPX Page…
<asp:Repeater ID="RepeaterBooks" runat="server">
<HeaderTemplate>
<table class="report">
<tr>
<th>Published</th>
<th>Title</th>
<th>Author</th>
<th>Price</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Literal ID="LiteralPublished" runat="server" /></td>
<td><asp:Literal ID="LiteralTitle" runat="server" /></td>
<td><asp:Literal ID="LiteralAuthor" runat="server" /></td>
<td><asp:Literal ID="LiteralPrice" runat="server" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
ASPX.VB Code Behind…
Protected Sub Page_Load( ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim db As New BookstoreDataContext
RepeaterBooks.DataSource = From b In db.Books _
Order By b.Published _
Select b
RepeaterBooks.DataBind()
End Sub
Sub RepeaterBooks_ItemDataBound( ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles RepeaterBooks.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim b As Book = DirectCast(e.Item.DataItem, Book)
DirectCast(e.Item.FindControl("LiteralPublished"), Literal).Text = "<nobr>" + b.Published.ToShortDateString + "</nobr>"
DirectCast(e.Item.FindControl("LiteralTitle"), Literal).Text = "<nobr>" + TryNbsp(HttpContext.Current.Server.HtmlEncode(b.Title)) + "</nobr>"
DirectCast(e.Item.FindControl("LiteralAuthor"), Literal).Text = "<nobr>" + TryNbsp(HttpContext.Current.Server.HtmlEncode(b.Author)) + "</nobr>"
DirectCast(e.Item.FindControl("LiteralPrice"), Literal).Text = "<nobr>" + TryNbsp(HttpContext.Current.Server.HtmlEncode(b.Price)) + "</nobr>"
End If
End Sub
Function TryNbsp(ByVal s As String) As String
If s = "" Then
Return " "
Else
Return s
End If
End Function |
This is what I've got. It works. But, is there a simpler or better way?
ASPX Page…
<asp:Repeater ID="RepeaterBooks" runat="server">
<HeaderTemplate>
<table class="report">
<tr>
<th>Published</th>
<th>Title</th>
<th>Author</th>
<th>Price</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Literal ID="LiteralPublished" runat="server" /></td>
<td><asp:Literal ID="LiteralTitle" runat="server" /></td>
<td><asp:Literal ID="LiteralAuthor" runat="server" /></td>
<td><asp:Literal ID="LiteralPrice" runat="server" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
ASPX.VB Code Behind…
Protected Sub Page_Load( ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim db As New BookstoreDataContext
RepeaterBooks.DataSource = From b In db.Books _
Order By b.Published _
Select b
RepeaterBooks.DataBind()
End Sub
Sub RepeaterBooks_ItemDataBound( ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles RepeaterBooks.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim b As Book = DirectCast(e.Item.DataItem, Book)
DirectCast(e.Item.FindControl("LiteralPublished"), Literal).Text = "<nobr>" + b.Published.ToShortDateString + "</nobr>"
DirectCast(e.Item.FindControl("LiteralTitle"), Literal).Text = "<nobr>" + TryNbsp(HttpContext.Current.Server.HtmlEncode(b.Title)) + "</nobr>"
DirectCast(e.Item.FindControl("LiteralAuthor"), Literal).Text = "<nobr>" + TryNbsp(HttpContext.Current.Server.HtmlEncode(b.Author)) + "</nobr>"
DirectCast(e.Item.FindControl("LiteralPrice"), Literal).Text = "<nobr>" + Format(b.Price, "c") + "</nobr>"
End If
End Sub
Function TryNbsp(ByVal s As String) As String
If s = "" Then
Return " "
Else
Return s
End If
End Function |
My group at work is using Git, and it has been all the difference in the world. We were using SCCS and a steaming pile of csh scripts to manage quite large and complicated projects that shared code between them (attempted to, anyway).
With Git, submodule support makes a lot of this stuff easy, and only a minimum of scripting is necessary. Our release engineering effort has gone way, way down because branches are easy to maintain and track. Being able to cheaply branch and merge really makes it reasonably easy to maintain a single collection of sources across several projects (contracts), whereas before, any disruption to the typical flow of things was very, very expensive. We've also found the scriptabability of Git to be a **huge** plus, because we can customize its behavior through hooks or through scripts that do `. git-sh-setup`, and it doesn't seem like a pile of kludges like before.
We also sometimes have situations in which we have to maintain our version control across distributed, non-networked sites (in this case, disconnected secure labs), and Git has mechanisms for dealing with that quite smoothly (bundles, the basic clone mechanism, formatted patches, etc).
Some of this is just us stepping out of the early 80s and adopting some modern version control mechanisms, but Git "did it right" in most areas.
I'm not sure of the extent of answer you're looking for, but our experience with Git has been very, very positive. |
Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.
So basically Apache is an HTTP Server. It servers HTTP. Tomcat is a Servelt and JSP server that servers Java technologies. |
Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.
So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servelt and JSP Server serving Java technologies. |
Please take a look at [this page][1] (section "Dependency Version Ranges"). What you might want to do is something like
<version>[1.2.3,)</version>
HTH
**Edit:** Just saw the note that the ideas expressed in the linked document may not be implemented yet...
[1]: http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution |
Please take a look at [this page][1] (section "Dependency Version Ranges"). What you might want to do is something like
<version>[1.2.3,)</version>
HTH
**Edit:** Just saw the note that the ideas expressed in the linked document may not be implemented yet...
**Edit 2:** The version ranges are implemented in Maven2.
[1]: http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges |
MySQL Binary Log Replication: Can it be set to ignore errors? |
|mysql|replication|binlog| |
I'm running a master-slave MySQL binary log replication system (phew!) that, for some data, is not in sync (meaning, the master holds more data than the slave). But the slave stops very frequently on the slightest MySQL error, can this be disabled? (perhaps a my.cnf setting for the replicating slave ignore-replicating-errors or some of the sort ;) )
This is what happens, every now and then, when the slave tries to replicate an item that does not exist, the slave just dies. a quick check at **SHOW SLAVE STATUS \G;** gives
Slave-IO-Running: Yes
Slave-SQL-Running: No
Replicate-Do-DB:
Last-Errno: 1062
Last-Error: Error 'Duplicate entry '15218' for key 1' on query. Default database: 'db'. Query: 'INSERT INTO db.table ( FIELDS ) VALUES ( VALUES )'
which I promptly fix (once I realize that the slave has been stopped) by doing the following:
STOP SLAVE;
RESET SLAVE;
START SLAVE;
... lately this has been getting kind of tiresome, and before I spit out some sort of PHP which does this for me, i was wondering if there's some my.cnf entry which will not kill the slave on the first error.
Cheers,
/mp
|
Lets make it the best way to shift `N` bits in the array of 8 bit integers.
N - Total number of bits to shift
F = (N / 8) - Full 8 bit integers shifted
R = (N % 8) - Remaining bits that need to be shifted
I guess from here you would have to find the most optimal way to make use of this data to move around ints in an array. Generic algorithms would be to apply the full integer shifts by starting from the right of the array and moving each integer `F` indexes. Zero fill the newly empty spaces. Then finally perform an `R` bit shift on all of the indexes, again starting from the right.
In the case of shifting `0xBC` by `R` bits you can calculate the overflow by doing a bitwise OR, and the shift using the bitshift operator:
// 0xAB shifted 4 bits is:
(0xAB | 0x0F) >> 4 // is the overflow (0x0A)
0xAB << 4 // is the shifted value (0xB0)
Keep in mind that the 4 bits is just a simple mask: 0x0F or just 0b00001111. This is easy to calculate, dynamically build, or you can even use a simple static lookup table.
I hope that is generic enough. I'm not good with C/C++ at all so maybe someone can clean up my syntax or be more specific.
Bonus: If you're crafty with your C you might be able to fudge multiple array indexes into a single 16, 32, or even 64 bit integer and perform the shifts. But that is prabably not very portable and I would recommend against this. Just a possible optimization.
|
Lets make it the best way to shift `N` bits in the array of 8 bit integers.
N - Total number of bits to shift
F = (N / 8) - Full 8 bit integers shifted
R = (N % 8) - Remaining bits that need to be shifted
I guess from here you would have to find the most optimal way to make use of this data to move around ints in an array. Generic algorithms would be to apply the full integer shifts by starting from the right of the array and moving each integer `F` indexes. Zero fill the newly empty spaces. Then finally perform an `R` bit shift on all of the indexes, again starting from the right.
In the case of shifting `0xBC` by `R` bits you can calculate the overflow by doing a bitwise AND, and the shift using the bitshift operator:
// 0xAB shifted 4 bits is:
(0xAB & 0x0F) >> 4 // is the overflow (0x0A)
0xAB << 4 // is the shifted value (0xB0)
Keep in mind that the 4 bits is just a simple mask: 0x0F or just 0b00001111. This is easy to calculate, dynamically build, or you can even use a simple static lookup table.
I hope that is generic enough. I'm not good with C/C++ at all so maybe someone can clean up my syntax or be more specific.
Bonus: If you're crafty with your C you might be able to fudge multiple array indexes into a single 16, 32, or even 64 bit integer and perform the shifts. But that is prabably not very portable and I would recommend against this. Just a possible optimization.
|
How do you troubleshoot character encoding problems? |
|encoding|localization| |
If all you see is the ugly no-char boxes, what tools or strategies do you use to figure out what went wrong?
(The specific scenario I'm facing is no-char boxes within a <select> when it should be showing Japanese chars.) |
The [FlashWindowEx][1] function which controls the flashing takes a [FLASHWINFO][2] struct which has a uCount field to control how many times it flashes. Also, a possible value for the dwFlags field is FLASHW_STOP to cause the flashing to stop.
[1]: http://msdn.microsoft.com/en-us/library/ms679347%28VS.85%29.aspx
[2]: http://msdn.microsoft.com/en-us/library/ms679348%28VS.85%29.aspx |
In addition to what Nick has said you can find out more at [Streamed Lines: Branching Patterns for Parallel Software Development](http://www.cmcrossroads.com/bradapp/acme/branching/)
![Example][1]
[1]: http://www.cmcrossroads.com/bradapp/acme/branching/vtree.gif
In this figure main is the trunk, rel1-maint a branch and "1.0" a tag. |
GROUP BY is similar to DISTINCT in that it groups multiple records into one.
This example, borrowed from [http://www.devguru.com/technologies/t-sql/7080.asp][1], lists distinct products in the Products table.
SELECT Product FROM Products GROUP BY Product
Product
-------------
Desktop
Laptop
Mouse
Network Card
Hard Drive
Software
Book
Accessory
The advantage of GROUP BY over DISTINCT, is that it can give you granular control when used with a HAVING clause.
SELECT Product, count(Product) as ProdCnt
FROM Products
GROUP BY Product
HAVING count(Product) > 2
Product ProdCnt
--------------------
Desktop 10
Laptop 5
Mouse 3
Network Card 9
Software 6
[1]: http://www.devguru.com/technologies/t-sql/7080.asp
|
I'm going to make some enemies with this, but I actually use -- *gasp* -- a non-monospace font! I occasionally switch back to a monospace to disambiguate something, but mostly find that a good clean sans-serif font is easiest to read and doesn't waste screen estate.
An IDE with good syntax colouring helps. |
I prefer using jQuery for AJAXy stuff like that. It also has a lot of very good plugins that make writing client-side code very easy.
Here is the plugin page specifically for Drag-n-Drop.
[http://plugins.jquery.com/project/Plugins/category/45][1]
[1]: http://plugins.jquery.com/project/Plugins/category/45
<br />
Ajax callback are also very easy so saving the setup should be fairly easy as well. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.