instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>I am working on a very large legacy code base. We are looking to introduce FindBugs into the development practice.</p> <p>I intend to have FindBugs run whenever the code is built by eclipse.</p> <p>I would like to be able to make the findbugs warnings appear as errors in the code much in this way you can change th...
<p>The accepted answer is out of date now. I don't know the release it changed in, but the Reporter Configuration tab of the FindBugs Eclipse plugin preferences dialog now allows you to configure each severity of bug (Scariest, Scary, Troubling, and Of Concern) as Info, Warning, or Error. Bugs marked as Error will caus...
<p>No, it isn't possible to have the FindBugs Eclipse plugin mark potential bugs as errors in the code.</p> <p>I did some checking and the <a href="http://maven-plugins.sourceforge.net/maven-findbugs-plugin/index.html" rel="nofollow noreferrer">FindBugs Maven plugin</a> doesn't provide an option to do this either (so ...
40,028
<p>I'm working on a spec for a piece of software for my company and as part of the auditing system I think it would be neat if there was a way to grab the current Active Directory user.</p> <p>Hopefully something like:</p> <pre><code>Dim strUser as String strUser = ActiveDirectory.User() MsgBox "Welcome back, " &amp;...
<p><a href="http://bytes.com/forum/thread717576.html" rel="nofollow noreferrer">Try this article</a> - I have some code at work that will erm, work if this doesn't...</p> <p>Relevant quote:</p> <blockquote> <pre class="lang-vba prettyprint-override"><code>Private Declare Function GetUserName Lib "advapi32.dll" Alia...
<p>Depending on environment variables to remain valid is a bad idea, since they can easily be changed within a user session.</p>
3,054
<p>I get this error on an update panel within a popupControlExtender which is within a dragPanelExtender.</p> <p>I see that a lot of other people have this issue and have various fixes none of which have worked for me.</p> <p>I would love to hear a logical explanation for why this is occurring and a foolproof way to ...
<p>My best guess is that the UpdatePanel is not able to write out the custom "async" property to the postback request properly. This is likely due to blocking from one of the controls wrapping it (my gut feeling is that it's the popupControlExtender - it tends to have odd behavior with updatepanels, as it is intended t...
<p>Settign "EnablePartialRendering" to false on the ScriptManager control prevents the error, but it is not an optimal solution. Losing the benefit of partial rendering could be a big deal, depending on your application.</p> <p>Just for the record, I wasn't doing exactly the same as other folks who saw the error. I ...
8,191
<p>Here's a problem I ran into recently. I have attributes strings of the form</p> <pre><code>"x=1 and y=abc and z=c4g and ..." </code></pre> <p>Some attributes have numeric values, some have alpha values, some have mixed, some have dates, etc.</p> <p>Every string is <em>supposed</em> to have "<code>x=someval and y...
<p>I'm not the best at regular expressions, but this seems pretty close to what you're looking for:</p> <pre><code>/x=(.+) and y=([^ ]+)( and (.*))?/ </code></pre> <p>Except you use $1, $2, and $4. In use:</p> <pre><code>my @strs = ("x=1 and y=abc and z=c4g and w=v4l", "x=yes and y=no", "z=n...
<p>Here's basically what I did to solve this:</p> <pre><code>($x_str, $y_str, $remainder) = split(/ and /, $str, 3); if ($x_str !~ /x=(.*)/) { # error } $x = $1; if ($y_str !~ /y=(.*)/) { # error } $y = $1; </code></pre> <p>I've omitted some additional validation and error handling. This technique works,...
3,174
<p>Is it possible to log out user from a web site if he is using basic authentication?</p> <p>Killing session is not enough, since, once user is authenticated, each request contains login info, so user is automatically logged in next time he/she access the site using the same credentials.</p> <p>The only solution so ...
<p>Basic Authentication wasn't designed to manage logging out. You can do it, but not completely automatically.</p> <p>What you have to do is have the user click a logout link, and send a ‘401 Unauthorized’ in response, using the same realm and at the same URL folder level as the normal 401 you send requesting a login...
<pre><code><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code> function logout(secUrl, redirUrl) { if (bowser.msie) { document.execCommand('ClearAuthentic...
28,906
<p>When is it appropriate to use a class in Visual Basic for Applications (VBA)?</p> <p>I'm assuming the <a href="http://en.wikipedia.org/wiki/Class_(computer_science)#Reasons_for_using_classes" rel="noreferrer">accelerated development and reduction of introducing bugs</a> is a common benefit for most languages that s...
<p>It depends on who's going to develop and maintain the code. Typical "Power User" macro writers hacking small ad-hoc apps may well be confused by using classes. But for serious development, the reasons to use classes are the same as in other languages. You have the same restrictions as VB6 - no inheritance - but y...
<p>I don't see why the criteria for VBA would be any different from another language, particularly if you are referring to VB.NET.</p>
14,466
<p>Is it possible to provide Unicode input to a console app, and read the Unicode char/string via Console.ReadKey()?</p> <p>I know Unicode works when reading the input via other methods, but unfortunately I need to use the 'interception' feature provided by ReadKey.</p> <p>Update:</p> <p>When pasting a Unicode chara...
<p>Unfortunately, Console.ReadKey is only able to process keyboard events. Keyboard events can only represent things that can be typed on the keyboard (using the real and "virtual" keys defined in the ConsoleKey enumeration). So when using ReadKey you will only get two things: a raw key code, which corresponds to a key...
<p>The ConsoleKeyInfo object returned by Console.ReadKey() has a property called KeyChar containing the Unicode char of the pressed key or key combination (if the key or key combination has a Unicode equivalent). So...</p> <pre><code>char c = Console.ReadKey().KeyChar; </code></pre> <p>You'll get a '\0' char if the k...
42,158
<p>How can I document a member inline in .Net? Let me explain. Most tools that extract documentation from comments support some kind of inline documentation where you can add a brief after the member declaration. Something like:</p> <pre><code>public static string MyField; /// &lt;summary&gt;Information about MyField....
<p>No, you can't. XML comments are only supported as a block level comment, meaning it must be placed before the code element you are documenting. The common tools for extracting XML comments from .NET code do not understand how to parse inline comments like that. If you need this ability you will need to write your ow...
<p>Yep, just put it BEFORE the thing you want to comment</p> <pre><code>/// &lt;summary&gt;Information about MyField.&lt;/summary&gt; public static string MyField; </code></pre>
33,775
<p>What is the best way to record statistics on the number of visitors visiting my site that have set their browser to block ads?</p>
<p>Since programs like AdBlock actually never request the advert, you would have to look the server logs to see if the same user accessed a webpage but didn't access an advert. This is assuming the advert is on the same server.</p> <p>If your adverts are on a separate server, then I would suggest it's impossible to do...
<p>I suppose you could compare the ad prints with the page views on your website (which you can get from your analytics software).</p>
2,455
<p>I'm witting a WCF service for a customer to send part information to our application. We have multiple customers that will have one or many locations, and part information is scoped to each location for the customer. When the customer calls our service they will need to specify the location. </p> <p>Options that we...
<p>I would say if it's only one or two operations that need it, make it part of the data contract - sort of like making it a parameter to a method call. If every operation requires it, put it in the header, since it's just as much context as username, roles, tenant, or other authentication information - sort of like so...
<p>Do you need to use a message contract? I use Data contracts unless I need to stream something back, so everything just ends up in the body. But, even for a message contract I would put that information in the body, I tend to reserve the header for authentication information.</p>
16,917
<p>In addition to informing the user, we want to collect information for our debugging purposes. Our system is a niche system for only about 1400 customers, and therefore we are not as well-financed as we would hope, so bugs are more common than we would like. We currently have a window that shows the first line of t...
<p>Without the copy:</p> <pre><code>CharSequence seq = java.nio.CharBuffer.wrap(array); </code></pre> <p>However, the <code>new String(array)</code> approach is likely to be easier to write, easier to read and faster.</p>
<p><strong>Context:</strong></p> <p>One of the most common usage of char[] instead of String, is to &quot;temporary&quot; store secrets/passwords. To pass it to initialization of some service/clients ... The sercrets are not needed after such initialization. But in java string is not possible to clear it from memory (m...
38,395
<p>I've Added a setup project to my solution (didn't use the wizard) I then added the primary output of the Windows Application I have coded to the Applcation Folder node (Right click the setup project in Solution-Explorer and select View -> File System). I Right clicked the User's Desktop node and selected 'Create Sho...
<p>You actually have to right-click on 'Primary Output From ' in your setup project, and create a shortcut to that. Then, you can move the shortcut over to the 'Users Desktop' location within your setup project.</p>
<p>You actually have to right-click on 'Primary Output From ' in your setup project, and create a shortcut to that. Then, you can move the shortcut over to the 'Users Desktop' location within your setup project.</p>
15,487
<p>I am trying to separate some asp logic out into a separate page. For now, I am trying to call a simple function. </p> <p>Here is the simple index page that I am using</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Calling a webservice from classic ASP&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;% If Reques...
<p><code>aspfunctions.asp</code> should be inside tags so the asp is &quot;executed&quot;, e.g.</p> <p>aspfunctions.asp file:</p> <pre><code>&lt;% sub doStuff() Response.Write(&quot;In Do Stuff&quot;) end sub %&gt; </code></pre> <p>Otherwise the asp in <code>aspfunctions.asp</code> is just seen as plain-text, so as...
<p>Make changes in two places:</p> <ol> <li>In aspfunctions.asp write "sub doStuff" instead of <code>sub doStuff()</code></li> <li>Call the function as <code>doStuff</code> not <code>doStuff()</code></li> </ol>
14,664
<p>I'd like to set a connection string programmatically, with absolutely no change to any config files / registry keys.</p> <p>I have this piece of code, but unfortunately it throws an exception with "the configuration is read only".</p> <pre><code>ConfigurationManager.ConnectionStrings.Clear(); string connectionStri...
<p>I've written about this in a <a href="http://davidgardiner.blogspot.com/2008/09/programmatically-setting.html" rel="noreferrer">post on my blog</a>. The trick is to use reflection to poke values in as a way to get access to the non-public fields (and methods).</p> <p>eg.</p> <pre><code>var settings = Configuration...
<p>ConfigurationManager is used to <em>read</em> from the config file.</p> <p>Your solution is to simply set conn.ConnectionString to the conn string you need.</p>
46,984
<p>What could be the cause of JVM thread dumps that show threads waiting to lock on a monitor, but the monitors do not have corresponding locking threads? </p> <p>Java 1.5_14 on Windows 2003</p>
<p>Does your code by any change use any JNI? (i.e. are you running any native code launched from Java?).</p> <p>We've seen a similar behavior, but JDK 1.6.0_05. App appears to deadlock, but Jstack shows threads waiting for a lock that no other threads are holding onto. We have some JNI code, so it's possible we're cor...
<p>That's just a wild guess, but could it be, that a thread locks itself by trying to acquire a lock twice? Probably it would help if you could post some code.</p>
9,066
<p>I have a function called FindSpecificRowValue that takes in a datatable and returns the row number that contains a particular value. If that value isn't found, I want to indicate so to the calling function.</p> <p>Is the best approach to:</p> <ol> <li>Write a function that returns false if not found, true if found...
<p>Personally I would not do either with that method name.</p> <p>I would instead make two methods:</p> <pre><code>TryFindSpecificRow FindSpecificRow </code></pre> <p>This would follow the pattern of Int32.Parse/TryParse, and in C# they could look like this:</p> <pre><code>public static Boolean TryFindSpecificRow(D...
<p>In this case, the item might not be there, and that's an okay condition. It's an error trap for unselected values in a GridView that binds to a datatable.</p>
30,641
<p>What is the best Image Manager to integrate in TinyMce editor apart the official Moxiecode commercial ones?</p> <p>I'm looking to integrate a light texteditor in an asp.net mvc application and I choosed the Tinymce solution (and not the classic FCKEditor as this seems more lightweight and more jquery friendly).</p>...
<p>There are a couple of open source plugins on SourceForge,</p> <p><a href="http://sourceforge.net/tracker/?group_id=103281&amp;atid=738747" rel="noreferrer">http://sourceforge.net/tracker/?group_id=103281&amp;atid=738747</a> (search for image)</p> <p>The plugin architecture is easy to understand if you know Javascr...
<p>Carlton : Alfresco seems to be a Java based solution. Ta: I've looked into the plugin folders but none was really good for asp.net mvc. What I'm now testing is a mix between Tiny with the image uploader of FCKEditor: this is the pho version but I think it is pretty easy to convert to .net [Tinyfck][1]</p> <p>[1]: t...
4,003
<p>I am developing a .NET CF 3.5 network game. My issue is the app loads all the resources at first instance. However upon subsequent launches, the app gives me memory out of exception while loading resources especially sounds or big images.</p> <p>Please guide me</p>
<p>I assume you're not attempting to lauch multiple instances of the game at a time. This sounds like memory is not being returned to the OS after your game shuts down. One simple way to determine if you have a leak is:</p> <ol> <li>Restart the device</li> <li>Check the memory usage </li> <li>Start your game, play i...
<p>How much memory is your application taking after loading all the resources ? On default settings I have been getting this error coming over cca 1.3 GB of private bytes (checking the task manager and the processes memory allocation).</p>
35,448
<p>I have a file. I want to get its contents into a blob column in my oracle database or into a blob variable in my PL/SQL program. What is the best way to do that?</p>
<p>To do it entirely in PL/SQL, the file would need to be on the server, located in a directory which you'd need to define in the database. Create the following objects:</p> <pre><code>CREATE OR REPLACE DIRECTORY BLOB_DIR AS '/oracle/base/lobs' / CREATE OR REPLACE PROCEDURE BLOB_LOAD AS lBlob BLOB...
<p>Depends a bit on your environment. In Java you could do it something like this...</p> <pre><code>// Need as OracleConnection in mConnection // Set an EMPTY_BLOB() String update = "UPDATE tablename"+ " SET blob_column = EMPTY_BLOB()"+ " WHERE ID = "+id; CallableStatement stmt = m...
14,959
<p>SQL Server Full Text Search uses language specific Word Breakers. </p> <p>For the German language this is used to break/split words including compound words. However, it appears not all known compound words are included in the Word Breaker. I would like to know if a list is available of the words the Word Breaker d...
<pre><code>public static bool IsInRuntimeMode( IComponent component ) { bool ret = IsInDesignMode( component ); return !ret; } public static bool IsInDesignMode( IComponent component ) { bool ret = false; if ( null != component ) { ISite site = component.Site; if ( null != site ) { ...
<p>This is the method I used in my project:</p> <pre><code>//use a Property or Field for keeping the info to avoid runtime computation public static bool NotInDesignMode { get; } = IsNotInDesignMode(); private static bool IsNotInDesignMode() { /* File.WriteAllLines(@"D:\1.log", new[] { LicenseManag...
43,695
<p>What are some of the techniques available to debug multi threading issues in .net environment.</p>
<p>Debugging and unit-testing multithreaded code is notoriously difficult, and I don't believe there are any tried and true solutions to debugging multiple threads.</p> <p>However, you can make it easier to write multithreaded code by taking a few notes from functional programming languages:</p> <p><strong>Use immuta...
<p>One source of multithreading bugs comes from failing to lock data that is used from multiple threads. Stress testing your app is a one technique to reveal some of these issues. The more threads that are contending with higher frequency for data the greater the chance of spotting a problem.</p> <p>Spotting that your...
41,506
<p>in a C program I have an long* that I want to serialize (thus converting to chars). A long doesn't fit in a single char, and the size varies depending of the processor (can be 4 bytes or 8 bytes).</p> <p>Theres a good way to make the serialization and de-serialization? </p>
<pre><code>long * longs; // ... int numChars = numLongs * sizeof(long); char* longsAsChars = (char*) longs; char* chars = malloc(numChars); memcpy(chars, longsAsChars, numChars); </code></pre>
<p>If you create a char pointer that points to the beginning of the long array, when you increment through the char "array", you'll get 8 bits at a time. Be aware, though, that the long won't be null-terminated (necessarily, it might be), so you need to keep track where the end of it is.</p> <p>For example:</p> <pre>...
19,834
<p>I have a .ini file with sensitive information in my php wab app. I denied access to it using a .htaccess file:</p> <pre><code>&lt;files my.ini&gt; order deny,allow deny from all &lt;/files&gt; </code></pre> <p>I don't have access to folders outside of htdocs, so I can't move the .ini file out of browsable terr...
<p>The .htaccess will block access from the web. However, if you're using a shared hosting environment, it might be possible for other users to access your ini. If its on a (virtual private) server and you're the only user for that server you're safe.</p> <p>In case of shared hosting it depends on server configuration...
<p>The file will not be visible from apache. Obviously the best option is to put it outside of your site's root. If you can't do that, .htaccess files (or similar directives in your apache configs) is pretty much your only option.</p>
26,554
<p>What are ways to draw animations in C++? GDI+? OpenGL? Would you recommend a class pattern in particular to get the drawing and redrawing done? </p> <p>Do you know of any open source project where animations are made so I can take a peek at the code?</p> <p>Where would you start if you wanted to code geometrical a...
<p>QT QGraphicsScene</p> <p>It was specifically designed to make writing 2D games easy and effortless, with great support for animation.<br> QT is a very mature cross platform toolkit which also have an open source flavor.</p>
<p>I know of this: <a href="http://www.openframeworks.cc/" rel="nofollow noreferrer">http://www.openframeworks.cc/</a></p> <p>and this: <a href="http://www.contextfreeart.org/" rel="nofollow noreferrer">http://www.contextfreeart.org/</a></p>
18,348
<p>Are there any 'good' resources for porting a VB.NET winforms application to C#? I'm sure there are is software that just translates the code, but I'm looking to refactor the code at the same time. Keeping it in its current form is problematic, since it uses some of the 'bad design' practices that VB.NET allows, an...
<p>Based on my experience working with some large applications that mix VB and C# projects, I would recommend leaving it in VB.NET. If there are problems with the design, then fix them, but converting the whole thing to C# sounds like a messy, unnecessary distraction to me.</p> <p>The non-stylistic differences between...
<p>Oo Wow ! I am the last person to catch the stuff. I have a very big VB.NET code in WinForms and have been assigned to port it to <strong>C#</strong> and <strong>WinForms</strong>. I have 0 knowledge of <strong>VB</strong> but had to get the task done. I used T<strong>elerik Online Code Converter</strong> to convert...
43,479
<p>Was reading up a bit on my C++, and found this article about RTTI (Runtime Type Identification): <a href="http://msdn.microsoft.com/en-us/library/70ky2y6k(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/70ky2y6k(VS.80).aspx</a> . Well, that's another subject :) - However, I stumbled up...
<p>How about this:</p> <pre><code>const char *getHelloString() const { return "HelloWorld!"; } </code></pre> <p>Returning a literal directly means the space for the string is allocated in static storage by the compiler and will be available throughout the duration of the program.</p>
<p>It's probably done using a static buffer:</p> <pre><code>const char* GetHelloString() { static char buffer[256] = { 0 }; strcpy( buffer, "Hello World!" ); return buffer; } </code></pre> <p>This buffer is like a global variable that is accessible only from this function.</p>
24,514
<p>Is it possible to do at least one of the following:</p> <p>1) Detect a setting of a Local Security Policy (Accounts: Limit local account use of blank passwords to console logon only)</p> <p>2) Modify that setting</p> <p>Using Win32/MFC?</p>
<ul> <li><a href="http://docs.plt-scheme.org/swindle/index.html" rel="noreferrer">Swindle</a> is primarily a CLOS emulator library, but it has list comprehensions too. I've used them, they're convenient, but the version I used was buggy and incomplete. (I just needed generic functions.)</li> <li>However, you probably w...
<p>You can use <a href="https://ironscheme.svn.codeplex.com/svn/IronScheme/IronSchemeConsole/ironscheme/linq.ss" rel="nofollow noreferrer">LINQ for R6RS Scheme</a> (although it could be made to run under 'older' implementations).</p>
15,912
<p>(sorry I should have been clearer with the code the first time I posted this. Hope this makes sense)</p> <p>File "size_specification.rb"</p> <pre><code>class SizeSpecification def fits? end end </code></pre> <p>File "some_module.rb"</p> <pre><code>require 'size_specification' module SomeModule def se...
<p>Are your settings and ruby installation ok? I created those 3 files and wrote what follows in "test.rb"</p> <pre><code>require 'yaml' require "some_module" SomeModule.sizes.first.fits? </code></pre> <p>Then I ran it.</p> <pre><code>$ ruby --version ruby 1.8.6 (2008-06-20 patchlevel 230) [i486-linux] $ ruby -w t...
<p>On second reading I'm a little confused, you seem to want to mix the class into module, which is porbably not so advisable. Also is the YAML supposed to load an array of the SizeSpecifications?</p> <p>It appears to be that you're not mixing the Module into your class. If I run the test in irb then the require thr...
10,483
<p>Consider this problem: I have a program which should fetch (let's say) 100 records from a database, and then for each one it should get updated information from a web service. There are two ways to introduce parallelism in this scenario:</p> <ol> <li><p>I start each request to the web service on a new Thread. The n...
<p>Option 3 is the best:</p> <p>Use Async IO.</p> <p>Unless your request processing is complex and heavy, your program is going to spend 99% of it's time waiting for the HTTP requests.</p> <p>This is exactly what Async IO is designed for - Let the windows networking stack (or .net framework or whatever) worry about ...
<p>The computer running the program is probably not the bottleneck, so: Remember that the HTTP protocol has a keep-alive header, that lets you send several GET requests on the same sockets, which saves you from the TCP/IP hand shake. Unfortunately I don't know how to use that in the .net libraries. (Should be possible....
3,144
<p>I am attempting to load an activex object on the same page where my flex application resides. Is this possible? Can I have 2 object tags on one page?</p> <p>As of right now the flex application loads fine but when I attempt to access the activeX control it says its null. But if I have the same activex control on ...
<p>Whoops, I found the error. It was a simple error in my javascript code. Turns out it works fine adding another Object tag and loading another activex control. Chalk this up as a learning experience.</p>
<p>Whoops, I found the error. It was a simple error in my javascript code. Turns out it works fine adding another Object tag and loading another activex control. Chalk this up as a learning experience.</p>
26,375
<p>I wish to display a list of letters from a through z on a form. Each letter needs to be clickable with that value being passed as a click argument. Aside from creating 26 letters and using the click event of each letter does anyone know of a quick way to do this? I know how to load dynamic controls etc and how to do...
<p>You can use a FlowLayoutPanel and a loop like this:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { flowLayoutPanel1.FlowDirection = FlowDirection.LeftToRight; flowLayoutPanel1.AutoSize = true; flowLayoutPanel1.WrapContents = false; //or true, whichever you like flowLayoutPanel1.Cont...
<p>Draw a string on a control, then match mouse clicks to the character positions on the form. It's actually easier than it sounds (this is adapted from standard documentation on MeasureCharacterRanges, which simplifies the entrire task). The example is drawn on a form, it would be simple enough to make this into a use...
42,847
<p>Let's say that you have overridden an object's equals() and hashCode() methods, so that they use the object's fields.</p> <p>How you do you check if two references are to the same object, ala the stock equals() method?</p>
<p>Use <code>==</code> on objects to perform identity comparison.</p> <p>That is what the default implementation of <code>equals()</code> does, but one normally overrides <code>equals()</code> to serve as an "equivalent content" check.</p>
<p>use == Operator because it compares with the reference not with the content, if u want to compare with content u can use equals() method. </p>
26,704
<p>Our groups legacy ASP 3.0 web apps were able to take advantage of a global error file by setting up a custom error file within IIS's Custom Error's tab. I'm unable to find a similar solution for ASP.NET apps. </p> <p>Does anyone know if there is a way to have a centralized "Error.aspx" page (for example) that wil...
<p>You can add the <code>&lt;customErrors defaultRedirect="[url]"&gt;&lt;/customErrors&gt;</code> tag to your web.config or even up to your machine.config to redirect to a custom error page. The custom errors tag also suppors multiple subelements that can be used to define custom errors.</p> <p>Just remember when ed...
<p>You an also capture the error by utilizing the Application_OnError event in the Global.asax file. Then, you can do as Ben R stated above. Capture the error via the Server.GetLastError() routine. </p>
27,203
<p>This question is for C# 2.0 Winform. </p> <p>For the moment I use checkboxes to select like this : Monday[x], Thuesday[x]¸... etc. </p> <p>It works fine but <strong>is it a better way to get the day of the week?</strong> (Can have more than one day picked)</p>
<p>Checkboxes are the standard UI component to use when selection of multiple items is allowed. From UI usability guru <a href="http://www.useit.com/jakob/" rel="nofollow noreferrer">Jakob Nielsen's</a> article on <a href="http://www.useit.com/alertbox/20040927.html" rel="nofollow noreferrer">Checkboxes vs. Radio Butt...
<p>Checkboxes would work fine, and there is a preexisting paradigm of that usage in Windows Scheduled Tasks. To see that example, create a scheduled task and select Weekly for the frequency.</p>
15,676
<p>Here's what I use:</p> <pre><code>SELECT CAST(FLOOR(CAST(getdate() as FLOAT)) as DATETIME) </code></pre> <p>I'm thinking there may be a better and more elegant way.</p> <p>Requirements:</p> <ul> <li>It has to be as fast as possible (the less casting, the better).</li> <li>The final result has to be a <code>datet...
<p><strong>SQL Server 2008 and up</strong></p> <p>In SQL Server 2008 and up, of course the fastest way is <code>Convert(date, @date)</code>. This can be cast back to a <code>datetime</code> or <code>datetime2</code> if necessary.</p> <p><strong>What Is Really Best In SQL Server 2005 and Older?</strong></p> <p>I've s...
<p>SQL2005: I recommend cast instead of dateadd. For example,</p> <pre><code>select cast(DATEDIFF(DAY, 0, datetimefield) as datetime) </code></pre> <p>averagely about 10% <em>faster</em> on my dataset, than</p> <pre><code>select DATEADD(DAY, DATEDIFF(DAY, 0, datetimefield), 0) </code></pre> <p>(and casting into smallda...
2,489
<p>Having a strange rendering issue with Safari: </p> <p>I have a table inside a div. Inside the table &lt;td&gt; I have lots of div's floated left. So the normal display is all of the divs within the td stacked up to the left until they fill the width, then flow to the next line, and so forth. So something like this:...
<p>Answering my own question: </p> <p>Finally figured out the issue: my inner divs (the "XXX"s) had white-space: nowrap. Apparently webkit was no-wrap'ing the entire list of divs instead of applying the nowrap within the div.</p> <p>That was a nasty one.</p> <p>(This had nothing to do with display:none)</p>
<p>Actually, I asked my above question separately, then I found the solution like a big boy: </p> <p>Instead of using white-space:nowrap, in this case it's more appropriate to go with display:inline-block.</p> <p>The CSS needs to be adapted here and there for the change, but it works as expected.</p> <p><a href="htt...
26,002
<p>I want to copy a live production database into my local development database. Is there a way to do this without locking the production database?</p> <p>I'm currently using:</p> <pre class="lang-none prettyprint-override"><code>mysqldump -u root --password=xxx -h xxx my_db1 | mysql -u root --password=xxx -h localh...
<p>Does the <code>--lock-tables=false</code> option work?</p> <p>According to the <a href="https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_lock-tables" rel="noreferrer">man page</a>, if you are dumping InnoDB tables you can use the <code>--single-transaction</code> option:</p> <pre class="lang-n...
<p>As none of these approaches worked for me, I simply did a:</p> <pre><code>mysqldump [...] | grep -v "LOCK TABLE" | mysql [...] </code></pre> <p>It will exclude both <code>LOCK TABLE &lt;x&gt;</code> and <code>UNLOCK TABLES</code> commands.</p> <p><strong>Note:</strong> Hopefully your data doesn't contain that str...
13,024
<p>This problem has been occurring for a while. On the top of round objects, you can see the individual layers. Maybe I just need a lower layer height.</p> <p><a href="https://i.stack.imgur.com/AQqhp.jpg" rel="nofollow noreferrer" title="Photo of a 3D printed model with printing errors on the top"><img src="https://i.s...
<p>At the top of curves layers will always be more visible because the layers are increasing offset from each other. Layer height will help with this, but if you really want it smooth you will need to do some post-processing.</p> <p>Usually if possible I avoid having a top surface like that of any significant size. But...
<p>Kilisi is absolutely right that you necessarily (without advanced non-planar slicing techniques that aren't available in production slicers) have a &quot;stairstep&quot; effect whenever you have a shallow angle top surface like that. However, it looks from your picture like you also have some <em>gaps</em> that are ...
2,126
<p>I have wondered about the appropriateness of reflection in C# code. For example I have written a function which iterates through the properties of a given source object and creates a new instance of a specified type, then copies the values of properties with the same name from one to the other. I created this to cop...
<p>Sometimes using reflection can be a bit of a hack, but a lot of the time it's simply the most fantastic code tool.</p> <p>Look at the .Net property grid - anyone who's used Visual Studio will be familiar with it. You can point it at any object and it it will produce a simple property editor. That uses reflection, i...
<p>Reflection makes it very easy to implement plugin architectures where plugin DLLs are automatically loaded at runtime (not explicitly linked at compile time).</p> <p>These can be scanned for classes that implement/extend relevant interfaces/classes. Reflection can then be used to instantiate instances of these on ...
7,012
<p>Is it really necessary to release COM components from Office PIA, when you don't need them anymore by invoking Marshal.ReleaseComObject(..)?</p> <p>I found various and contradictory advices on this topic on the web. In my opinion, since Outlook PIA is always returning a new references to its interfaces as returning...
<p>With Microsoft Office, in general, you do need to explicitly release your references, which can be safely done in two stages:</p> <p>(1) First release all the minor object to which you do not hold a named object variable via a call to GC.Collect() and then GC.WaitForPendingFinalizers(). (You need to call this twice...
<p>Maybe it's just my superstition, but I decided to explicitly release the Office PIA via Marshal.ReleaseComObject() because when my application crashed, the references to Excel and Word were staying open. I didn't dig too deep into why (stupid deadlines), but releasing them as part of my class's dispose pattern fixed...
20,160
<p>I take care of critical app in my project. It does stuff related to parsing business msgs (legacy standard), processing them and then storing some results in a DB (another apps picks that up). After more then a year of my work (I've other apps to look after as well) the app is finally stable. I've introduced strict ...
<p>I would advise you <strong>not</strong> to inherit your specific message handling classes from base classes that contain the common code like this:</p> <pre><code> CommonHandler ^ ^ | | = inheritance MsgAHandle...
<p>That <em>does</em> sound like a fun challenge. :-)</p> <p>Your "initial plan" sounds like a good one: factor out all of the similar processing between all of the messages and put the code for them in a base message class. The changing items can become virtual functions (such as <code>CheckForRequiredLines</code> or...
29,299
<p>Most statistics out there for browser stats show you the resolution of the screen.</p> <p>Thats fine for Windows where browsers typically open full screen and most people leave it as that. So if the browser stats say 1024x768 you just need to subtract a little width for the browser chrome.</p> <p>On a Mac however ...
<p><strong>Design away, my friend. The Apple display packs many pixels.</strong></p> <p>A window <strong>will open to fullscreen</strong> on the Mac, no problem. It simply conserves space when it can, unlike the PC behavior, which will fill the screen regardless of how much space the site actually needs.</p> <p>In oth...
<p>The stats you've read are based on actual screen sizes of visitors. If you're looking for stats on what size the average user's browser is at, you'll need to look elsewhere. Also I never browse full screen on windows or mac OS, and I consider a design that's wider than 960px or so to be very annoying. (it's 2^16+2^...
32,190
<p>I've been trying to implement unit testing and currently have some code that does the following:</p> <ol> <li>query external database, loading into a feed table </li> <li>query a view, which is a delta of my feed and data tables, updating data table to match feed table</li> </ol> <p>my unit testing strategy is thi...
<p>Is it your intent to test the view which generates the deltas, or to test that your code correctly adds, deletes and updates in response to the view?</p> <p>If you want to test the view, you could use a tool like <a href="http://dbunit.sourceforge.net/" rel="noreferrer">DBUnit</a> to populate your feed and data tab...
<p>I use DbUnit, but also I work very hard to not to have to test against the DB. Tests that go against the database should only exist for the purpose of testing the database interface. So I have Mock Db Connections that I can set the data for use in all the rest of my tests.</p>
6,980
<p>Are there any good code profilers/analyzers for Erlang? I need something that can build a call graph (eg gprof) for my code.</p>
<p>For static code analysis you have <a href="http://www.erlang.org/doc/man/xref.html" rel="nofollow noreferrer">Xref</a> and <a href="http://www.it.uu.se/research/group/hipe/dialyzer/" rel="nofollow noreferrer">Dialyzer</a>, for profiling you can use cprof, fprof or eprof, reference <a href="http://www.erlang.org/docu...
<p>Try this one: <a href="https://github.com/virtan/eep" rel="nofollow">https://github.com/virtan/eep</a> You could get something like this <a href="https://raw.github.com/virtan/eep/master/doc/sshot1.png" rel="nofollow">https://raw.github.com/virtan/eep/master/doc/sshot1.png</a></p>
25,101
<p>Is the SqlClient.SqlDataReader a .NET managed object or not? Why do we have to call the Close() method explicitly close an open connection? Shouldn't running out of scope for such an object automatically close this? Shouldn't garbage collector clean it up anyway?</p> <p>Please help me understand what is the best pr...
<p>Sure, it will be collected when it goes out of scope (if their are no other references to it). When it is collected, it will be closed through its Dispose() method. However, you never really know when the GC is going to deallocate things; if you don't close your readers, you very quickly run out of available conne...
<p>Also take into consideration what happens when an exception gets thrown - you never know if the connection will be closed if you suddenly are forced out of the executing code. </p> <p>As a rule in our shop, we explicitly wrap all database calls in a Try...Finally block, with the finally section catching and closing...
31,163
<p>Will the code below work if the clock on the server is ahead of the clock on the client?</p> <pre><code>Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)) </code></pre> <p>EDIT: the reason I ask is on one of our web apps some users are claiming they are seeing the pages ( account numbers, etc ) from a user tha...
<p><a href="https://stackoverflow.com/questions/49547/making-sure-a-webpage-is-not-cached-across-all-browsers">This question</a> covers making sure a webpage is not cached. It seems you have to set several properties to ensure a web page is not cached across all browsers.</p>
<p>Your problem could be caused by the browser remembering data entered into form fields. You can turn this off like this:</p> <pre><code>&lt;input autocomplete="off"&gt; </code></pre>
8,157
<p>I'm trying to split a string up into words and punctuation, adding the punctuation to the list produced by the split.</p> <p>For instance:</p> <pre><code>&gt;&gt;&gt; c = "help, me" &gt;&gt;&gt; print c.split() ['help,', 'me'] </code></pre> <p>What I really want the list to look like is:</p> <pre><code>['help', ...
<p>This is more or less the way to do it:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.findall(r"[\w']+|[.,!?;]", "Hello, I'm a string!") ['Hello', ',', "I'm", 'a', 'string', '!'] </code></pre> <p>The trick is, not to think about where to split the string, but what to include in the tokens.</p> <p>Caveats:<...
<p>Have you tried using a regex?</p> <p><a href="http://docs.python.org/library/re.html#re-syntax" rel="nofollow noreferrer">http://docs.python.org/library/re.html#re-syntax</a></p> <hr> <p>By the way. Why do you need the "," at the second one? You will know that after each text is written i.e. </p> <p>[0]</p> <p>...
47,922
<p>If I select from a table group by the month, day, year, it only returns rows with records and leaves out combinations without any records, making it appear at a glance that every day or month has activity, you have to look at the date column actively for gaps. How can I get a row for every day/month/year, even when...
<p>Create a calendar table and outer join on that table</p>
<p>Look into using a <a href="http://andre-silva-cardoso.blogspot.com/2007/11/sql-trickspatterns-1-numbers-table.html" rel="nofollow noreferrer">numbers table</a>. While it can be hackish, it's the best method I've come by to quickly query missing data, or show all dates, or anything where you want to examine values w...
6,168
<p>Here's the problem:</p> <p>1.) We have page here... www.blah.com/mypage.html</p> <p>2.) That page requests a js file www.foo.com like this...</p> <pre><code>&lt;script type="text/javascript" src="http://www.foo.com/jsfile.js" /&gt; </code></pre> <p>3.) "jsfile.js" uses Prototype to make an Ajax request back to w...
<p>It is XSS and it is forbidden. You should really not do things that way. </p> <p>If you really need to, make your AJAX code call the local code (PHP, ASP, whatever) on blah.com and make it behave like client and fetch whatever you need from foo.com and return that back to the client. If you use PHP, you can do this...
<p>The method shown above could become a large security hole. Suggest you verify the site name against a white list and build the actual URI being proxied on the server side.</p>
41,250
<p>What is the difference between <code>ROWNUM</code> and <code>ROW_NUMBER</code> ? </p>
<p>ROWNUM is a "pseudocolumn" that assigns a number to each row returned by a query:</p> <pre><code>SQL&gt; select rownum, ename, deptno 2 from emp; ROWNUM ENAME DEPTNO ---------- ---------- ---------- 1 SMITH 99 2 ALLEN 30 3 WARD 30 ...
<p><a href="http://www.adp-gmbh.ch/ora/sql/rownum.html" rel="nofollow noreferrer">rownum</a> is a pseudocolumn which can be added to any select query, to number the rows returned (starting with 1). They are ordered according to when they were identified as being part of the final result set. (<a href="https://stackover...
21,044
<p>I haven't used <code>C++</code> since college. Even though I've wanted to I haven't needed to do any until I started wanting to write plugins for <code>Launchy</code>. </p> <blockquote> <p>Is there a good book to read to get back into it?</p> </blockquote> <p>My experience since college is mainly <code>C#</code...
<p>The best way to get back into C++ is to jump in. You can't learn a real language without spending any serious time in a country where they speak it. I wouldn't try to learn a programming language without spending time coding in it either.</p> <p>I wouldn't recommend learning C first though. That's a good way to ...
<p><a href="https://rads.stackoverflow.com/amzn/click/com/0201700735" rel="nofollow noreferrer" rel="nofollow noreferrer">The C++ Programming Language</a> by Bjarne Stroustrup covers C++ in depth. Bjarne is the inventor of C++. It also provides insights into why the language is the way it is. Some people find the book ...
5,810
<p>I am having difficulty refreshing windows forms controls that are using a BindingSource object. We have a CAB/MVP/SCSF client that I (actually “we” since it is a team effort) are developing that will interact with WCF services running on a remote server. (This is our first attempt at this, so we are in a learning m...
<p>I was having a similar issue today and found this works.</p> <pre><code>private void btnCancel_Click(object sender, EventArgs e) { this.MyTable.RejectChanges(); this.txtMyBoundTextBox.DataBindings[0].ReadValue(); this.EditState = EditStates.NotEditting; } </code></pre>
<p>Failing all else, you can reassign the DataSource every time you receive a new dataset, doing something like this:</p> <pre><code>bindsrcContract.DataSource = typeof(System.Data.DataSet); bindsrcContract.DataSource = _ds; </code></pre> <p>(Also, initializing DataMember first and then DataSource will give you bette...
30,337
<p>how do I translate this code into jython?</p> <pre><code> ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file + ".zip")); byte[] buf = new byte[1024]; int len; //Create a new Zip entry with the file's name. ZipEntry zipEntry = new ZipEntry(file.toString()); //Create a bu...
<p>Here's an exact translation of that function (except, like your case, using <code>bin</code> instead of reserved keyword <code>in</code>).</p> <pre><code>from jarray import zeros from java.io import BufferedInputStream, FileInputStream, FileOutputStream from java.util.zip import ZipEntry, ZipOutputStream def test(...
<p>Don't use ZipFile without ensuring it is closed:</p> <pre><code>with ZipFile('spam.zip', 'w') as myzip: myzip.write('eggs.txt') </code></pre>
39,687
<p>I have written a watir script that downloads files. One of the files it downloads has a .dcf extension. Months ago, on my machine, I changed a setting somewhere so that .dcf files prompt for download ("Do you want to open or save this file?") instead of opening in the browser. This is the behavior that I desire. I ...
<p>instructions here:<br> <a href="http://www.mydigitallife.info/2007/06/15/disable-automatic-opening-or-saving-of-downloads-re-enable-always-ask-before-check-box/" rel="nofollow noreferrer"><a href="http://www.mydigitallife.info/2007/06/15/disable-automatic-opening-or-saving-of-downloads-re-enable-always-ask-before-ch...
<p>For PHP, try using these headers:</p> <p>header("Content-Type: application/force-download");</p> <p>header("Content-Type: application/octet-stream");</p> <p>header("Content-Type: application/download");</p> <p>header("Content-Disposition: attachment; filename=".basename($filename).";");</p> <p>Naturally you can...
18,636
<p>As a simple example, I want to write a CLI script which can print <code>=</code> across the entire width of the terminal window.</p> <pre><code>#!/usr/bin/env php &lt;?php echo str_repeat('=', ???); </code></pre> <p>or</p> <pre><code>#!/usr/bin/env python print '=' * ??? </code></pre> <p>or</p> <pre><code>#!/us...
<ul> <li><code>tput cols</code> tells you the number of columns.</li> <li><code>tput lines</code> tells you the number of rows.</li> </ul>
<p>There are some cases where your rows/LINES and columns do not match the actual size of the "terminal" being used. Perhaps you may not have a "tput" or "stty" available.</p> <p>Here is a bash function you can use to visually check the size. This will work up to 140 columns x 80 rows. You can adjust the maximums as n...
33,044
<p>I have an application with one form in it, and on the Load method I need to hide the form. </p> <p>The form will display itself when it has a need to (think along the lines of a outlook 2003 style popup), but I can' figure out how to hide the form on load without something messy.</p> <p>Any suggestions?</p>
<p>I'm coming at this from C#, but should be very similar in vb.net.</p> <p>In your main program file, in the Main method, you will have something like:</p> <pre><code>Application.Run(new MainForm()); </code></pre> <p>This creates a new main form and limits the lifetime of the application to the lifetime of the main...
<p>Here is a simple approach:<br> It's in C# (I don't have VB compiler at the moment)</p> <pre><code>public Form1() { InitializeComponent(); Hide(); // Also Visible = false can be used } private void Form1_Load(object sender, EventArgs e) { Thread.Sleep(10000); Show(); // Or visible = true; } </code><...
9,564
<p>I am looking for url encoding tips for SEO compliant site.</p> <p>I have a list of variables I need!</p> <p>hypen = used to split locations, Leeds-UK-England <br /> space = underscore for where spaces occur<br /> hypen = plus sign used in some british locations (stafford-upon-avon)<br /> forward slash = exclamatio...
<p>Google used not to recognise underscores as word separators - see this <a href="http://www.mattcutts.com/blog/dashes-vs-underscores/" rel="nofollow noreferrer">article from 2005</a>. This has entered into received wisdom and most of the 'experts' and articles you will find on SEO will still be recommending this.</p...
<p>Hyphens for spaces is the usual and preferred method.</p>
45,602
<p>I need to create a photo gallery for a website running IIS 4.0 or IIS 5.0 (im not sure which). It needs to display a low resolution version of the gallery to anyone, and it must show both the low and high resolution images for "priviledged" users. So I need access priviledges, photo albums and once the site is compl...
<p>If you don't want to re-invent the wheel you could use <a href="http://gallery.menalto.com/" rel="nofollow noreferrer">Gallery2</a> (requirements <a href="http://codex.gallery2.org/Gallery2:Installation_Requirements" rel="nofollow noreferrer">here</a>). It runs on IIS -- you'd just need PHP and a database. It's very...
<p>Flickr.com and their API may be suitable from what you described.</p> <p><a href="http://www.flickr.com/services/api/" rel="nofollow noreferrer">http://www.flickr.com/services/api/</a></p>
43,194
<p>I'd like to automatically generate database scripts on a regular basis. Is this possible.</p>
<p>To generate script for an object you have to pass up to six parameters:</p> <pre><code>exec proc_genscript @ServerName = 'Server Name', @DBName = 'Database Name', @ObjectName = 'Object Name to generate script for', @ObjectType = 'Object Type', @TableName = 'Parent table name for index and t...
<p>You might want to look at the SQL Server Management Objects (SMO). There are objects for scripting that will assist in generating T-SQL scripts from database objects. A good reference for this is <a href="https://rads.stackoverflow.com/amzn/click/com/0596004796" rel="nofollow noreferrer" rel="nofollow noreferrer">...
11,871
<p>To add a NOT NULL Column to a table with many records, a DEFAULT constraint needs to be applied. This constraint causes the entire ALTER TABLE command to take a long time to run if the table is very large. This is because:</p> <p>Assumptions:</p> <ol> <li>The DEFAULT constraint modifies existing records. This mean...
<p>I ran into this problem for my work also. And my solution is along #2.</p> <p>Here are my steps (I am using SQL Server 2005):</p> <p>1) Add the column to the table with a default value:</p> <pre><code>ALTER TABLE MyTable ADD MyColumn varchar(40) DEFAULT('') </code></pre> <p>2) Add a <code>NOT NULL</code> constra...
<p>Vertically segment the table. This means you will have two tables, with the same primary key, and exactly the same number of records... One will be the one you already have, the other will have just the key, and the new Non-Null column (with default value) . Modify all Insert, Update, and delete code so they keep t...
36,639
<p>Ok, I have a strange exception thrown from my code that's been bothering me for ages.</p> <pre><code>System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall at System.Net.Sockets.Socket.Accept() at System.Net.Sockets.TcpListener.AcceptTcpClient() </code></pr...
<p>Is it possible that the serverSocket is being closed from another thread? That will cause this exception.</p>
<p>More recently I saw this exception when using HttpWebRequest to PUT a large file and the Timeout period was passed.</p> <p>Using the following code as long as your upload time > 3 seconds it will cause this error as far as I could see.</p> <pre><code>string path = "Reasonably large file.dat"; int bufferSize = 1024...
5,181
<p>how do i check if an item is selected or not in my listbox? so i have a button remove, but i only want that button to execute if an item is selected in the list box. im using asp.net code behind C#. I'd prefer if this validation occurred on the server side.</p> <p>cheers..</p>
<p>On the callback for the button click, just check if the selected index of the list box is greater than or equal to zero.</p> <pre><code>protected void removeButton_Click( object sender, EventArgs e ) { if (listBox.SelectedIndex &gt;= 0) { listBox.Items.RemoveAt( listBox.SelectedIndex ); } } </co...
<pre><code>for (int i = 0; i &lt; lbSrc.Items.Count; i++) { if (lbSrc.Items[i].Selected == true) { lbSrc.Items.RemoveAt(lbSrc.SelectedIndex); } } </code></pre> <p>this is what i came up with.</p>
34,092
<p>What is the preferred way to remove spaces from a string in C++? I could loop through all the characters and build a new string, but is there a better way?</p>
<p>The best thing to do is to use the algorithm <a href="http://en.cppreference.com/w/cpp/algorithm/remove" rel="noreferrer"><code>remove_if</code></a> and isspace:</p> <pre><code>remove_if(str.begin(), str.end(), isspace); </code></pre> <p>Now the algorithm itself can't change the container(only modify the values), ...
<p>I'm afraid it's the best solution that I can think of. But you can use reserve() to pre-allocate the minimum required memory in advance to speed up things a bit. You'll end up with a new string that will probably be shorter but that takes up the same amount of memory, but you'll avoid reallocations.</p> <p>EDIT: De...
10,909
<p>Is there a performance difference between <code>i++</code> and <code>++i</code> if the resulting value is not used?</p>
<p>Executive summary: No.</p> <p><code>i++</code> could potentially be slower than <code>++i</code>, since the old value of <code>i</code> might need to be saved for later use, but in practice all modern compilers will optimize this away.</p> <p>We can demonstrate this by looking at the code for this function, both ...
<p>My C is a little rusty, so I apologize in advance. Speedwise, I can understand the results. But, I am confused as to how both files came out to the same MD5 hash. Maybe a for loop runs the same, but wouldn't the following 2 lines of code generate different assembly?</p> <pre><code>myArray[i++] = "hello"; </code>...
4,452
<p>I want to create an organisational chart in ASP.NET. Does anyone have any recommendations for components to do this. Most third-party charting packages don't handle organisational charts. The chart should also draw left to right rather than top to bottom as most organisational charts do.</p>
<p>It's not an ASP.NET component but you can make a web service or render the JavaScript dynamically. <a href="http://code.google.com/intl/en-US/apis/visualization/documentation/gallery/orgchart.html" rel="nofollow noreferrer">Google Visualization API - Organizational Chart</a>. </p> <p>I don't know if it has a left ...
<p>If you don´t mind paying for third party components, then there are a few available. .NET Charting is not too bad and I think Dundas has this functionality in it´s excellent charting suite. Both of these offer evaluation. </p>
47,904
<p>this is not a primary key, but merely used as a marker in existing system that marks these items with a 1 letter code ie 'N' for new, 'R' for return, etc. I was going to go with a varchar(50) as the data type but wondering if there's anything wrong with say varchar(2) instead aiming for efficiency. thx!</p>
<p>The best datatype would be char(1). </p> <p>varchar means <a href="http://msdn.microsoft.com/en-us/library/aa258242(SQL.80).aspx" rel="noreferrer">variable width</a>, that is, if on a varchar(50) you store only 3 characters, there will be no 47 wasted bytes. But there is a (small) performance hit on accessing it as...
<p>char(1) if it's always 1 character.</p> <p>Unless you see good reason that it should be expanded in the future - and even then, you might want to look at the design and use a surrogate key to a lookup table with your varchar(50) or whatever.</p>
36,671
<p>I am loading some data from an XML document, modifying it, and writing back out to XML. The reading is done using a SAX parser library and the writing is done with a piece of custom code. Sometimes, the file is modified externally, and extra elements are added (such as references to stylesheets). Rather than losi...
<p>I don't know how you've written your content handler, but it's methods should be called on all events, including on the external modifications you want to preserve. Your <code>startElement()</code> and <code>endElement()</code> callbacks could test element name and attributes to decide whether to call specialized m...
<p>I believe SAX is not the right way to go when you want to modify an xml file and save it back to some other file after being altered. My advice is to use DOM. It will load the entire file (including the modifications done externally) so that you just have to think about what you want to do. Everything will be back i...
31,225
<p>What is the difference between</p> <ul> <li>A simple <em>fields-accesors-mutators</em> class</li> <li>A rich-modeled class</li> </ul> <p>What constitutes rich modeling in business-domain classes?</p>
<p>"Rich" as used here implies "rich behavior" (as opposed to state).</p> <p>There is technical behavior and domain behavior. <em>Accessors</em> and <em>mutators</em> are technical; they lack the "why" which defines business interest.</p> <p>Domain objects represent the "why" and encapsulate the "how". Actually, all ...
<p>When your business logic is encapsulated in your business objects. In other words, you have a Business Objects (Domain Model) layer, without the need for a separate Business Logic layer.</p>
40,155
<p>I have the following code in my Django application:</p> <pre><code>if 'book' in authorForm.changed_data: #Do something here... </code></pre> <p>I realize Django can tell me which values have changed in my form by utilizing the "changed_data" list object, but I'd like to know the new values of the fields that ha...
<p>Hmm... Try this:</p> <pre><code>if authorForm.is_valid() and 'book' in authorForm.changed_data: new_value = authorForm.cleaned_data['book'] </code></pre>
<p>The short answer to my original question is "No".</p>
30,800
<p>I am trying to install newgem on my linux box (sudo gem install newgem) and i am getting the following error:</p> <pre><code>Building native extensions. This could take a while... ERROR: Error installing newgem: ERROR: Failed to build gem native extension. /usr/bin/ruby1.8 extconf.rb install newgem extconf.rb:1:...
<p><code>mkmf</code> is a Ruby module which generates Makefiles. It is supposed to be part of the standard Ruby install, but Debian (and derivatives) split it out into the <code>ruby1.8-dev</code> package.</p> <p>If you can't find <code>mkmf.rb</code> in any of the directories outputted by <code>ruby -e'print $:.join...
<p>Its probably caused by one of its dependencies. I don't think it needs all those dependencies anymore. If its still an issue, raise a bug at <a href="http://drnic.lighthouseapp.com/projects/18881-newgem/" rel="nofollow noreferrer">http://drnic.lighthouseapp.com/projects/18881-newgem/</a> and we'll see what dependenc...
22,198
<p>Let say that I have a website with some information that could be access externally. Those information need to be only change by the respected client. Example: Google Analytic or WordPress API key. How can I create a system that work like that (no matter the programming language)?</p>
<p>A number of smart people are working on a standard, and it's called <a href="http://oauth.net/" rel="noreferrer">OAuth</a>. It already has a number of <a href="http://oauth.net/code" rel="noreferrer">sample implementations</a>, so it's pretty easy to get started.</p>
<p>A good way of generating a key would be to store a GUID (Globally Unique Identifier) on each user record n the database. GUID is going to be unique and almost impossible to guess.</p>
10,285
<p>I am making a game in JAVA where I want to come up with a list of files in a certain directory in my jar so I can make sure to have a list of those classes to be used in the game.</p> <p>For example say in my jar I have a directory </p> <pre><code>mtd/entity/creep/ </code></pre> <p>I want to get a list of all the...
<p>Old java1.4 code, but that would give you the idea:</p> <pre><code>private static List getClassesFromJARFile(String jar, String packageName) throws Error { final List classes = new ArrayList(); JarInputStream jarFile = null; try { jarFile = new JarInputStream(new FileInputStream(jar)); ...
<p>It's not possible, as Java doesn't provide direct access to the jar file the classes are loaded from. You could try to parse the java.class.path system property to find it, but that wouldn't work under all circumstances. Or you could restrict on where the jar file has to reside, or provide the list of the classes in...
45,125
<p>The StackOverflow transcripts are enormous, and sometimes I want to link to a little bit within it.</p> <p>How do I create an HTML anchor in a FogBugz wiki page?</p>
<p>As of this writing, this feature is now supported -- just edit the wiki page's html directly (via the &lt;> button).</p> <p>See <a href="http://fogbugz.stackexchange.com/questions/2967/create-html-anchors-in-wiki-pages" rel="nofollow">this support question</a> for details. Use html anchor tags as you would in a typ...
<p>It doesn't appear to be possible.</p>
2,753
<p>I use a Prusa i3, and this is ABS printed part with 225/90°C. Why did this happen?</p> <p><a href="https://i.stack.imgur.com/qQbFC.jpg" rel="nofollow noreferrer" title="First ABS print - image#1"><img src="https://i.stack.imgur.com/qQbFC.jpg" alt="First ABS print - image#1" title="First ABS print - image#1"></a> <a...
<p>My best results with ABS have been with a hot bed (100 degrees C), and using the "acetone/ABS slurry" to stick the print to the bed.</p> <p>I was not able to get ABS to stick well enough to blue tape at low bed temperatures, and at high bed temperatures the blue tape would sometimes separate from the bed.</p> <p>T...
<p>Try putting your printer into a heated chamber, and when the print is finished, slowly decrease the temperature of the chamber. I would also recommend using putting something like buildtak or printbite onto your buildplate. If you are not able to do that I would recommend putting some purple gluestick onto the bed, ...
751
<p>I'm looking for a way to extract the audio part of a FLV file. </p> <p>I'm recording from the user's microphone and the audio is encoded using the <a href="http://en.wikipedia.org/wiki/Nellymoser_Asao_Codec" rel="nofollow noreferrer">Nellymoser Asao Codec</a>. This is the default codec and there's no way to change ...
<p><a href="http://ffmpeg.mplayerhq.hu/" rel="nofollow noreferrer">ffMpeg</a> is the way to go ! It worked for me with SVN Rev 14277.</p> <p>The command I used is : <code>ffmpeg -i source.flv -nv -f mp3 destination.mp3</code></p> <p><strong>GOTCHA</strong> :</p> <p>If you get this error message : <code>Unsupported a...
<p>I was going to recommend this: <a href="http://code.google.com/hosting/takenDown?project=nelly2pcm&amp;notice=7281" rel="nofollow noreferrer">http://code.google.com/hosting/takenDown?project=nelly2pcm&amp;notice=7281</a>.</p> <p>But its been taken down. Glad I got a copy first :-)</p>
9,320
<p>How do you convert a numerical number to an Excel column name in C# without using automation getting the value directly from Excel.</p> <p>Excel 2007 has a possible range of 1 to 16384, which is the number of columns that it supports. The resulting values should be in the form of excel column names, e.g. A, AA, AAA...
<p>Here's how I do it:</p> <pre><code>private string GetExcelColumnName(int columnNumber) { string columnName = &quot;&quot;; while (columnNumber &gt; 0) { int modulo = (columnNumber - 1) % 26; columnName = Convert.ToChar('A' + modulo) + columnName; columnNumber = (columnNumber - mo...
<pre><code> public string ToBase26(int number) { if (number &lt; 0) return String.Empty; int remainder = number % 26; int value = number / 26; return value == 0 ? String.Format("{0}", Convert.ToChar(65 + remainder)) : String.Format("{0}{1}", ToBase26(valu...
21,921
<p>I've created a forum, and we're implementing an apc and memcache caching solution to save the database some work.</p> <p>I started implementing the cache layer with keys like "Categories::getAll", and if I had user-specific data, I'd append the keys with stuff like the user ID, so you'd get <code>"User::getFavorite...
<p>You might also want to have a look at the cost of storing the cache data, in terms of your effort and CPU cost, against how what the cache will buy you. </p> <p>If you find that 80% of your forum views are looking at the first page of threads, then you could decide to cache that page only. That would mean both cach...
<p>One possible solution is not to paginate the cache of threads in a forum, but rather put the thread information in to <code>Forum::getThreads|$iForumId</code>. Then in your PHP code only pull out the ones you want for that given page, e.g.</p> <pre><code>$page = 2; $threads_per_page = 25; $start_thread = $page * $t...
13,476
<p>How do I implement a circular list that overwrites the oldest entry when it's full? </p> <p>For a little background, I want to use a circular list within GWT; so using a 3rd party lib is <strong>not</strong> what I want.</p>
<p>A very simple implementation, expressed in C. Implements a circular buffer style FIFO queue. Could be made more generic by creating a structure containing the queue size, queue data, and queue indexes (in and out), which would be passed in with the data to add or remove from the queue. These same routines could t...
<p>Here is an elegant way to create <strong>dynamically increasing/decreasing circular queue</strong> using <strong><em>java</em></strong>. </p> <p>I have commented most part of the code for easy &amp; fast understanding. Hope it helps :)</p> <pre><code> public class CircularQueueDemo { public static void main...
26,494
<p>I have a flash app in my page, and when a user interacts with the flash app, the browser/html/javascript stops receiving keyboard input. </p> <p>For example, in Firefox control-t no longer opens a new tab.</p> <p>However, if I click on part of the page that isn't flash, the browser starts receiving these events a...
<p>You can use the ExternalInterface class within Flash to call JavaScript. For example you could set up a function on an interval (Event.ENTER_FRAME for example) to call the JavaScript function that @Diodeus mentioned:</p> <pre><code>document.body.focus(); </code></pre> <p>Or, an even better solution would be to add...
<p>You can return the focus to the browser by doing a geturl can calling javascript on the HTML page:</p> <pre><code>document.body.focus() </code></pre> <p>How you do this in your Flash movie will depend on how the user interaction with the movie works. You could keep doing it on a timer, or when a control loses focu...
31,685
<p>looking tutorials for integrating OpenId feature in .net </p>
<p>I have a feeling that this <a href="http://code.google.com/p/dotnetopenid/" rel="nofollow noreferrer">Google Code Project</a> will be a great place to start. I just started looking at it myself a while back, I haven't had much time to dig in, but it looks promising for those not wanting to spend much time implement...
<p><a href="http://openid.net/get-an-openid/start-using-your-openid/" rel="nofollow">This document</a> explains working of OpenID and shows the whole process with screenshots. </p> <p><a href="http://code.google.com/apis/accounts/docs/OpenID.html" rel="nofollow">Document</a> describes how to implement Google login int...
44,638
<p>How does one write a unittest that fails only if a function doesn't throw an expected exception?</p>
<p>Use <a href="http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises" rel="noreferrer"><code>TestCase.assertRaises</code></a> (or <code>TestCase.failUnlessRaises</code>) from the unittest module, for example:</p> <pre><code>import mymod class MyTestCase(unittest.TestCase): def test1(self): ...
<p>While all the answers are perfectly fine, I was looking for a way to test if a function raised an exception without relying on unit testing frameworks and having to write test classes.</p> <p>I ended up writing the following:</p> <pre class="lang-py prettyprint-override"><code>def assert_error(e, x): try: ...
15,746
<p>In C++ when a virtual function is called from within a constructor it doesn't behave like a virtual function.</p> <p>I think everyone who encountered this behavior for the first time was surprised but on second thought it made sense:</p> <p>As long as the derived constructor has not been executed the object is <st...
<p>There's a fundamental difference in how the languages define an object's life time. In Java and .Net the object members are zero/null initialized before any constructor is run and is at this point that the object life time begins. So when you enter the constructor you've already got an initialized object.</p> <p>In...
<p>Delphi makes good use of virtual constructors in the VCL GUI framework: </p> <pre><code>type TComponent = class public constructor Create(AOwner: TComponent); virtual; // virtual constructor end; TMyEdit = class(TComponent) public constructor Create(AOwner: TComponent); override; // override virt...
5,743
<p>After solving my <a href="https://stackoverflow.com/questions/147802/why-does-swing-in-my-java-applet-flicker-on-fast-mouse-over">flicker issue</a>, I wonder if there is a better closable Tabbed Pane, then the one that pops up on top by googling for <a href="http://www.google.ch/search?q=closeabletabbedpane" rel="no...
<p>There is a <a href="http://java.sun.com/docs/books/tutorial/uiswing/examples/components/index.html#TabComponentsDemo" rel="nofollow noreferrer">sample implementation of closable tabs</a> using <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/tabbedpane.html" rel="nofollow noreferrer">JTabbedPane</...
<p>I really recommend to follow tutorial mentioned above. It is simple to create such a tab and you have <em>full</em> control over its behavior. </p>
17,803
<p>I have ANOTHER serialization question, but this time it is in regards to Java's native serialization import when serializing to binary. I have to serialize a random tree that is generated in another java file. I know how serialization and deserialization works, but the example I followed when using binary serializ...
<p>At a guess, GeneralTree doesn't implement the <a href="http://java.sun.com/javase/6/docs/api/java/io/Serializable.html" rel="nofollow noreferrer">Serializable</a> marker interface, as documented <a href="http://java.sun.com/javase/6/docs/api/java/io/ObjectOutputStream.html#writeObject(java.lang.Object)" rel="nofollo...
<blockquote> <p>edit: I know it says GeneralTree, but at the start of the class it was in I put</p> </blockquote> <pre><code>print("public class RandomTreeBuilder implements java.io.Serializable"); </code></pre> <p>This does you no good - you are not trying to write an object of type <em>RandomTreeBuilder</em> ...
47,543
<p>I'm looking to write a config file that allows for RESTful services in WCF, but I still want the ability to 'tap into' the membership provider for username/password authentication.</p> <p>The below is part of my current config using basicHttp binding or wsHttp w/out WS Security, how will this change w/ REST based s...
<p>I agree with Darrel that complex REST scenarios over WCF are a bad idea. It just isn't pretty.</p> <p>However, Dominick Baier has some <a href="http://www.leastprivilege.com/HTTPBasicAuthenticationAgainstNonWindowsAccountsInIISASPNETPart3AddingWCFSupport.aspx" rel="nofollow noreferrer">good posts</a> about this on...
<p>Before you continue down this path of fighting to implement REST over WCF, I suggest you read <a href="http://www.pluralsight.com/community/blogs/tewald/archive/2007/08/26/48298.aspx" rel="nofollow noreferrer">this</a> post by Tim Ewald. I was especially impacted by the following statement:</p> <blockquote> <p>I...
17,097
<p>I need to parse a xml file which is practically an image of a really big tree structure, so I'm using the XmlReader class to populate the tree 'on the fly'. Each node is passed just the xml chunk it expects from its parent via the ReadSubtree() function. This has the advantage of not having to worry about when a nod...
<p>ReadSubTree() gives you an XmlReader that wraps the original XmlReader. This new reader appears to consumers as a complete document. This might be important if the code you pass the subtree to thinks it is getting a standalone xml document. For example the Depth property of the new Reader starts out at 0. It is a pr...
<p>Making the assumption that all objects are created on the normal managed heap, and not the large object heap (ie less than 85k), there really should be no problem here, this is just what the GC was designed to deal with. </p> <p>I would suggest that there is also no need to call GC.Collect at the end of the process...
13,967
<p>There are quite a lot of unittesting frameworks out there for .NET. I found this little feature comparison: <a href="https://xunit.net/docs/comparisons" rel="noreferrer">http://xunit.github.io/docs/comparisons.html</a></p> <p>Now I am to choose the best one for us. But how? Does it matter? Which one is most future p...
<p>I know this is an old thread, but I thought I'd post a vote for <a href="http://xunit.github.io/" rel="noreferrer">xUnit.NET</a>. While most of the other testing frameworks mentioned are all pretty much the same, xUnit.NET has taken a pretty unique, modern, and flexible approach to unit testing. It changes terminolo...
<p>It's not a big deal, it's pretty easy to switch between them. MSTest being integrated isn't a big deal either, just grab testdriven.net.</p> <p>Like the previous person said pick a mocking framework, my favourite at the moment is Moq.</p>
32,649
<p>A good and flexible database schema illustrating e-commerce products and their rates management is required.</p>
<p>I agree with Chris Roberts, <a href="http://www.oscommerce.com/community/contributions,3853/page,23" rel="noreferrer">OSCommerce</a> is a good place to start as well as <a href="http://www.databaseanswers.org/data_models/index.htm" rel="noreferrer">DatabaseAnswers.org</a>.</p> <p>Hope that helps.</p>
<p>I'm sure there are many examples about - try looking at some open source shopping cart tools.</p> <p>As a general point, though, I think there are so many ways that a product pricing and discount / gift voucher system <em>could</em> work that finding a database schema that works for <em>every</em> possibility is un...
41,418
<p>Any recommended practices for cleaning up "header spaghetti" which is causing extremely slow compilation times (Linux/Unix)?</p> <p>Is there any equvalent to "#pragma once" with GCC?<br> (found conflicting messages regarding this)</p> <p>Thanks.</p>
<p>Assuming you're familiar with "include guards" (#ifdef at the begining of the header..), an additional way of speeding up build time is by using external include guards. It was discussed in "<a href="http://vig.pearsoned.com/store/product/1,1207,store-15080_isbn-0201633620,00.html" rel="noreferrer">Large Scale C++ S...
<p>In headers: include headers only if you can't use forward declaration, but always #include any file that you need (include dependencies are evil!).</p>
13,570
<p>What are the alternative's to using the <a href="http://www.ithenticate.com" rel="nofollow noreferrer">iThenticate</a> service for content comparison?</p>
<p>Wikipedia page on <a href="http://en.wikipedia.org/wiki/Plagiarism_detection" rel="nofollow noreferrer">plagiarism detection</a> has a list of commercial and free services.</p>
<p>I generally recommend <a href="http://www.copyscape.com" rel="nofollow">Copyscape</a> and/or <a href="http://etest.vbi.vt.edu/etblast3/" rel="nofollow">eTBlast</a> if you choose not to use iThenticate. </p>
7,414
<p>In the early days of .NET, I <i>believe</i> there was an attribute you could decorate a class with to specify a default property.</p> <p>According to some articles I've found, this appears to have been yanked from the framework at some point, because it was a little confusing, and I can see how that is the case. </...
<p>Well, the .NET framework does have a notion of a default member. Key ingredients are the DefaultMemberAttribute class and Type.GetDefaultMembers(). In VB.NET, specifying the default member is part of the language syntax:</p> <pre><code> Public Class Sample Private mValue As Integer Default Public ReadOnl...
<p>You can still use the attribute if you import System.ComponentModel.</p> <p>As others mentioned, this is not ideal since VB.Net prefers that you use the Default attribute. Of course, that comes with conditions, which doesn't really help (requiring an index, for example).</p> <p>But if you use</p> <p><code>Impor...
37,418
<p>I just finished a 2d platformer in C++/Allegro. Its still in an incomplete stage...</p> <p>I wonder how to go about a peer-review from people who are into game development. I would like to review my project on grounds of </p> <ol> <li>game play</li> <li>Collision detection</li> <li>use of OOP</li> <li>programming ...
<p>The first thing I noticed in your source code is that you've got most of your game logic is in the main.cpp file, with the nesting going as deep as 11 tabs! For code organizational purposes, this is a nightmare. Of course, I did this too on my first game. :) The first thing you can do is simplify your main game loop...
<p><strong>RECAP from previous episode -</strong></p> <p>I do not understand why people vote you down and offensive. Keep the good work... – Daok (27 mins ago)</p> <p>anything awefully wrong in asking for a peer review ? think before hitting the down button, tomorrow you might too be in need of peer review! – Abhishe...
30,656
<p>Consider I'm interfacing with an external system that will send a message (DB table, message queue, web service) in some format. In the "message header" there is the "MessageType" that is a number from 1 to 20. The MessageType defines what to do with the rest of the message. There are things like new, modified, d...
<p>In Java, you can make it an enum and give behaviour to the different values (although with 100 values, I'd hope that each type of behaviour is briefly, calling out to "proper" classes).</p> <p>In C#, you can have a map from value to some appropriate delegate type - then when you statically construct the map, you ca...
<p>This is how I've done this in C#. </p> <p>I think this approach is actually not so ugly as all that, It gets less ugly as the number of message types increases: to implement a new message type, you just have to add a value to your Enum and mark the new message handler class with an attribute.</p> <p>And there ...
26,309
<p>I have a web application developed with ASP.net and C# that is running on my companies' intranet. Because all the users for this application are all using Microsoft Outlook without exception, I would like for the the application to open up an Outlook message on the client-side. <strong>I understand that Office is...
<p>You cannot open something on the client from server side code. You'd have to use script on the page to do what you're wanting (or something else client-side like ActiveX or embedded .NET or something) </p> <p>Here's a sample Javascript that invokes an Outlook MailItem from an webpage. This could easily be injected...
<p>If everyone in the company uses Outlook, then just using a standard "mailto" link should always open Outlook. It sounds like you're over-engineering this.</p>
6,620
<p>If the user does a "onmousedown" inside a iframe, drags outside the iframe and hovers over elements that have a "onmouseover" attached to them - safari does not fire this event.</p> <p>I have a slightly unconventional drag n drop setup. The items that can be "dragged" are inside a iframe. The drop targets are outsi...
<p>IE and Firefox fire the onmouseover event just fine. I'm doing something similar dragging from the parent doc to drop targets in the iframe and can see the onmouseover events fire for the targets in IE and FireFox but not Safari. Any workarounds out there?</p>
<p>Offhand, I don't think <em>anything</em> fires this event. It's two completely separate DOMs.</p> <p>Have you tried this in FF, IE, Opera, Chrome?</p>
45,914
<p>I've set hibernate.generate_statistics=true and now need to register the mbeans so I can see the statistics in the jmx console. I can't seem to get anywhere and this doesn't seem like it should be such a difficult problem. Maybe I'm making things overcomplicated, but in any case so far I've tried:</p> <ul> <li>I co...
<p>Solved. Since I was not seeing all the caches for my entities I suspected I was not getting the right SessionFactory instance. I started out with this line (see the example jmx registration code in the link I provided in the question):</p> <pre><code>SessionFactory sf = (new Configuration()).configure().buildSessio...
<p>Solved. Since I was not seeing all the caches for my entities I suspected I was not getting the right SessionFactory instance. I started out with this line (see the example jmx registration code in the link I provided in the question):</p> <pre><code>SessionFactory sf = (new Configuration()).configure().buildSessio...
31,358
<p>I've used Slime within Emacs as my primary development environment for Common Lisp (or Aquamacs on OS X), but are there other compelling choices out there? I've heard about Lispworks, but is that [or something else] worth looking at? Or does anyone have tips to getting the most out of Emacs (e.g., hooking it up to t...
<p>There are some flashier options out there, but I don't think anything's better than <a href="http://www.gnu.org/software/emacs/" rel="noreferrer">Emacs</a> and <a href="http://common-lisp.net/project/slime/" rel="noreferrer">SLIME</a>. I'd stick with what you're using and just work on pimping your Emacs install.</p>...
<p>I use Vim, the Ion3 window manager and terminal windows and enjoy it very much.</p>
28,768
<p>We're looking into developing a product that would use Amazon's cloud tools (EC2, SQS, etc), and I'm curious what tips/gotchas/pointers people that have used these technologies have.</p> <p>One tip/whatever per post, please.</p>
<p>The Elasticfox plug-in for Mozilla makes doing a lot of the EC2 stuff easier. It can be found at: <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=609" rel="nofollow noreferrer">Elasticfox Firefox Extension for Amazon EC2</a>. This page has links specifically to download the Elasticfox p...
<p>For managing your EC2 instances, etc. Amazon also offers - in beta since a couple of days - the management console which has similar functionality to the Elasticfox Firefox plugin but is a pure web console.</p> <p><a href="https://console.aws.amazon.com" rel="nofollow noreferrer">https://console.aws.amazon.com</a><...
19,286
<p>Is there any way in the SQL language or in MySQL (or other DBMA) to transfer a value from one cell to another? For example, say there is a table called user_cars with the following structure:</p> <pre><code>|id| |user_name| |num_cars| </code></pre> <p>Bob has 5 cars, and John has 3 cars. Is there any way to in one...
<p>For Oracle you could do this. Don't know if there is an equivalent in mysql. Obviously this particular statement is very specific to the example you stated.</p> <pre><code> UPDATE user_cars SET num_cars = num_cars + CASE WHEN user_name='Bob' THEN -2 WHEN user_name...
<p>If you really want to do it in one query, you can do an update on a self join of the table, but it's both less readable and probably less efficient.</p>
22,886
<p>I know I'm gonna get down votes, but I have to make sure if this is logical or not.</p> <p>I have three tables A, B, C. B is a table used to make a many-many relationship between A and C. But the thing is that A and C are also related directly in a 1-many relationship</p> <p>A customer added the following requirem...
<p>This is a doable scenario. You can join a table twice in a query, usually assigning it a different alias to keep things straight.</p> <p>For example:</p> <pre><code>SELECT s.name AS "student name", c1.className AS "student class", c2.className as "class list" FROM s JOIN many_to_many mtm ON s.id_student = mtm.id_...
<p>I personally never heard a requirement from a customer that would sound like:</p> <blockquote> <p>Obtain the information from the Table B inner joining with A and C, and in the same query relate A and C in a one-many relationship</p> </blockquote> <p>It looks like that it is what you translated the require...
28,303